Skip to content

Commit

Permalink
Merge pull request #350 from pivotpointux/addExtendFlag
Browse files Browse the repository at this point in the history
fix: add extend flag to opionally generate config within extend key o…
  • Loading branch information
nado1001 authored Apr 7, 2024
2 parents 4a48e5e + 28499af commit 9f44ce0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Optional except for `type`.
| type | Set the name of each theme (colors, fontSize, etc.) for `'all'` or tailwind. | `'all'` or string |
| formatType | Set the format of the Tailwind CSS configuration file. <br>Default value: `js` | `'js'` `'cjs'` |
| isVariables | Set when using CSS custom variables. <br>Default value: `false` | boolean |
| extend | Set to add transformed styles to the `'extend'` key within the `'theme'` key or not. <br>Default value: `true` | boolean |
| source | [`source`](https://github.com/amzn/style-dictionary/blob/main/README.md#configjson) attribute of style-dictionary.<br>Default value: ` ['tokens/**/*.json']` | Array of strings |
| transforms | [`platform.transforms`](https://github.com/amzn/style-dictionary/blob/main/README.md#configjson) attribute of style-dictionary.<br>Default value: `['attribute/cti','name/cti/kebab']` | Array of strings |
| buildPath | [`platform.buildPath`](https://github.com/amzn/style-dictionary/blob/main/README.md#configjson) attribute of style-dictionary.<br>Default value: `'build/web/'` | string |
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const getTailwindFormat = ({
type,
isVariables,
prefix,
extend,
tailwind
}: TailwindFormatObjType) => {
const content = formatTokens(allTokens, type, isVariables, prefix)
Expand All @@ -72,6 +73,7 @@ export const getTailwindFormat = ({
content,
darkMode,
tailwindContent,
extend,
plugins
)

Expand All @@ -85,6 +87,7 @@ export const makeSdTailwindConfig = ({
type,
formatType = 'js',
isVariables = false,
extend = true,
source,
transforms,
buildPath,
Expand All @@ -107,6 +110,7 @@ export const makeSdTailwindConfig = ({
dictionary,
formatType,
isVariables,
extend,
prefix,
type,
tailwind
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ export type SdTailwindConfigType = {
buildPath?: Platform['buildPath']
prefix?: Platform['prefix']
tailwind?: Partial<TailwindOptions>
extend?: boolean
}

export type TailwindFormatObjType = Pick<
SdTailwindConfigType,
'type' | 'isVariables' | 'prefix' | 'tailwind'
'type' | 'isVariables' | 'prefix' | 'tailwind' | 'extend'
> & {
dictionary: Dictionary
formatType: TailwindFormatType
Expand Down
9 changes: 6 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ export const getTemplateConfigByType = (
content: string,
darkMode: TailwindOptions['darkMode'],
tailwindContent: TailwindOptions['content'],
extend: SdTailwindConfigType['extend'],
plugins: string[]
) => {
const extendTheme = extend
? `theme: { extend: ${unquoteFromKeys(content, type)}, },`
: `theme: ${unquoteFromKeys(content, type)},`

const getTemplateConfig = () => {
let config = `{
mode: "jit",
content: [${tailwindContent}],
darkMode: "${darkMode}",
theme: {
extend: ${unquoteFromKeys(content, type)},
},`
${extendTheme}`

if (plugins.length > 0) {
config += `\n plugins: [${plugins}]`
Expand Down

0 comments on commit 9f44ce0

Please sign in to comment.