-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4408 from grommet/style-dictionaryv4
Upgrade to style-dictionary v4
- Loading branch information
Showing
21 changed files
with
903 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,76 @@ | ||
import StyleDictionary from 'style-dictionary-utils'; | ||
import { StyleDictionary } from 'style-dictionary-utils'; | ||
import { | ||
commonJs, | ||
commonJsGrommetRefs, | ||
cssColorModes, | ||
cssBreakpoints, | ||
esmGrommetRefs, | ||
javascriptEsm, | ||
jsonFlat, | ||
} from './formats/index.js'; | ||
import { | ||
cssW3c, | ||
javascriptW3c, | ||
linearGradientCss, | ||
numberToDimension, | ||
shadowCSS, | ||
} from './transforms/index.js'; | ||
|
||
StyleDictionary.registerFormat({ | ||
export const HPEStyleDictionary = new StyleDictionary({ | ||
log: { | ||
verbosity: 'verbose', | ||
}, | ||
}); | ||
|
||
HPEStyleDictionary.registerFormat({ | ||
name: 'javascript/commonJs', | ||
formatter: commonJs, | ||
format: commonJs, | ||
}); | ||
StyleDictionary.registerFormat({ | ||
HPEStyleDictionary.registerFormat({ | ||
name: 'javascript/esm', | ||
format: javascriptEsm, | ||
}); | ||
HPEStyleDictionary.registerFormat({ | ||
name: 'css/variables-themed', | ||
formatter: cssColorModes, | ||
format: cssColorModes, | ||
}); | ||
StyleDictionary.registerFormat({ | ||
HPEStyleDictionary.registerFormat({ | ||
name: 'css/variables-breakpoints', | ||
formatter: cssBreakpoints, | ||
format: cssBreakpoints, | ||
}); | ||
StyleDictionary.registerFormat({ | ||
HPEStyleDictionary.registerFormat({ | ||
name: `esmGrommetRefs`, | ||
formatter: esmGrommetRefs, | ||
format: esmGrommetRefs, | ||
}); | ||
StyleDictionary.registerFormat({ | ||
HPEStyleDictionary.registerFormat({ | ||
name: `commonJsGrommetRefs`, | ||
formatter: commonJsGrommetRefs, | ||
format: commonJsGrommetRefs, | ||
}); | ||
StyleDictionary.registerFormat({ | ||
HPEStyleDictionary.registerFormat({ | ||
name: `jsonFlat`, | ||
formatter: jsonFlat, | ||
format: jsonFlat, | ||
}); | ||
StyleDictionary.registerTransform({ | ||
name: 'numberToDimension', | ||
HPEStyleDictionary.registerTransform({ | ||
...numberToDimension, | ||
}); | ||
StyleDictionary.registerTransform({ | ||
HPEStyleDictionary.registerTransform({ | ||
...shadowCSS, | ||
}); | ||
HPEStyleDictionary.registerTransform({ | ||
name: 'name/dot', | ||
type: 'name', | ||
transformer: (token, config) => { | ||
transform: (token, config) => { | ||
return [config.prefix].concat(token.path).join('.'); | ||
}, | ||
}); | ||
StyleDictionary.registerTransform({ | ||
name: 'linearGradient/css', | ||
HPEStyleDictionary.registerTransform({ | ||
...linearGradientCss, | ||
}); | ||
StyleDictionary.registerTransformGroup({ | ||
HPEStyleDictionary.registerTransformGroup({ | ||
name: 'js/w3c', | ||
transforms: javascriptW3c, | ||
}); | ||
StyleDictionary.registerTransformGroup({ | ||
HPEStyleDictionary.registerTransformGroup({ | ||
name: 'css/w3c', | ||
transforms: cssW3c, | ||
}); | ||
|
||
export const HPEStyleDictionary: StyleDictionary.Core = StyleDictionary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import StyleDictionary from 'style-dictionary'; | ||
import { FormatterArguments } from 'style-dictionary/types/Format.js'; | ||
import { FormatFn, FormatFnArguments } from 'style-dictionary/types'; | ||
import { fileHeader, formattedVariables } from 'style-dictionary/utils'; | ||
|
||
export const cssBreakpoints = ({ | ||
export const cssBreakpoints: FormatFn = async ({ | ||
dictionary, | ||
file, | ||
options, | ||
}: FormatterArguments) => { | ||
}: FormatFnArguments) => { | ||
const { outputReferences, mediaQuery } = options; | ||
let output = `:root {\n${StyleDictionary.formatHelpers.formattedVariables({ | ||
let output = `:root {\n${formattedVariables({ | ||
format: 'css', | ||
dictionary, | ||
outputReferences, | ||
usesDtcg: true, | ||
})}\n}`; | ||
if (mediaQuery) output = `@media (${mediaQuery}) {\n${output}\n}\n`; | ||
|
||
return `${StyleDictionary.formatHelpers.fileHeader({ | ||
return `${await fileHeader({ | ||
file, | ||
})}${output}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { fileHeader, minifyDictionary } from 'style-dictionary/utils'; | ||
import { FormatFn, FormatFnArguments } from 'style-dictionary/types'; | ||
import { jsonToNestedValue } from './utils/jsonToNestedValue.js'; | ||
|
||
export const javascriptEsm: FormatFn = async ({ | ||
dictionary, | ||
file, | ||
platform = {}, | ||
}: FormatFnArguments) => { | ||
const { prefix } = platform; | ||
const tokens = prefix ? { [prefix]: dictionary.tokens } : dictionary.tokens; | ||
// | ||
const output = | ||
(await fileHeader({ file })) + | ||
`export default ${JSON.stringify( | ||
jsonToNestedValue(minifyDictionary(tokens, true)), // Build in minified | ||
null, | ||
2, | ||
)}\n`; | ||
// TO DO return prettified | ||
return output; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.