-
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.
- Loading branch information
Showing
7 changed files
with
468 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import StyleDictionary from 'style-dictionary-utils'; | ||
|
||
// color theme mode | ||
StyleDictionary.registerFormat({ | ||
name: 'css/variables-themed', | ||
formatter({ dictionary, file, options }) { | ||
const { outputReferences, theme } = options; | ||
return `${StyleDictionary.formatHelpers.fileHeader({ | ||
file, | ||
// eslint-disable-next-line max-len | ||
})}:root[data-theme=${theme}] {\n${StyleDictionary.formatHelpers.formattedVariables( | ||
{ | ||
format: 'css', | ||
dictionary, | ||
outputReferences, | ||
}, | ||
)}\n}\n`; | ||
}, | ||
}); | ||
|
||
// light mode | ||
StyleDictionary.extend({ | ||
source: ['tokens/primitives.base.json', 'tokens/color.light.json'], | ||
platforms: { | ||
css: { | ||
transformGroup: 'css', | ||
buildPath: 'dist/css/', | ||
files: [ | ||
{ | ||
destination: 'colors.css', | ||
format: 'css/variables', | ||
filter: { | ||
attributes: { | ||
category: 'color', | ||
}, | ||
}, | ||
options: { | ||
outputReferences: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}).buildAllPlatforms(); | ||
|
||
// dark mode | ||
StyleDictionary.extend({ | ||
source: ['tokens/primitives.base.json', 'tokens/color.dark.json'], | ||
platforms: { | ||
css: { | ||
transformGroup: 'css', | ||
buildPath: 'dist/css/', | ||
files: [ | ||
{ | ||
destination: 'colors-dark.css', | ||
format: 'css/variables-themed', | ||
options: { | ||
outputReferences: true, | ||
theme: 'dark', | ||
}, | ||
filter: { | ||
attributes: { | ||
category: 'color', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}).buildAllPlatforms(); | ||
|
||
// small | ||
StyleDictionary.registerFormat({ | ||
name: 'css/variables-breakpoints', | ||
formatter({ dictionary, file, options }) { | ||
const { outputReferences } = options; | ||
return `${StyleDictionary.formatHelpers.fileHeader({ | ||
file, | ||
// TO DO how to dynamically get the breakpoint value | ||
// eslint-disable-next-line max-len | ||
})}@media (max-width: 768px) { \n:root {\n${StyleDictionary.formatHelpers.formattedVariables( | ||
{ | ||
format: 'css', | ||
dictionary, | ||
outputReferences, | ||
}, | ||
)}\n}\n}\n`; | ||
}, | ||
}); | ||
|
||
StyleDictionary.registerFilter({ | ||
name: 'isDimension', | ||
matcher(prop) { | ||
return ['dimension', 'content', 'spacing', 'border', 'radius'].includes( | ||
prop.attributes.category, | ||
); | ||
}, | ||
}); | ||
|
||
const dimensions = ['dimension', 'content', 'spacing', 'border', 'radius']; | ||
|
||
// small | ||
StyleDictionary.extend({ | ||
source: ['tokens/primitives.base.json', 'tokens/dimension.small.json'], | ||
platforms: { | ||
css: { | ||
transformGroup: 'css', | ||
buildPath: 'dist/css/', | ||
files: [ | ||
{ | ||
destination: 'dimensions-small.css', | ||
format: 'css/variables-breakpoints', | ||
options: { | ||
outputReferences: true, | ||
}, | ||
filter: token => dimensions.includes(token.attributes.category), | ||
}, | ||
], | ||
}, | ||
}, | ||
}).buildAllPlatforms(); | ||
|
||
// large | ||
StyleDictionary.extend({ | ||
source: ['tokens/primitives.base.json', 'tokens/dimension.large.json'], | ||
platforms: { | ||
css: { | ||
transformGroup: 'css', | ||
buildPath: 'dist/css/', | ||
files: [ | ||
{ | ||
destination: 'dimensions-large.css', | ||
format: 'css/variables', | ||
options: { | ||
outputReferences: true, | ||
}, | ||
filter: token => dimensions.includes(token.attributes.category), | ||
}, | ||
], | ||
}, | ||
}, | ||
}).buildAllPlatforms(); |
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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.