Skip to content

Commit 6b8eb32

Browse files
committed
fix: add extend flag to opionally generate config within extend key or not
1 parent 4a48e5e commit 6b8eb32

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//README
12
# Style Dictionary Tailwind CSS Transformer
23

34
[![Release](https://badgen.net/github/release/nado1001/sd-tailwindcss-transformer)](https://badgen.net/github/release/nado1001/sd-tailwindcss-transformer)
@@ -191,6 +192,7 @@ Optional except for `type`.
191192
| type | Set the name of each theme (colors, fontSize, etc.) for `'all'` or tailwind. | `'all'` or string |
192193
| formatType | Set the format of the Tailwind CSS configuration file. <br>Default value: `js` | `'js'` `'cjs'` |
193194
| isVariables | Set when using CSS custom variables. <br>Default value: `false` | boolean |
195+
| extend | Set to add transformed styles to the `'extend'` key within the `'theme'` key or not. <br>Default value: `true` | boolean |
194196
| 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 |
195197
| 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 |
196198
| 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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// index.ts
12
import type { Dictionary, Config } from 'style-dictionary/types'
23
import type { SdTailwindConfigType, TailwindFormatObjType } from './types'
34
import {
@@ -46,6 +47,7 @@ export const getTailwindFormat = ({
4647
type,
4748
isVariables,
4849
prefix,
50+
extend,
4951
tailwind
5052
}: TailwindFormatObjType) => {
5153
const content = formatTokens(allTokens, type, isVariables, prefix)
@@ -72,6 +74,7 @@ export const getTailwindFormat = ({
7274
content,
7375
darkMode,
7476
tailwindContent,
77+
extend,
7578
plugins
7679
)
7780

@@ -85,6 +88,7 @@ export const makeSdTailwindConfig = ({
8588
type,
8689
formatType = 'js',
8790
isVariables = false,
91+
extend = true,
8892
source,
8993
transforms,
9094
buildPath,
@@ -107,6 +111,7 @@ export const makeSdTailwindConfig = ({
107111
dictionary,
108112
formatType,
109113
isVariables,
114+
extend,
110115
prefix,
111116
type,
112117
tailwind
@@ -132,4 +137,4 @@ export const makeSdTailwindConfig = ({
132137
}
133138
}
134139
}
135-
}
140+
}

src/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//types.ts
12
import type { Dictionary } from 'style-dictionary/types/Dictionary'
23
import type { Platform } from 'style-dictionary/types/Platform'
34
import type { Config } from 'style-dictionary/types/Config'
@@ -23,12 +24,13 @@ export type SdTailwindConfigType = {
2324
buildPath?: Platform['buildPath']
2425
prefix?: Platform['prefix']
2526
tailwind?: Partial<TailwindOptions>
27+
extend?: boolean
2628
}
2729

2830
export type TailwindFormatObjType = Pick<
2931
SdTailwindConfigType,
30-
'type' | 'isVariables' | 'prefix' | 'tailwind'
32+
'type' | 'isVariables' | 'prefix' | 'tailwind' | 'extend'
3133
> & {
3234
dictionary: Dictionary
3335
formatType: TailwindFormatType
34-
}
36+
}

src/utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//utils.ts
12
import { camelCase } from 'change-case'
23
import type { SdObjType, SdTailwindConfigType, TailwindOptions } from './types'
34

@@ -62,16 +63,19 @@ export const getTemplateConfigByType = (
6263
content: string,
6364
darkMode: TailwindOptions['darkMode'],
6465
tailwindContent: TailwindOptions['content'],
66+
extend: SdTailwindConfigType['extend'],
6567
plugins: string[]
6668
) => {
69+
const extendTheme = extend ?
70+
`theme: { extend: ${unquoteFromKeys(content, type)}, },` :
71+
`theme: ${unquoteFromKeys(content, type)},`
72+
6773
const getTemplateConfig = () => {
6874
let config = `{
6975
mode: "jit",
7076
content: [${tailwindContent}],
7177
darkMode: "${darkMode}",
72-
theme: {
73-
extend: ${unquoteFromKeys(content, type)},
74-
},`
78+
${extendTheme}`
7579

7680
if (plugins.length > 0) {
7781
config += `\n plugins: [${plugins}]`
@@ -85,4 +89,4 @@ export const getTemplateConfigByType = (
8589
const configs = `/** @type {import('tailwindcss').Config} */\n module.exports = ${getTemplateConfig()}`
8690

8791
return configs
88-
}
92+
}

0 commit comments

Comments
 (0)