Skip to content

Commit f91c435

Browse files
Using upstream config from primer/primitives (#726)
* using upstream transforms * replace custom-media * rm unused stuff
1 parent 98fa3a2 commit f91c435

File tree

5 files changed

+69
-138
lines changed

5 files changed

+69
-138
lines changed

package-lock.json

+52-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/design-tokens/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
"test": "jest"
3434
},
3535
"devDependencies": {
36-
"@primer/primitives": "9.0.2",
36+
"@primer/primitives": "9.1.0",
37+
"prettier": "^2.8.8",
38+
"@prettier/sync": "^0.5.2",
3739
"color2k": "^2.0.2",
3840
"fast-glob": "3.3.2",
3941
"style-dictionary": "3.8.0"

packages/design-tokens/scripts/build-tokens.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,5 @@ const darkJson = require('../src/tokens/base/colors/dark')
276276
* Step 4:
277277
* Clean up the temporary directory
278278
*/
279-
fs.rmdirSync(dest, {recursive: true})
279+
fs.rmSync(dest, {recursive: true})
280280
})()

packages/design-tokens/scripts/style-dictionary.js

+7-118
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,18 @@
33
*/
44

55
const glob = require('fast-glob')
6-
const StyleDictionary = require('style-dictionary')
6+
const {PrimerStyleDictionary} = require('@primer/primitives/dist/build/PrimerStyleDictionary.js')
7+
8+
const StyleDictionary = PrimerStyleDictionary
79

810
const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers
911

1012
//-----
1113
// functions to be extracted
1214
// TODO: extract to a separate files
1315

14-
const pathToKebabCase = token => token.path.join('-')
15-
16-
const pathToDotNotation = token => token.path.join('.')
17-
18-
const capitalize = string => string[0].toUpperCase() + string.slice(1)
19-
20-
const pathToPascalCase = token => token.path.map(tokenPathItems => capitalize(tokenPathItems)).join('')
21-
2216
// REGISTER THE CUSTOM TRANFORMS
2317

24-
/**
25-
* transform: scss variable names
26-
* example: `$namespace-item-variant-property-modifier`
27-
*/
28-
StyleDictionary.registerTransform({
29-
name: 'name/scss',
30-
type: 'name',
31-
transformer: pathToKebabCase,
32-
})
33-
34-
/**
35-
* transform: css variable names
36-
* example: `--namespace-item-variant-property-modifier`
37-
*/
38-
StyleDictionary.registerTransform({
39-
name: 'name/css',
40-
type: 'name',
41-
transformer: pathToKebabCase,
42-
})
43-
44-
/**
45-
* transform: js variable names
46-
* example: `namespace.item.variant.property.modifier`
47-
*/
48-
StyleDictionary.registerTransform({
49-
name: 'name/js',
50-
type: 'name',
51-
transformer: pathToDotNotation,
52-
})
53-
54-
/**
55-
* transform: js es6 variable names
56-
* example: `NamespaceItemVariantPropertyModifier`
57-
*/
58-
StyleDictionary.registerTransform({
59-
name: 'name/js/es6',
60-
type: 'name',
61-
transformer: pathToPascalCase,
62-
})
63-
6418
// find values with px unit
6519
function isPx(value) {
6620
return /[\d.]+px$/.test(value)
@@ -93,68 +47,16 @@ StyleDictionary.registerTransform({
9347
},
9448
})
9549

96-
//-----
97-
98-
// ts output
99-
StyleDictionary.registerTransform({
100-
name: 'attribute/typescript',
101-
type: 'attribute',
102-
transformer: token => {
103-
return {
104-
typescript: {
105-
// these transforms will need to match the ones you use for typescript
106-
// or you can "chain" the transforms and use token.name and token.value
107-
// like scss and less transforms do.
108-
name: token.path.slice(1).join('.'),
109-
value: token.value,
110-
},
111-
}
112-
},
113-
})
114-
115-
// css output
116-
StyleDictionary.registerTransform({
117-
name: 'attribute/css',
118-
type: 'attribute',
119-
transformer: token => {
120-
const tokenName = token.path.slice(1).join('-')
121-
return {
122-
css: {
123-
name: `--${tokenName}`,
124-
value: token.value,
125-
},
126-
}
127-
},
128-
})
129-
130-
// transform: composite typography to shorthands
131-
StyleDictionary.registerTransform({
132-
name: 'typography/shorthand',
133-
type: 'value',
134-
transitive: true,
135-
matcher: token => token.type === 'typography',
136-
transformer: token => {
137-
const {value} = token
138-
139-
// if lineHeight has value, include in shorthand
140-
if (value.lineHeight) {
141-
return `${value.fontWeight} ${value.fontSize}/${value.lineHeight} ${value.fontFamily}`
142-
}
143-
144-
return `${value.fontWeight} ${value.fontSize} ${value.fontFamily}`
145-
},
146-
})
147-
14850
// REGISTER THE CUSTOM TRANFORM GROUPS
14951

15052
StyleDictionary.registerTransformGroup({
15153
name: 'css',
152-
transforms: ['name/css', 'pxToRem', 'typography/shorthand'],
54+
transforms: ['name/pathToKebabCase', 'pxToRem', 'typography/css'],
15355
})
15456

15557
StyleDictionary.registerTransformGroup({
15658
name: 'scss',
157-
transforms: ['name/scss', 'pxToRem', 'typography/shorthand'],
59+
transforms: ['name/pathToKebabCase', 'pxToRem', 'typography/css'],
15860
})
15961

16062
// REGISTER A CUSTOM FORMAT
@@ -187,19 +89,6 @@ StyleDictionary.registerFormat({
18789
},
18890
})
18991

190-
StyleDictionary.registerFormat({
191-
name: 'custom/format/custom-media',
192-
formatter({dictionary}) {
193-
return dictionary.allProperties
194-
.map(prop => {
195-
const {value, name} = prop
196-
197-
return `@custom-media --${name}-viewport ${value};`
198-
})
199-
.join('\n')
200-
},
201-
})
202-
20392
// format docs
20493
StyleDictionary.registerFormat({
20594
name: 'json/docs',
@@ -398,7 +287,7 @@ function buildPrimitives(
398287
files: [
399288
{
400289
filter: token => token.filePath.includes('viewport'),
401-
format: 'custom/format/custom-media',
290+
format: 'css/customMedia',
402291
destination: 'viewport.css',
403292
},
404293
],
@@ -420,7 +309,7 @@ function buildPrimitives(
420309
},
421310
js: {
422311
buildPath: `${outputPath}/js/`,
423-
transforms: ['name/js/es6', 'pxToRem'],
312+
transforms: ['name/pathToPascalCase', 'pxToRem'],
424313
// map the array of token file paths to style dictionary output files
425314
files: files.map(filePath => {
426315
return {

packages/design-tokens/src/tokens/functional/size/viewport.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
22
"brand": {
33
"viewportRange": {
4-
"narrow": {
4+
"narrow-viewport": {
55
"$value": "(max-width: calc({brand.breakpoint.medium} - 0.02px))",
66
"$type": "custom-viewportRange"
77
},
8-
"narrowLandscape": {
8+
"narrowLandscape-viewport": {
99
"$value": "(max-width: calc({brand.breakpoint.large} - 0.02px) and (max-height: calc({brand.breakpoint.small} - 0.02px)) and (orientation: landscape))",
1010
"$type": "custom-viewportRange"
1111
},
12-
"regular": {
12+
"regular-viewport": {
1313
"$value": "(min-width: {brand.breakpoint.medium})",
1414
"$type": "custom-viewportRange"
1515
},
16-
"wide": {
16+
"wide-viewport": {
1717
"$value": "(min-width: {brand.breakpoint.xxlarge})",
1818
"$type": "custom-viewportRange"
1919
},
20-
"portrait": {
20+
"portrait-viewport": {
2121
"$value": "(orientation: portrait)",
2222
"$type": "custom-viewportRange"
2323
},
24-
"landscape": {
24+
"landscape-viewport": {
2525
"$value": "(orientation: landscape)",
2626
"$type": "custom-viewportRange"
2727
}

0 commit comments

Comments
 (0)