Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX-754 Style Dictionary #1029

Merged
merged 12 commits into from
Dec 6, 2021
15 changes: 3 additions & 12 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@
"version": "6.1.0",
"command": {
"publish": {
"ignoreChanges": [
"**/tests/**",
"**/*.md"
]
"ignoreChanges": ["**/tests/**", "**/*.md"]
},
"bootstrap": {
"npmClientArgs": [
"--no-package-lock"
]
"npmClientArgs": ["--no-package-lock"]
},
"version": {
"message": "Publish %s"
}
},
"ignoreChanges": [
"**/matchbox-site/**",
"**/tests/**",
"**/*.md"
]
"ignoreChanges": ["**/matchbox-site/**", "**/tests/**", "**/*.md"]
}
3 changes: 0 additions & 3 deletions packages/design-tokens/.npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/node_modules
/data
/gulpfile
/scripts

# misc
.DS_Store
Expand Down
24 changes: 17 additions & 7 deletions packages/design-tokens/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# design-tokens
# @sparkpost/design-tokens

Want to start using tokens? See:

- [Getting Started](https://design.sparkpost.com/design/tokens)
- [Getting Started](https://design.sparkpost.com/foundations/design-tokens)

Looking for documentation? See:

- [Design System Website](https://design.sparkpost.com)
- [Playroom](https://matchbox-playroom.netlify.app/)

Want to contribute? See:

Expand All @@ -18,9 +17,20 @@ Want to contribute? See:
Commands:

```bash
# Runs docs task and starts a local server at http://localhost:3000
npm run start

# Compiles tokens for packaging
# Compiles tokens
npm run build
```

Importing:

```css
@import '~@sparkpost/design-tokens/dist/css/tokens.css';
```

```css
@import '~@sparkpost/design-tokens/dist/scss/tokens.scss';
```

```js
import { tokens, tokens_next, tokens_legacy, meta } from '@sparkpost/design-tokens';
```
115 changes: 115 additions & 0 deletions packages/design-tokens/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
const { mapGet, utils, colorMapGet } = require('./templates/scss-functions');
const { toSnake, toCamel, toFriendly } = require('./utils/utils');
const transforms = require('style-dictionary/lib/common/transforms');

module.exports = {
source: ['tokens/**/*.json'],
platforms: {
// Generates css custom properties
css: {
transformGroup: 'css',
buildPath: 'dist/css/',
files: [
{
destination: 'tokens.css',
format: 'css/variables',
},
],
},
scss: {
transformGroup: 'scss',
buildPath: 'dist/scss/',
files: [
// Generates scss maps
{
destination: 'maps.scss',
format: 'scss/map-deep',
mapName: 'matchbox-tokens',
},
// Generates scss map functions
{
destination: 'tokens.scss',
format: 'scss/functions',
},
],
},
// Generates JS files in snake case
js: {
transformGroup: 'js',
buildPath: 'dist/js/',
transforms: ['name/cti/snake'],
files: [
{
destination: 'tokens.js',
format: 'javascript/module-flat',
},
],
},
// Generates JS files in the old format of snake & camel using a custom transform
js_legacy: {
transformGroup: 'js',
buildPath: 'dist/js/',
transforms: ['name/cti/legacy'],
files: [
{
destination: 'tokens.legacy.js',
format: 'javascript/module-flat',
},
],
},
// Generates meta JS file
js_meta: {
transformGroup: 'js',
buildPath: 'dist/meta/',
files: [
{
destination: 'meta.js',
format: 'javascript/meta',
},
],
},
},
transform: {
'name/cti/legacy': {
type: 'name',
transformer: (token) => {
const [category, ...rest] = token.path;
return `${toCamel(category)}_${toSnake(rest.join('-'))}`;
},
},
},
format: {
'scss/functions': (args) => {
const keys = Object.keys(args.dictionary.tokens);
const rootFontSize = args.dictionary.allTokens.find(({ name }) => name === 'font-size-root');
const functions = keys.map((key) => (key !== 'color' ? mapGet(key) : colorMapGet())).join('');
return `${utils(rootFontSize)}\n${functions}`;
},
'javascript/meta': (args) => {
const all = args.dictionary.allTokens;

const tokens = all
.map((token) => {
const { path, value, pixel_value } = token;
const [head, ...tail] = path;

return JSON.stringify({
category: head,
css: `--${path.join('-')}`,
friendly: toFriendly(path.join(' ')),
javascript: transforms['name/cti/snake'].transformer(token, {}),
name: path.join('-'),
pixel_value: pixel_value,
pixel_value_unitless: !!pixel_value ? pixel_value.replace(/px$/, '') : undefined,
scss: `${head}(${tail.join(',')})`,
system: tail.join('.'),
type: head,
value: head.match(/^color$/) ? value.toUpperCase() : value,
});
})
.join(',\n');

return `module.exports = [${tokens}]`;
},
},
};
9 changes: 0 additions & 9 deletions packages/design-tokens/formats/common.js.js

This file was deleted.

24 changes: 0 additions & 24 deletions packages/design-tokens/formats/deepMap.scss.js

This file was deleted.

18 changes: 0 additions & 18 deletions packages/design-tokens/formats/map.scss.js

This file was deleted.

55 changes: 0 additions & 55 deletions packages/design-tokens/formats/meta.js.js

This file was deleted.

56 changes: 0 additions & 56 deletions packages/design-tokens/formats/templates.js

This file was deleted.

Loading