@primer/primitives 8.0.0 → 8.1.0
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.
- package/dist/css/functional/size/size-coarse.css +0 -7
- package/dist/css/functional/size/size-fine.css +0 -7
- package/dist/css/functional/themes/dark-colorblind.css +10 -0
- package/dist/css/functional/themes/dark-dimmed.css +10 -0
- package/dist/css/functional/themes/dark-high-contrast.css +10 -0
- package/dist/css/functional/themes/dark-tritanopia.css +10 -0
- package/dist/css/functional/themes/dark.css +10 -0
- package/dist/css/functional/themes/light-colorblind.css +10 -0
- package/dist/css/functional/themes/light-high-contrast.css +10 -0
- package/dist/css/functional/themes/light-tritanopia.css +10 -0
- package/dist/css/functional/themes/light.css +10 -0
- package/dist/css/functional/typography/typography.css +12 -12
- package/dist/docs/functional/themes/dark-colorblind.json +145 -0
- package/dist/docs/functional/themes/dark-dimmed.json +145 -0
- package/dist/docs/functional/themes/dark-high-contrast.json +145 -0
- package/dist/docs/functional/themes/dark-tritanopia.json +145 -0
- package/dist/docs/functional/themes/dark.json +145 -0
- package/dist/docs/functional/themes/light-colorblind.json +145 -0
- package/dist/docs/functional/themes/light-high-contrast.json +145 -0
- package/dist/docs/functional/themes/light-tritanopia.json +145 -0
- package/dist/docs/functional/themes/light.json +145 -0
- package/dist/figma/themes/dark-colorblind.json +80 -0
- package/dist/figma/themes/dark-dimmed.json +80 -0
- package/dist/figma/themes/dark-high-contrast.json +80 -0
- package/dist/figma/themes/dark-tritanopia.json +80 -0
- package/dist/figma/themes/dark.json +80 -0
- package/dist/figma/themes/light-colorblind.json +80 -0
- package/dist/figma/themes/light-high-contrast.json +80 -0
- package/dist/figma/themes/light-tritanopia.json +80 -0
- package/dist/figma/themes/light.json +80 -0
- package/dist/figma/typography/typography.json +10 -10
- package/dist/internalCss/dark-colorblind.css +10 -0
- package/dist/internalCss/dark-dimmed.css +10 -0
- package/dist/internalCss/dark-high-contrast.css +10 -0
- package/dist/internalCss/dark-tritanopia.css +10 -0
- package/dist/internalCss/dark.css +10 -0
- package/dist/internalCss/light-colorblind.css +10 -0
- package/dist/internalCss/light-high-contrast.css +10 -0
- package/dist/internalCss/light-tritanopia.css +10 -0
- package/dist/internalCss/light.css +10 -0
- package/dist/styleLint/functional/themes/dark-colorblind.json +145 -0
- package/dist/styleLint/functional/themes/dark-dimmed.json +145 -0
- package/dist/styleLint/functional/themes/dark-high-contrast.json +145 -0
- package/dist/styleLint/functional/themes/dark-tritanopia.json +145 -0
- package/dist/styleLint/functional/themes/dark.json +145 -0
- package/dist/styleLint/functional/themes/light-colorblind.json +145 -0
- package/dist/styleLint/functional/themes/light-high-contrast.json +145 -0
- package/dist/styleLint/functional/themes/light-tritanopia.json +145 -0
- package/dist/styleLint/functional/themes/light.json +145 -0
- package/package.json +5 -7
- package/src/PrimerStyleDictionary.ts +9 -15
- package/src/formats/cssAdvanced.ts +99 -0
- package/src/formats/index.ts +1 -3
- package/src/platforms/css.ts +25 -17
- package/src/platforms/figma.ts +1 -1
- package/src/tokens/functional/color/dark/display-dark.json5 +66 -0
- package/src/tokens/functional/color/light/display-light.json5 +66 -0
- package/src/transformers/floatToPixel.ts +9 -2
- package/src/transformers/index.ts +1 -0
- package/src/formats/cssThemed.ts +0 -35
- package/src/formats/cssVariables.ts +0 -25
- package/src/formats/cssWrapMediaQuery.ts +0 -29
package/src/platforms/css.ts
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import {isFromFile, isSource} from '../filters'
|
|
2
2
|
import type StyleDictionary from 'style-dictionary'
|
|
3
3
|
import type {PlatformInitializer} from '../types/PlatformInitializer'
|
|
4
|
+
import type {TransformedToken} from 'style-dictionary'
|
|
4
5
|
|
|
5
|
-
const getCssSelectors = (outputFile: string)
|
|
6
|
+
const getCssSelectors = (outputFile: string) => {
|
|
6
7
|
// check for dark in the beginning of the output filename
|
|
7
8
|
const lastSlash = outputFile.lastIndexOf('/')
|
|
8
9
|
const outputBasename = outputFile.substring(lastSlash + 1, outputFile.indexOf('.'))
|
|
9
10
|
const themeName = outputBasename.replace(/-/g, '_')
|
|
10
11
|
const mode = outputBasename.substring(0, 4) === 'dark' ? 'dark' : 'light'
|
|
11
12
|
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
selector: `[data-color-mode="${mode}"][data-${mode}-theme="${themeName}"], [data-color-mode="${mode}"][data-${mode}-theme="${themeName}"] ::backdrop, [data-color-mode="auto"][data-light-theme="${themeName}"], [data-color-mode="auto"][data-light-theme="${themeName}"] ::backdrop`,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
query: '@media (prefers-color-scheme: dark)',
|
|
19
|
+
selector: `[data-color-mode="auto"][data-dark-theme="${themeName}"], [data-color-mode="auto"][data-dark-theme="${themeName}"] ::backdrop`,
|
|
20
|
+
},
|
|
21
|
+
]
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
export const css: PlatformInitializer = (outputFile, prefix, buildPath, options): StyleDictionary.Platform => {
|
|
20
|
-
const {selector, selectorLight, selectorDark} = getCssSelectors(outputFile)
|
|
21
25
|
return {
|
|
22
26
|
prefix,
|
|
23
27
|
buildPath,
|
|
@@ -40,21 +44,19 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
|
|
|
40
44
|
files: [
|
|
41
45
|
{
|
|
42
46
|
destination: `${outputFile}`,
|
|
43
|
-
format: `css/
|
|
47
|
+
format: `css/advanced`,
|
|
44
48
|
filter: token => isSource(token) && options?.themed === true,
|
|
45
49
|
options: {
|
|
46
50
|
showFileHeader: false,
|
|
47
51
|
outputReferences: false,
|
|
48
52
|
descriptions: false,
|
|
49
|
-
|
|
50
|
-
selectorLight,
|
|
51
|
-
selectorDark,
|
|
53
|
+
queries: getCssSelectors(outputFile),
|
|
52
54
|
...options?.options,
|
|
53
55
|
},
|
|
54
56
|
},
|
|
55
57
|
{
|
|
56
58
|
destination: `${outputFile}`,
|
|
57
|
-
format: `css/
|
|
59
|
+
format: `css/advanced`,
|
|
58
60
|
filter: token => isSource(token) && options?.themed !== true,
|
|
59
61
|
options: {
|
|
60
62
|
showFileHeader: false,
|
|
@@ -72,7 +74,7 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
|
|
|
72
74
|
},
|
|
73
75
|
{
|
|
74
76
|
destination: `${outputFile}`,
|
|
75
|
-
format: `css/
|
|
77
|
+
format: `css/advanced`,
|
|
76
78
|
filter: token =>
|
|
77
79
|
isSource(token) &&
|
|
78
80
|
isFromFile(token, [
|
|
@@ -82,10 +84,16 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
|
|
|
82
84
|
options: {
|
|
83
85
|
descriptions: false,
|
|
84
86
|
showFileHeader: false,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
queries: [
|
|
88
|
+
{
|
|
89
|
+
query: '@media (pointer: fine)',
|
|
90
|
+
matcher: (token: TransformedToken) => token.path.includes('size-fine'),
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
query: '@media (pointer: coarse)',
|
|
94
|
+
matcher: (token: TransformedToken) => token.path.includes('size-coarse'),
|
|
95
|
+
},
|
|
96
|
+
],
|
|
89
97
|
},
|
|
90
98
|
},
|
|
91
99
|
],
|
package/src/platforms/figma.ts
CHANGED
|
@@ -28,7 +28,7 @@ export const figma: PlatformInitializer = (outputFile, prefix, buildPath, option
|
|
|
28
28
|
// 'name/pathToSlashNotation',
|
|
29
29
|
'figma/attributes',
|
|
30
30
|
'fontFamily/figma',
|
|
31
|
-
'float/
|
|
31
|
+
'float/pixelUnitless',
|
|
32
32
|
'dimension/pixelUnitless',
|
|
33
33
|
// 'border/figma',
|
|
34
34
|
// 'typography/figma',
|
|
@@ -330,6 +330,72 @@
|
|
|
330
330
|
},
|
|
331
331
|
},
|
|
332
332
|
},
|
|
333
|
+
coral: {
|
|
334
|
+
bgColor: {
|
|
335
|
+
muted: {
|
|
336
|
+
$value: '{base.display.color.red.0}',
|
|
337
|
+
$type: 'color',
|
|
338
|
+
$extensions: {
|
|
339
|
+
'org.primer.figma': {
|
|
340
|
+
collection: 'mode',
|
|
341
|
+
mode: 'light',
|
|
342
|
+
group: 'component (internal)',
|
|
343
|
+
scopes: ['bgColor'],
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
emphasis: {
|
|
348
|
+
$value: '{base.display.color.red.5}',
|
|
349
|
+
$type: 'color',
|
|
350
|
+
$extensions: {
|
|
351
|
+
'org.primer.figma': {
|
|
352
|
+
collection: 'mode',
|
|
353
|
+
mode: 'light',
|
|
354
|
+
group: 'component (internal)',
|
|
355
|
+
scopes: ['bgColor'],
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
fgColor: {
|
|
361
|
+
$value: '{base.display.color.red.6}',
|
|
362
|
+
$type: 'color',
|
|
363
|
+
$extensions: {
|
|
364
|
+
'org.primer.figma': {
|
|
365
|
+
collection: 'mode',
|
|
366
|
+
mode: 'light',
|
|
367
|
+
group: 'component (internal)',
|
|
368
|
+
scopes: ['fgColor'],
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
borderColor: {
|
|
373
|
+
muted: {
|
|
374
|
+
$value: '{base.display.color.red.1}',
|
|
375
|
+
$type: 'color',
|
|
376
|
+
$extensions: {
|
|
377
|
+
'org.primer.figma': {
|
|
378
|
+
collection: 'mode',
|
|
379
|
+
mode: 'light',
|
|
380
|
+
group: 'component (internal)',
|
|
381
|
+
scopes: ['borderColor'],
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
emphasis: {
|
|
386
|
+
$value: '{base.display.color.red.5}',
|
|
387
|
+
$type: 'color',
|
|
388
|
+
$extensions: {
|
|
389
|
+
'org.primer.figma': {
|
|
390
|
+
collection: 'mode',
|
|
391
|
+
mode: 'light',
|
|
392
|
+
group: 'component (internal)',
|
|
393
|
+
scopes: ['borderColor'],
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
},
|
|
333
399
|
yellow: {
|
|
334
400
|
bgColor: {
|
|
335
401
|
muted: {
|
|
@@ -330,6 +330,72 @@
|
|
|
330
330
|
},
|
|
331
331
|
},
|
|
332
332
|
},
|
|
333
|
+
coral: {
|
|
334
|
+
bgColor: {
|
|
335
|
+
muted: {
|
|
336
|
+
$value: '{base.display.color.coral.0}',
|
|
337
|
+
$type: 'color',
|
|
338
|
+
$extensions: {
|
|
339
|
+
'org.primer.figma': {
|
|
340
|
+
collection: 'mode',
|
|
341
|
+
mode: 'light',
|
|
342
|
+
group: 'component (internal)',
|
|
343
|
+
scopes: ['bgColor'],
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
emphasis: {
|
|
348
|
+
$value: '{base.display.color.coral.5}',
|
|
349
|
+
$type: 'color',
|
|
350
|
+
$extensions: {
|
|
351
|
+
'org.primer.figma': {
|
|
352
|
+
collection: 'mode',
|
|
353
|
+
mode: 'light',
|
|
354
|
+
group: 'component (internal)',
|
|
355
|
+
scopes: ['bgColor'],
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
fgColor: {
|
|
361
|
+
$value: '{base.display.color.coral.6}',
|
|
362
|
+
$type: 'color',
|
|
363
|
+
$extensions: {
|
|
364
|
+
'org.primer.figma': {
|
|
365
|
+
collection: 'mode',
|
|
366
|
+
mode: 'light',
|
|
367
|
+
group: 'component (internal)',
|
|
368
|
+
scopes: ['fgColor'],
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
borderColor: {
|
|
373
|
+
muted: {
|
|
374
|
+
$value: '{base.display.color.coral.1}',
|
|
375
|
+
$type: 'color',
|
|
376
|
+
$extensions: {
|
|
377
|
+
'org.primer.figma': {
|
|
378
|
+
collection: 'mode',
|
|
379
|
+
mode: 'light',
|
|
380
|
+
group: 'component (internal)',
|
|
381
|
+
scopes: ['borderColor'],
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
emphasis: {
|
|
386
|
+
$value: '{base.display.color.coral.5}',
|
|
387
|
+
$type: 'color',
|
|
388
|
+
$extensions: {
|
|
389
|
+
'org.primer.figma': {
|
|
390
|
+
collection: 'mode',
|
|
391
|
+
mode: 'light',
|
|
392
|
+
group: 'component (internal)',
|
|
393
|
+
scopes: ['borderColor'],
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
},
|
|
333
399
|
yellow: {
|
|
334
400
|
bgColor: {
|
|
335
401
|
muted: {
|
|
@@ -5,7 +5,7 @@ import {isNumber} from '../filters'
|
|
|
5
5
|
* @param value
|
|
6
6
|
* @returns string
|
|
7
7
|
*/
|
|
8
|
-
export const convertFloatToPixel = (token: StyleDictionary.TransformedToken) => {
|
|
8
|
+
export const convertFloatToPixel = (token: StyleDictionary.TransformedToken, unitless = false) => {
|
|
9
9
|
// short circut if value is not a number
|
|
10
10
|
if (
|
|
11
11
|
typeof token.value !== 'number' ||
|
|
@@ -17,7 +17,7 @@ export const convertFloatToPixel = (token: StyleDictionary.TransformedToken) =>
|
|
|
17
17
|
// convert value
|
|
18
18
|
const convertedValue = token.$extensions?.['org.primer.data']?.fontSize * token.value
|
|
19
19
|
// return converted value
|
|
20
|
-
return convertedValue === 0 ? 0 : `${Math.round(convertedValue)}px`
|
|
20
|
+
return convertedValue === 0 ? 0 : unitless ? Math.round(convertedValue) : `${Math.round(convertedValue)}px`
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* @description converts a float value to a pixel value based on the provided fontSize on the tokersn extension
|
|
@@ -31,3 +31,10 @@ export const floatToPixel: StyleDictionary.Transform = {
|
|
|
31
31
|
matcher: isNumber,
|
|
32
32
|
transformer: (token: StyleDictionary.TransformedToken): string => convertFloatToPixel(token),
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
export const floatToPixelUnitless: StyleDictionary.Transform = {
|
|
36
|
+
type: `value`,
|
|
37
|
+
transitive: true,
|
|
38
|
+
matcher: isNumber,
|
|
39
|
+
transformer: (token: StyleDictionary.TransformedToken): string => convertFloatToPixel(token, true),
|
|
40
|
+
}
|
|
@@ -5,6 +5,7 @@ export {colorToHexMix} from './colorToHexMix'
|
|
|
5
5
|
export {colorToRgbAlpha} from './colorToRgbAlpha'
|
|
6
6
|
export {colorToRgbaFloat} from './colorToRgbaFloat'
|
|
7
7
|
export {floatToPixel} from './floatToPixel'
|
|
8
|
+
export {floatToPixelUnitless} from './floatToPixel'
|
|
8
9
|
export {dimensionToRem} from './dimensionToRem'
|
|
9
10
|
export {dimensionToRemPxArray} from './dimensionToRemPxArray'
|
|
10
11
|
export {dimensionToPixelUnitless} from './dimensionToPixelUnitless'
|
package/src/formats/cssThemed.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import StyleDictionary from 'style-dictionary'
|
|
2
|
-
import type {FormatterArguments} from 'style-dictionary/types/Format'
|
|
3
|
-
import {format} from 'prettier'
|
|
4
|
-
import type {LineFormatting} from 'style-dictionary/types/FormatHelpers'
|
|
5
|
-
const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @description Converts `StyleDictionary.dictionary.tokens` to css with prefers dark and light section
|
|
9
|
-
* @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts)
|
|
10
|
-
* @param arguments.options outputReferences `boolean`, selector `string`, selectorLight `string`, selectorDark `string`
|
|
11
|
-
* @returns formatted `string`
|
|
12
|
-
*/
|
|
13
|
-
export const cssThemed: StyleDictionary.Formatter = ({dictionary, options = {}, file}: FormatterArguments) => {
|
|
14
|
-
const {selector, selectorLight, selectorDark} = options
|
|
15
|
-
const {outputReferences, descriptions} = options
|
|
16
|
-
const formatting: LineFormatting = {
|
|
17
|
-
commentStyle: descriptions ? 'long' : 'none',
|
|
18
|
-
}
|
|
19
|
-
// add file header
|
|
20
|
-
const output = [fileHeader({file})]
|
|
21
|
-
// add single theme css
|
|
22
|
-
output.push(`${selector || ':root'}${selectorLight ? `, ${selectorLight}` : ''}{
|
|
23
|
-
${formattedVariables({format: 'css', dictionary, outputReferences, formatting})}
|
|
24
|
-
}`)
|
|
25
|
-
// add auto dark theme css
|
|
26
|
-
if (selectorDark) {
|
|
27
|
-
output.push(`@media (prefers-color-scheme: dark) {
|
|
28
|
-
${selectorDark} {
|
|
29
|
-
${formattedVariables({format: 'css', dictionary, outputReferences, formatting})}
|
|
30
|
-
}
|
|
31
|
-
}`)
|
|
32
|
-
}
|
|
33
|
-
// return prettified
|
|
34
|
-
return format(output.join('\n'), {parser: 'css', printWidth: 500})
|
|
35
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import StyleDictionary from 'style-dictionary'
|
|
2
|
-
import type {FormatterArguments} from 'style-dictionary/types/Format'
|
|
3
|
-
import type {LineFormatting} from 'style-dictionary/types/FormatHelpers'
|
|
4
|
-
const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @description Converts `StyleDictionary.dictionary.tokens` to csssection
|
|
8
|
-
* @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts)
|
|
9
|
-
* @param arguments.options outputReferences `boolean`, selector `string`
|
|
10
|
-
* @returns formatted `string`
|
|
11
|
-
*/
|
|
12
|
-
export const cssVariables: StyleDictionary.Formatter = ({dictionary, options = {}, file}: FormatterArguments) => {
|
|
13
|
-
const selector = options.selector ? options.selector : `:root`
|
|
14
|
-
const {outputReferences, descriptions} = options
|
|
15
|
-
const formatting: LineFormatting = {
|
|
16
|
-
commentStyle: descriptions ? 'long' : 'none',
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return `${fileHeader({file})}${selector} {\n${formattedVariables({
|
|
20
|
-
format: 'css',
|
|
21
|
-
dictionary,
|
|
22
|
-
outputReferences,
|
|
23
|
-
formatting,
|
|
24
|
-
})}\n}\n`
|
|
25
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import StyleDictionary from 'style-dictionary'
|
|
2
|
-
import type {FormatterArguments} from 'style-dictionary/types/Format'
|
|
3
|
-
import {format} from 'prettier'
|
|
4
|
-
import type {LineFormatting} from 'style-dictionary/types/FormatHelpers'
|
|
5
|
-
const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @description Converts `StyleDictionary.dictionary.tokens` to css with @custom-media
|
|
9
|
-
* @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts)
|
|
10
|
-
* @returns formatted `string`
|
|
11
|
-
*/
|
|
12
|
-
export const cssWrapMediaQuery: StyleDictionary.Formatter = ({dictionary, options, file}: FormatterArguments) => {
|
|
13
|
-
const {outputReferences, descriptions} = options
|
|
14
|
-
const formatting: LineFormatting = {
|
|
15
|
-
commentStyle: descriptions ? 'long' : 'none',
|
|
16
|
-
}
|
|
17
|
-
// get specific media query or use screen
|
|
18
|
-
const mediaQuery = options.mediaQuery?.[file.destination] || 'screen'
|
|
19
|
-
// add file header
|
|
20
|
-
const output = [fileHeader({file})]
|
|
21
|
-
// add meadia query
|
|
22
|
-
output.push(`@media ${mediaQuery} {\n:root {`)
|
|
23
|
-
// add tokens
|
|
24
|
-
output.push(formattedVariables({format: 'css', dictionary, outputReferences, formatting}))
|
|
25
|
-
// close media query
|
|
26
|
-
output.push(`}\n}`)
|
|
27
|
-
// return prettified
|
|
28
|
-
return format(output.join('\n'), {parser: 'css', printWidth: 500})
|
|
29
|
-
}
|