@primer/primitives 7.9.0 → 7.10.0-rc.15b37d5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +3 -4
  3. package/build.js +81 -47
  4. package/dist/color-contrast-check.json +1 -0
  5. package/dist/js/colors/dark.d.ts +5 -0
  6. package/dist/js/colors/dark.js +6 -1
  7. package/dist/js/colors/dark_colorblind.d.ts +5 -0
  8. package/dist/js/colors/dark_colorblind.js +6 -1
  9. package/dist/js/colors/dark_dimmed.d.ts +5 -0
  10. package/dist/js/colors/dark_dimmed.js +6 -1
  11. package/dist/js/colors/dark_high_contrast.d.ts +5 -0
  12. package/dist/js/colors/dark_high_contrast.js +6 -1
  13. package/dist/js/colors/dark_tritanopia.d.ts +5 -0
  14. package/dist/js/colors/dark_tritanopia.js +6 -1
  15. package/dist/js/colors/index.d.ts +45 -0
  16. package/dist/js/colors/light.d.ts +5 -0
  17. package/dist/js/colors/light.js +5 -0
  18. package/dist/js/colors/light_colorblind.d.ts +5 -0
  19. package/dist/js/colors/light_colorblind.js +5 -0
  20. package/dist/js/colors/light_high_contrast.d.ts +5 -0
  21. package/dist/js/colors/light_high_contrast.js +5 -0
  22. package/dist/js/colors/light_tritanopia.d.ts +5 -0
  23. package/dist/js/colors/light_tritanopia.js +5 -0
  24. package/dist/js/index.d.ts +45 -0
  25. package/dist/json/colors/dark.json +6 -1
  26. package/dist/json/colors/dark_colorblind.json +6 -1
  27. package/dist/json/colors/dark_dimmed.json +6 -1
  28. package/dist/json/colors/dark_high_contrast.json +6 -1
  29. package/dist/json/colors/dark_tritanopia.json +6 -1
  30. package/dist/json/colors/light.json +5 -0
  31. package/dist/json/colors/light_colorblind.json +5 -0
  32. package/dist/json/colors/light_high_contrast.json +5 -0
  33. package/dist/json/colors/light_tritanopia.json +5 -0
  34. package/dist/scss/colors/_dark.scss +2 -1
  35. package/dist/scss/colors/_dark_colorblind.scss +2 -1
  36. package/dist/scss/colors/_dark_dimmed.scss +2 -1
  37. package/dist/scss/colors/_dark_high_contrast.scss +2 -1
  38. package/dist/scss/colors/_dark_tritanopia.scss +2 -1
  39. package/dist/scss/colors/_light.scss +1 -0
  40. package/dist/scss/colors/_light_colorblind.scss +1 -0
  41. package/dist/scss/colors/_light_high_contrast.scss +1 -0
  42. package/dist/scss/colors/_light_tritanopia.scss +1 -0
  43. package/dist/ts/colors/dark.ts +6 -1
  44. package/dist/ts/colors/dark_colorblind.ts +6 -1
  45. package/dist/ts/colors/dark_dimmed.ts +6 -1
  46. package/dist/ts/colors/dark_high_contrast.ts +6 -1
  47. package/dist/ts/colors/dark_tritanopia.ts +6 -1
  48. package/dist/ts/colors/light.ts +5 -0
  49. package/dist/ts/colors/light_colorblind.ts +5 -0
  50. package/dist/ts/colors/light_high_contrast.ts +5 -0
  51. package/dist/ts/colors/light_tritanopia.ts +5 -0
  52. package/package.json +25 -4
  53. package/tokens-v2-private/css/tokens/base/size/size.css +1 -1
  54. package/tokens-v2-private/css/tokens/base/typography/typography.css +1 -1
  55. package/tokens-v2-private/css/tokens/functional/size/border.css +1 -1
  56. package/tokens-v2-private/css/tokens/functional/size/breakpoints.css +1 -1
  57. package/tokens-v2-private/css/tokens/functional/size/size-coarse.css +3 -2
  58. package/tokens-v2-private/css/tokens/functional/size/size-fine.css +3 -2
  59. package/tokens-v2-private/css/tokens/functional/size/size.css +1 -1
  60. package/tokens-v2-private/css/tokens/functional/typography/typography.css +1 -1
  61. package/tokens-v2-private/js/module/tokens/base/size/size.js +1 -1
  62. package/tokens-v2-private/js/module/tokens/base/typography/typography.js +1 -1
  63. package/tokens-v2-private/js/module/tokens/functional/size/border.js +1 -1
  64. package/tokens-v2-private/js/module/tokens/functional/size/breakpoints.js +1 -1
  65. package/tokens-v2-private/js/module/tokens/functional/size/size-coarse.js +1 -1
  66. package/tokens-v2-private/js/module/tokens/functional/size/size-fine.js +1 -1
  67. package/tokens-v2-private/js/module/tokens/functional/size/size.js +1 -1
  68. package/tokens-v2-private/js/module/tokens/functional/size/viewport.js +1 -1
  69. package/tokens-v2-private/js/module/tokens/functional/typography/typography.js +1 -1
  70. package/tokens-v2-private/js/tokens/base/size/size.js +1 -1
  71. package/tokens-v2-private/js/tokens/base/typography/typography.js +1 -1
  72. package/tokens-v2-private/js/tokens/functional/size/border.js +1 -1
  73. package/tokens-v2-private/js/tokens/functional/size/breakpoints.js +1 -1
  74. package/tokens-v2-private/js/tokens/functional/size/size-coarse.js +1 -1
  75. package/tokens-v2-private/js/tokens/functional/size/size-fine.js +1 -1
  76. package/tokens-v2-private/js/tokens/functional/size/size.js +1 -1
  77. package/tokens-v2-private/js/tokens/functional/size/viewport.js +1 -1
  78. package/tokens-v2-private/js/tokens/functional/typography/typography.js +1 -1
  79. package/tokens-v2-private/scss/tokens/base/size/size.scss +21 -0
  80. package/tokens-v2-private/scss/tokens/base/typography/typography.scss +8 -0
  81. package/tokens-v2-private/scss/tokens/functional/size/border.scss +14 -0
  82. package/tokens-v2-private/scss/tokens/functional/size/breakpoints.scss +10 -0
  83. package/tokens-v2-private/scss/tokens/functional/size/size-coarse.scss +7 -0
  84. package/tokens-v2-private/scss/tokens/functional/size/size-fine.scss +7 -0
  85. package/tokens-v2-private/scss/tokens/functional/size/size.scss +51 -0
  86. package/tokens-v2-private/scss/tokens/functional/size/viewport.scss +10 -0
  87. package/tokens-v2-private/scss/tokens/functional/typography/typography.scss +44 -0
  88. package/tokens-v2-private/ts/tokens/base/size/size.d.ts +4 -2
  89. package/tokens-v2-private/ts/tokens/base/size/size.js +3 -1
  90. package/tokens-v2-private/ts/tokens/base/typography/typography.d.ts +4 -2
  91. package/tokens-v2-private/ts/tokens/base/typography/typography.js +3 -1
  92. package/tokens-v2-private/ts/tokens/functional/size/border.d.ts +4 -2
  93. package/tokens-v2-private/ts/tokens/functional/size/border.js +3 -1
  94. package/tokens-v2-private/ts/tokens/functional/size/breakpoints.d.ts +4 -2
  95. package/tokens-v2-private/ts/tokens/functional/size/breakpoints.js +3 -1
  96. package/tokens-v2-private/ts/tokens/functional/size/size-coarse.d.ts +4 -2
  97. package/tokens-v2-private/ts/tokens/functional/size/size-coarse.js +3 -1
  98. package/tokens-v2-private/ts/tokens/functional/size/size-fine.d.ts +4 -2
  99. package/tokens-v2-private/ts/tokens/functional/size/size-fine.js +3 -1
  100. package/tokens-v2-private/ts/tokens/functional/size/size.d.ts +4 -2
  101. package/tokens-v2-private/ts/tokens/functional/size/size.js +3 -1
  102. package/tokens-v2-private/ts/tokens/functional/size/viewport.d.ts +4 -2
  103. package/tokens-v2-private/ts/tokens/functional/size/viewport.js +3 -1
  104. package/tokens-v2-private/ts/tokens/functional/typography/typography.d.ts +4 -2
  105. package/tokens-v2-private/ts/tokens/functional/typography/typography.js +3 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @primer/primitives
2
2
 
3
+ ## 7.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#354](https://github.com/primer/primitives/pull/354) [`3b28659`](https://github.com/primer/primitives/commit/3b286594aed3d4de97866d354f050f7e59945e95) Thanks [@mperrotti](https://github.com/mperrotti)! - Introduces TreeView.Item component color primitives
8
+
9
+ ### Patch Changes
10
+
11
+ - [#351](https://github.com/primer/primitives/pull/351) [`d8d2480`](https://github.com/primer/primitives/commit/d8d2480c1ec971dca7dd9b1026cf445663f1ae03) Thanks [@langermank](https://github.com/langermank)! - Add SCSS vars for PCSS utilities & dotcom
12
+
3
13
  ## 7.9.0
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -6,7 +6,6 @@ This repo contains values for color, spacing, and typography primitives for use
6
6
 
7
7
  ![primer primitives diagram](https://user-images.githubusercontent.com/4608155/135384588-192c279f-020f-4544-a61f-559be6629f18.png)
8
8
 
9
-
10
9
  ## Install
11
10
 
12
11
  This repository is distributed on [npm][npm]. After [installing npm][install-npm], you can install `@primer/primitives` with this command.
@@ -35,15 +34,15 @@ To deprecate a variable, define a mapping from the deprecated variable to its re
35
34
  ...
36
35
  ```
37
36
 
38
- ```js
37
+ ```
39
38
  // data/colors/deprecated.json
40
- {
39
+
41
40
  {
42
41
  "text.primary": "fg.default", // this means: `text.primary` is deprecated. Use `fg.default` instead
43
42
  "auto.blue.4": ["accent.fg, accent.emphasis"], // this means: `auto.blue.4` is deprecated. Use `accent.fg` or `accent.emphasis` instead
44
43
  "text.white": null // this means: `text.white` is deprecated. We don't have a replacement for it
45
44
  }
46
- }
45
+
47
46
  ```
48
47
 
49
48
  During the build process, the `deprecated.json` files will be added to a `dist/deprecated` directory organized by variable category:
package/build.js CHANGED
@@ -3,8 +3,30 @@ const StyleDictionary = require('style-dictionary')
3
3
 
4
4
  const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers
5
5
 
6
+ //-----
7
+ // functions to be extracted
8
+ // TODO: extract to a separate files
9
+
10
+ const pathToKebabCase = token => token.path.join('-')
11
+
12
+ const pathToDotNotation = token => token.path.join('.')
13
+
14
+ const capitalize = string => string[0].toUpperCase() + string.slice(1)
15
+
16
+ const pathToPascalCase = token => token.path.map(tokenPathItems => capitalize(tokenPathItems)).join('')
17
+
6
18
  // REGISTER THE CUSTOM TRANFORMS
7
19
 
20
+ /**
21
+ * transform: scss variable names
22
+ * example: `$namespace-item-variant-property-modifier`
23
+ */
24
+ StyleDictionary.registerTransform({
25
+ name: 'name/scss',
26
+ type: 'name',
27
+ transformer: pathToKebabCase
28
+ })
29
+
8
30
  /**
9
31
  * transform: css variable names
10
32
  * example: `--namespace-item-variant-property-modifier`
@@ -12,9 +34,7 @@ const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers
12
34
  StyleDictionary.registerTransform({
13
35
  name: 'name/css',
14
36
  type: 'name',
15
- transformer: (token, options) => {
16
- return token.path.join('-')
17
- }
37
+ transformer: pathToKebabCase
18
38
  })
19
39
 
20
40
  /**
@@ -24,9 +44,7 @@ StyleDictionary.registerTransform({
24
44
  StyleDictionary.registerTransform({
25
45
  name: 'name/js',
26
46
  type: 'name',
27
- transformer: (token, options) => {
28
- return token.path.join('.')
29
- }
47
+ transformer: pathToDotNotation
30
48
  })
31
49
 
32
50
  /**
@@ -36,27 +54,19 @@ StyleDictionary.registerTransform({
36
54
  StyleDictionary.registerTransform({
37
55
  name: 'name/js/es6',
38
56
  type: 'name',
39
- transformer: (token, options) => {
40
- const tokenPath = token.path.join(' ')
41
- const tokenPathItems = tokenPath.split(' ')
42
- for (var i = 0; i < tokenPathItems.length; i++) {
43
- tokenPathItems[i] = tokenPathItems[i].charAt(0).toUpperCase() + tokenPathItems[i].slice(1)
44
- }
45
- const tokenName = tokenPathItems.join('')
46
- return tokenName
47
- }
57
+ transformer: pathToPascalCase
48
58
  })
49
59
 
50
60
  // find values with px unit
51
61
  function isPx(value) {
52
- return /[\d\.]+px$/.test(value)
62
+ return /[\d.]+px$/.test(value)
53
63
  }
54
64
 
55
65
  // transform: px to rem
56
66
  StyleDictionary.registerTransform({
57
67
  name: 'pxToRem',
58
68
  type: 'value',
59
- transformer: (token, options) => {
69
+ transformer: token => {
60
70
  if (isPx(token.value)) {
61
71
  const baseFontSize = 16
62
72
  const floatValue = parseFloat(token.value.replace('px', ''))
@@ -138,33 +148,38 @@ StyleDictionary.registerTransformGroup({
138
148
  transforms: ['name/css', 'pxToRem', 'typography/shorthand']
139
149
  })
140
150
 
151
+ StyleDictionary.registerTransformGroup({
152
+ name: 'scss',
153
+ transforms: ['name/scss', 'pxToRem', 'typography/shorthand']
154
+ })
155
+
141
156
  // REGISTER A CUSTOM FORMAT
142
157
 
143
158
  // wrap mobile tokens in media query
144
159
  StyleDictionary.registerFormat({
145
160
  name: 'css/touch-target-mobile',
146
- formatter: function({dictionary, file, options}) {
161
+ formatter({dictionary, file, options}) {
147
162
  const {outputReferences} = options
148
- return (
149
- fileHeader({file}) +
150
- `@media (pointer: coarse) { :root {\n` +
151
- formattedVariables({format: 'css', dictionary, outputReferences}) +
152
- '\n}}\n'
153
- )
163
+ return `${fileHeader({file})}
164
+ @media (pointer: coarse) { :root {\n${formattedVariables({
165
+ format: 'css',
166
+ dictionary,
167
+ outputReferences
168
+ })}\n}}\n`
154
169
  }
155
170
  })
156
171
 
157
172
  // wrap desktop tokens in media query
158
173
  StyleDictionary.registerFormat({
159
174
  name: 'css/touch-target-desktop',
160
- formatter: function({dictionary, file, options}) {
175
+ formatter({dictionary, file, options}) {
161
176
  const {outputReferences} = options
162
- return (
163
- fileHeader({file}) +
164
- `@media (pointer: fine) { :root {\n` +
165
- formattedVariables({format: 'css', dictionary, outputReferences}) +
166
- '\n}}\n'
167
- )
177
+ return `${fileHeader({file})}
178
+ @media (pointer: fine) { :root {\n${formattedVariables({
179
+ format: 'css',
180
+ dictionary,
181
+ outputReferences
182
+ })}\n}}\n`
168
183
  }
169
184
  })
170
185
 
@@ -173,9 +188,8 @@ StyleDictionary.registerFormat({
173
188
  formatter({dictionary}) {
174
189
  return dictionary.allProperties
175
190
  .map(prop => {
176
- const {value, path, name} = prop
177
- // const tokenPath = path
178
- // const tokenProperty = path[path.length - 1]
191
+ const {value, name} = prop
192
+
179
193
  return `@custom-media --${name}-viewport ${value};`
180
194
  })
181
195
  .join('\n')
@@ -185,7 +199,7 @@ StyleDictionary.registerFormat({
185
199
  // format docs
186
200
  StyleDictionary.registerFormat({
187
201
  name: 'json/docs',
188
- formatter: function({dictionary}) {
202
+ formatter({dictionary}) {
189
203
  const groupedTokens = groupBy(dictionary.allProperties, 'filePath')
190
204
 
191
205
  return JSON.stringify(groupedTokens, null, 2)
@@ -197,7 +211,7 @@ StyleDictionary.registerFormat({
197
211
  */
198
212
  StyleDictionary.registerFormat({
199
213
  name: 'javascript/module-v2',
200
- formatter: function({dictionary, file}) {
214
+ formatter({dictionary, file}) {
201
215
  const recursiveleyFlattenDictionary = obj => {
202
216
  const tree = {}
203
217
  if (typeof obj !== 'object' || Array.isArray(obj)) {
@@ -216,11 +230,9 @@ StyleDictionary.registerFormat({
216
230
  return tree
217
231
  }
218
232
 
219
- return (
220
- fileHeader({file}) +
221
- 'module.exports = ' +
222
- JSON.stringify(recursiveleyFlattenDictionary(dictionary.tokens), null, 2)
223
- )
233
+ return `${fileHeader({file})}
234
+
235
+ module.exports = ${JSON.stringify(recursiveleyFlattenDictionary(dictionary.tokens), null, 2)}`
224
236
  }
225
237
  })
226
238
 
@@ -230,7 +242,7 @@ StyleDictionary.registerFormat({
230
242
  */
231
243
  StyleDictionary.registerFormat({
232
244
  name: 'typescript/module-declarations-v2',
233
- formatter: function({dictionary, options, file}) {
245
+ formatter({dictionary, options, file}) {
234
246
  const {moduleName = `tokens`} = options
235
247
 
236
248
  const getType = value => {
@@ -268,10 +280,10 @@ StyleDictionary.registerFormat({
268
280
  return tree
269
281
  }
270
282
 
271
- const output =
272
- fileHeader({file}) +
273
- `declare const ${moduleName}: ${JSON.stringify(recursiveTypeGeneration(dictionary.tokens), null, 2)}
274
- export default ${moduleName};`
283
+ const output = `${fileHeader({file})}
284
+
285
+ declare const ${moduleName}: ${JSON.stringify(recursiveTypeGeneration(dictionary.tokens), null, 2)}
286
+ export default ${moduleName};`
275
287
 
276
288
  return output
277
289
  .replace(/"any"/g, 'any')
@@ -326,7 +338,9 @@ function buildPrimitives(
326
338
  {source, outputPath = 'tokens-v2-private', include, platforms, namespace = 'primer'},
327
339
  _StyleDictionary = StyleDictionary
328
340
  ) {
341
+ // eslint-disable-next-line no-console
329
342
  console.log('Build started...')
343
+ // eslint-disable-next-line no-console
330
344
  console.log('\n==============================================')
331
345
 
332
346
  const customParseConfig = {
@@ -345,6 +359,7 @@ function buildPrimitives(
345
359
 
346
360
  return JSON.parse(parsed)
347
361
  } catch (error) {
362
+ // eslint-disable-next-line no-console
348
363
  console.log(error)
349
364
  }
350
365
  }
@@ -380,6 +395,21 @@ function buildPrimitives(
380
395
  }
381
396
  ]
382
397
  },
398
+ scss: {
399
+ buildPath: `${outputPath}/scss/`,
400
+ transformGroup: 'scss',
401
+ // map the array of token file paths to style dictionary output files
402
+ files: files.map(filePath => {
403
+ return {
404
+ format: `scss/variables`,
405
+ destination: filePath.replace(`.json`, `.scss`),
406
+ filter: token => token.filePath === filePath,
407
+ options: {
408
+ outputReferences: true
409
+ }
410
+ }
411
+ })
412
+ },
383
413
  js: {
384
414
  buildPath: `${outputPath}/js/`,
385
415
  transforms: ['name/js/es6', 'pxToRem'],
@@ -540,5 +570,9 @@ function _init() {
540
570
  module.exports = {
541
571
  buildPrimitives,
542
572
  _init,
543
- StyleDictionary
573
+ StyleDictionary,
574
+ pathToKebabCase,
575
+ pathToDotNotation,
576
+ capitalize,
577
+ pathToPascalCase
544
578
  }