Skip to content

Commit

Permalink
✨ feat(minor): add bud.wp.json.removeDefaultSuffix
Browse files Browse the repository at this point in the history
  • Loading branch information
kellymears committed Jul 25, 2024
1 parent 7dfad60 commit ab9b853
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
19 changes: 18 additions & 1 deletion sources/@roots/bud-tailwindcss-theme-json/src/extension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Options {
color?: `extend` | boolean
fontFamily?: `extend` | boolean
fontSize?: `extend` | boolean
removeDefaultSuffix: boolean
spacing?: `extend` | boolean
}

Expand All @@ -27,6 +28,7 @@ interface Options {
color: false,
fontFamily: false,
fontSize: false,
removeDefaultSuffix: false,
spacing: false,
})
export class TailwindThemeJSON extends Extension {
Expand Down Expand Up @@ -82,17 +84,32 @@ export class TailwindThemeJSON extends Extension {
bud.wpjson.useTailwindFontFamily = this.useTailwindFontFamily
bud.wpjson.useTailwindFontSize = this.useTailwindFontSize
bud.wpjson.useTailwindSpacing = this.useTailwindSpacing
bud.wpjson.removeDefaultSuffix = this.removeDefaultSuffix
}

@bind
public removeDefaultSuffix(value: boolean = true) {
this.set(`removeDefaultSuffix`, value)
return this.app.wpjson
}

@bind
public tapTailwindColor(options: SettingsAndStyles): SettingsAndStyles {
const palette = tailwindAdapter.palette.transform({
const values = tailwindAdapter.palette.transform({
...this.app.tailwind.resolveThemeValue(
`colors`,
this.options.color === `extend`,
),
})

const palette = this.get(`removeDefaultSuffix`)
? values.map(({color, name, slug}) => ({
color,
name: name.replace(/ default$/i, ``),
slug: slug.replace(/-default$/i, ``),
}))
: values

return {
...(options ?? {}),
settings: {
Expand Down
15 changes: 15 additions & 0 deletions sources/@roots/bud-wordpress-theme-json/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ class WordPressThemeJson extends Extension<
`templateParts`
>

/**
* ## bud.wp.json.removeDefaultSuffix
*
* Remove the `-default` suffix from color slugs and ` Default` from color names
*
* @example
* ```ts
* bud.wp.json.removeDefaultSuffix()
* bud.wp.json.removeDefaultSuffix(true)
* ```
*/
public declare removeDefaultSuffix?: (
value?: boolean,
) => WordPressThemeJson

/**
* ## bud.wp.json.useTailwindColors
*
Expand Down

0 comments on commit ab9b853

Please sign in to comment.