@strategies/tokens
v5.0.0
Published
Tokens for Sasaki Strategies' design system
Maintainers
Keywords
Readme
Strategies' Design System Tokens
Installation
pnpm add @strategies/tokensHow to update tokens ?
Update the tokens in JSON files
- The tokens are stored in JSON files located in the
srcfolder. - We use our own code in
utilsto generate SCSS variable files from these JSON files. - One of the advantages of storing tokens in JSON format is that they can be easily integrated into the
tokenfunction. So that, tokens can be used in js/jsx/ts/tsx files
Mixins
- The mixins are stored in the
mixinsfolder.- The mixins are written in SCSS format.
- The
-base.scssfiles are the base mixins that are used in the other mixins. - The
.scssfiles are the mixins that are used in the components. - The
-use-cases.scssfiles are the use cases of the mixins, which contain implemented classes. They are ONLY for testing purposes.
- The mixins are NOT generated from the JSON files.
Token with reference/alias
- If the token is a reference/alias token, plz make sure the format of its
valueis like this. For example, we wanna set tokencolor-testto bepalette-primary-test.
{
"color": {
"test": {
"value": "palette.$primary-test",
"isReference": true
}
}
}valueis the reference to another tokenisReferenceis the flag to indicate that this token is a reference token- Important! Make sure the first divider, aka. the divider between the
paletteandprimary-testis.$. This is meant for successfully converting thejsonfiles toscssfiles
Token w/o reference/alias
- If the token is a normal token, plz make sure the format is like this
{
"color": {
"test": {
"value": "#ff0000"
}
}
}- If the token is deprecated, plz make sure the format is like this
{
"color": {
"test": {
"value": "#ff0000",
"deprecated": true
}
}
}Generate the SCSS file with latest token values
- The command below will generate the public
.scssfiles and testing.module.scssfiles with the latest token values from the JSON files
pnpm run buildHow to update mixins ?
- The mixins are stored in the
mixinsfolder.- The mixins are written in SCSS format.
- The
-base.scssfiles are the base mixins that are used in the other mixins. - The
.scssfiles are the mixins that are used in the components. - The
-use-cases.scssfiles are the use cases of the mixins, which contain implemented classes.
- All the mixins are eventually rolled up in the
index.scssfile.
Usage
Include the global styles to normalize the styling environment
// In your top-level SCSS file (e.g. App.scss)
@import '~@strategies/tokens';If you are using vite, please remove the tide ~ in the import statement, like this
// In your top-level SCSS file (e.g. App.scss)
@import '@strategies/tokens';Using the tokens in CSS or SCSS file
@use '~@strategies/tokens/color';
@use '~@strategies/tokens/font';
.YourComponent {
color: color.$blue;
font-size: font.$size-small;
}Using the tokens in js/jsx/ts/tsx file
- the `token`` function is for getting the value by passing in a path string
- to use the
tokenfunction, please install another package@strategeies/ui
pnpm add --save-dev @strategies/tokens- usage example
import { ConfigProvider } from 'antd'
import { token } from '@strategeies/tokens'
export const ButtonAntConfig = ({ children }) => {
return (
<ConfigProvider
theme={{
token: {
/* token fn here */
colorPrimary: token('color.text.danger', '#ff0000'),
},
}}
>
{children}
</ConfigProvider>
)
}
export default ButtonAntConfigImplement default value (for DEV)
- If the token path is not found, the default value will be used
- Both of the following formats are supported.
- If some tokens are missing in the
SCSSbuilt file, plz check theconvertJsonToScssfunction inutilsfolder
{
"color": {
"value": "#ff0000",
"dark": {
"value": "#ff0000"
}
}
}{
"color": {
"default": { "value": "#ff0000" },
"dark": {
"value": "#ff0000"
}
}
}