-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move the generate style variables to StyleDictionary * Update README * Handle no style dictionary config * Changeset * Improve colors json struct * Fix tests * Up changeset to major * Add support for CSS dark mode * Update Readme and template * Refactor * Changeset
- Loading branch information
Imar Abreu
authored
Dec 20, 2023
1 parent
646a330
commit 1b7ed3b
Showing
14 changed files
with
222 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@runroom/design-tokens': major | ||
--- | ||
|
||
- Move the `StyleDictionary` config to a `styleDictionary` entry in the design tokens config | ||
- Add support for dark mode in the CSS variables with the `darkMode` and the `darkModeStyleDictionary` entries in the | ||
design tokens config | ||
- Remove `figmaThemes` |
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
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,110 @@ | ||
import StyleDictionary, { Config as StyleDictionaryConfig } from 'style-dictionary'; | ||
import { EMOJIS, log } from '@/functions'; | ||
import { getGradientsParser, getShadowsParser, getTypographiesParser } from '@/tokens'; | ||
import { Config } from '@/types/designTokens'; | ||
|
||
const registerParsers = () => { | ||
StyleDictionary.registerParser(getTypographiesParser()); | ||
StyleDictionary.registerParser(getShadowsParser()); | ||
StyleDictionary.registerParser(getGradientsParser()); | ||
}; | ||
|
||
const getDarkModeSource = (source?: string[], outputDir?: string) => { | ||
const defaultJsonPath = `${outputDir}/**/*.dark.json`; | ||
|
||
if (!source) { | ||
return [defaultJsonPath]; | ||
} | ||
|
||
return source.map(path => { | ||
if (path.indexOf(`.dark.json`) > -1) { | ||
return path; | ||
} | ||
|
||
return `${path.replace(`.json`, `.dark.json`)}`; | ||
}); | ||
}; | ||
|
||
const getDarkModeStyleDictionaryDefaultConfig = (settings: Config) => { | ||
const source = getDarkModeSource(settings.styleDictionary?.source, settings.outputDir); | ||
const buildPath = | ||
settings.styleDictionary!.platforms.css.buildPath ?? `${settings.outputDir}/tokens/`; | ||
|
||
return { | ||
include: source, | ||
source, | ||
filter: { | ||
dark: ({ filePath }: { filePath: string }) => filePath.indexOf(`.dark`) > -1 | ||
}, | ||
platforms: { | ||
css: { | ||
transformGroup: `css`, | ||
buildPath, | ||
files: [ | ||
{ | ||
destination: `variables-dark.css`, | ||
format: `css/variables` | ||
} | ||
] | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
const buildDarkModeStyles = (settings: Config) => { | ||
const darkModeConfig = | ||
settings.darkModeStyleDictionary ?? getDarkModeStyleDictionaryDefaultConfig(settings); | ||
|
||
const extendedDictionary = StyleDictionary.extend(darkModeConfig); | ||
|
||
log('Compiling dark mode styles...', EMOJIS.workingInProgress); | ||
extendedDictionary.buildAllPlatforms(); | ||
log('Dark mode styles compiled', EMOJIS.success); | ||
}; | ||
|
||
const buildStyles = (styleDictionary: StyleDictionaryConfig) => { | ||
const extendedDictionary = StyleDictionary.extend(styleDictionary); | ||
|
||
log('Compiling styles...', EMOJIS.workingInProgress); | ||
extendedDictionary.buildAllPlatforms(); | ||
log('Styles compiled', EMOJIS.success); | ||
}; | ||
|
||
const getStyleDictionaryWithoutDarkFiles = ( | ||
styleDictionary: StyleDictionaryConfig | ||
): StyleDictionaryConfig => { | ||
const source = styleDictionary.source | ||
? styleDictionary.source.map(sourcePath => sourcePath.replace('*.json', '!(*.dark).json')) | ||
: []; | ||
|
||
return { | ||
...styleDictionary, | ||
source, | ||
filter: { | ||
...styleDictionary.filter, | ||
dark: ({ filePath }: { filePath: string }) => filePath.indexOf(`.dark`) === -1 | ||
} | ||
}; | ||
}; | ||
|
||
const buildStyleDictionary = (settings: Config) => { | ||
if (!settings.styleDictionary) { | ||
log('No Style Dictionary config found', EMOJIS.warning); | ||
return; | ||
} | ||
|
||
registerParsers(); | ||
|
||
const { darkMode, styleDictionary } = settings; | ||
|
||
if (darkMode) { | ||
const styleDictionaryWithoutDarkFiles = getStyleDictionaryWithoutDarkFiles(styleDictionary); | ||
buildStyles(styleDictionaryWithoutDarkFiles); | ||
buildDarkModeStyles(settings); | ||
return; | ||
} | ||
|
||
buildStyles(styleDictionary); | ||
}; | ||
|
||
export { buildStyleDictionary }; |
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.
1b7ed3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
82 tests passing in 4 suites.
Report generated by π§ͺjest coverage report action from 1b7ed3b
1b7ed3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
82 tests passing in 4 suites.
Report generated by π§ͺjest coverage report action from 1b7ed3b
1b7ed3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
82 tests passing in 4 suites.
Report generated by π§ͺjest coverage report action from 1b7ed3b