Skip to content

Commit

Permalink
add duration transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Oct 5, 2023
1 parent 9308e89 commit 923b2cb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
29 changes: 29 additions & 0 deletions scripts/buildTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ export const buildDesignTokens = (buildOptions: ConfigGeneratorOptions): void =>
getStyleDictionaryConfig(`base/typography/typography`, [`src/tokens/base/typography/*.json`], [], buildOptions),
).buildAllPlatforms()

/** -----------------------------------
* Motion tokens
* ----------------------------------- */
PrimerStyleDictionary.extend(
getStyleDictionaryConfig(
`functional/motion/motion`,
[`src/tokens/functional/motion/*.json5`],
[`src/tokens/base/motion/*.json5`],
buildOptions,
{
css: css(`css/functional/motion/motion.css`, buildOptions.prefix, buildOptions.buildPath, {
options: {
outputReferences: true,
},
}),
},
),
).buildAllPlatforms()

PrimerStyleDictionary.extend(
getStyleDictionaryConfig(`base/motion/motion`, [`src/tokens/base/motion/*.json5`], [], buildOptions),
).buildAllPlatforms()

/** -----------------------------------
* deprecated tokens
* ----------------------------------- */
Expand Down Expand Up @@ -139,6 +162,12 @@ export const buildDesignTokens = (buildOptions: ConfigGeneratorOptions): void =>
source: [`src/tokens/base/size/*.json`, `src/tokens/functional/size/*.json`],
include: [`src/tokens/base/size/*.json`],
},
// motion
{
filename: 'motion',
source: [`src/tokens/base/motion/*.json5`, `src/tokens/functional/motion/*.json5`],
include: [`src/tokens/base/motion/*.json5`],
},
]
//
for (const {filename, source, include} of deprecatedBuilds) {
Expand Down
1 change: 1 addition & 0 deletions src/platforms/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
'color/hexAlpha',
'color/hexMix',
'dimension/rem',
'duration/css',
'shadow/css',
'border/css',
'typography/css',
Expand Down
1 change: 1 addition & 0 deletions src/platforms/scss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const scss: PlatformInitializer = (outputFile, prefix, buildPath): StyleD
'color/hexMix',
'color/hexAlpha',
'dimension/rem',
'duration/css',
'shadow/css',
'border/css',
'typography/css',
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/durationToCss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type StyleDictionary from 'style-dictionary'
export const durationToCss: StyleDictionary.Transform = {
type: `value`,
transitive: true,
matcher: (token: StyleDictionary.TransformedToken) => token.type === `duration`,
matcher: (token: StyleDictionary.TransformedToken) => token.$type === `duration`,
transformer: (token: StyleDictionary.TransformedToken, _options?: StyleDictionary.Platform) => {
// throw an error if token value is not a string or does not end with `ms`
if (typeof token.value !== `string` || !token.value.endsWith(`ms`)) {
Expand Down

0 comments on commit 923b2cb

Please sign in to comment.