Skip to content

Commit 9f44ce0

Browse files
authored
Merge pull request #350 from pivotpointux/addExtendFlag
fix: add extend flag to opionally generate config within extend key o…
2 parents 4a48e5e + 28499af commit 9f44ce0

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Optional except for `type`.
191191
| type | Set the name of each theme (colors, fontSize, etc.) for `'all'` or tailwind. | `'all'` or string |
192192
| formatType | Set the format of the Tailwind CSS configuration file. <br>Default value: `js` | `'js'` `'cjs'` |
193193
| isVariables | Set when using CSS custom variables. <br>Default value: `false` | boolean |
194+
| extend | Set to add transformed styles to the `'extend'` key within the `'theme'` key or not. <br>Default value: `true` | boolean |
194195
| 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 |
195196
| 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 |
196197
| buildPath | [`platform.buildPath`](https://github.com/amzn/style-dictionary/blob/main/README.md#configjson) attribute of style-dictionary.<br>Default value: `'build/web/'` | string |

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const getTailwindFormat = ({
4646
type,
4747
isVariables,
4848
prefix,
49+
extend,
4950
tailwind
5051
}: TailwindFormatObjType) => {
5152
const content = formatTokens(allTokens, type, isVariables, prefix)
@@ -72,6 +73,7 @@ export const getTailwindFormat = ({
7273
content,
7374
darkMode,
7475
tailwindContent,
76+
extend,
7577
plugins
7678
)
7779

@@ -85,6 +87,7 @@ export const makeSdTailwindConfig = ({
8587
type,
8688
formatType = 'js',
8789
isVariables = false,
90+
extend = true,
8891
source,
8992
transforms,
9093
buildPath,
@@ -107,6 +110,7 @@ export const makeSdTailwindConfig = ({
107110
dictionary,
108111
formatType,
109112
isVariables,
113+
extend,
110114
prefix,
111115
type,
112116
tailwind

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ export type SdTailwindConfigType = {
2323
buildPath?: Platform['buildPath']
2424
prefix?: Platform['prefix']
2525
tailwind?: Partial<TailwindOptions>
26+
extend?: boolean
2627
}
2728

2829
export type TailwindFormatObjType = Pick<
2930
SdTailwindConfigType,
30-
'type' | 'isVariables' | 'prefix' | 'tailwind'
31+
'type' | 'isVariables' | 'prefix' | 'tailwind' | 'extend'
3132
> & {
3233
dictionary: Dictionary
3334
formatType: TailwindFormatType

src/utils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,19 @@ export const getTemplateConfigByType = (
6262
content: string,
6363
darkMode: TailwindOptions['darkMode'],
6464
tailwindContent: TailwindOptions['content'],
65+
extend: SdTailwindConfigType['extend'],
6566
plugins: string[]
6667
) => {
68+
const extendTheme = extend
69+
? `theme: { extend: ${unquoteFromKeys(content, type)}, },`
70+
: `theme: ${unquoteFromKeys(content, type)},`
71+
6772
const getTemplateConfig = () => {
6873
let config = `{
6974
mode: "jit",
7075
content: [${tailwindContent}],
7176
darkMode: "${darkMode}",
72-
theme: {
73-
extend: ${unquoteFromKeys(content, type)},
74-
},`
77+
${extendTheme}`
7578

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

0 commit comments

Comments
 (0)