-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
501eb61
commit 9326e3b
Showing
9 changed files
with
57 additions
and
10 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
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 was deleted.
Oops, something went wrong.
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,19 @@ | ||
import type {Dictionary, PlatformConfig, PreprocessedTokens} from 'style-dictionary/types' | ||
import {transformTokens} from './utilities/transformTokens.js' | ||
|
||
export const getThemeValue = { | ||
name: 'getThemeValue', | ||
preprocessor: (dictionary: Dictionary, config: PlatformConfig): PreprocessedTokens => { | ||
const tokens = transformTokens(dictionary, token => { | ||
// return early if no theme value is set | ||
if (!config.options?.theme || !token.$extensions?.['org.primer.theme']?.[config.options.theme]) return token | ||
// token an theme value exist | ||
const valueProp = 'value' in token ? 'value' : '$value' | ||
return { | ||
...token, | ||
[valueProp]: token.$extensions['org.primer.theme'][config.options.theme], | ||
} | ||
}) | ||
return tokens | ||
}, | ||
} |
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,25 @@ | ||
import type {DesignToken} from 'style-dictionary/types' | ||
/** | ||
* jsonToNestedValue | ||
* @description creates a nested json tree where every final value is the `.value` prop | ||
* @param token StyleDictionary.DesignToken | ||
* @returns nested json three | ||
*/ | ||
export const transformTokens = ( | ||
token: DesignToken | Record<string, unknown>, | ||
transform: (token: DesignToken) => DesignToken, | ||
) => { | ||
// is non-object value | ||
if (typeof token !== 'object') return token | ||
// is design token | ||
if ('$value' in token || 'value' in token) { | ||
return transform(token as DesignToken) | ||
} | ||
// is obj | ||
const nextObj = {} | ||
for (const [prop, value] of Object.entries(token)) { | ||
// @ts-expect-error: can't predict type | ||
nextObj[prop] = transformTokens(value, transform) | ||
} | ||
return nextObj | ||
} |
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