@sanity/ui 2.0.0-beta.1 → 2.0.0-beta.10
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/LICENSE +1 -1
- package/README.md +6 -3
- package/dist/index.cjs.mjs +11 -36
- package/dist/index.d.ts +248 -268
- package/dist/index.esm.js +494 -354
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +503 -567
- package/dist/index.js.map +1 -1
- package/dist/theme.cjs.mjs +1 -1
- package/dist/theme.d.ts +81 -114
- package/dist/theme.esm.js +299 -252
- package/dist/theme.esm.js.map +1 -1
- package/dist/theme.js +299 -252
- package/dist/theme.js.map +1 -1
- package/package.json +6 -3
- package/src/core/__workshop__/constants.ts +3 -2
- package/src/core/_compat.ts +236 -87
- package/src/core/components/menu/__workshop__/selectedItem.tsx +7 -2
- package/src/core/components/menu/menuButton.tsx +12 -1
- package/src/core/constants.ts +18 -0
- package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +6 -3
- package/src/core/middleware/origin.ts +47 -0
- package/src/core/primitives/avatar/__workshop__/asButton.tsx +1 -1
- package/src/core/primitives/avatar/__workshop__/stack.tsx +1 -1
- package/src/core/primitives/avatar/avatar.tsx +14 -4
- package/src/core/primitives/avatar/avatarCounter.tsx +16 -5
- package/src/core/primitives/avatar/avatarStack.tsx +2 -2
- package/src/core/primitives/badge/badge.tsx +1 -3
- package/src/core/primitives/kbd/kbd.tsx +2 -0
- package/src/core/primitives/popover/popover.tsx +67 -13
- package/src/core/primitives/popover/popoverCard.tsx +26 -15
- package/src/core/primitives/select/select.tsx +1 -1
- package/src/core/primitives/switch/styles.ts +6 -1
- package/src/core/primitives/tooltip/tooltip.tsx +47 -57
- package/src/core/primitives/tooltip/tooltipCard.tsx +104 -0
- package/src/core/styles/card/_cardColorStyle.ts +2 -0
- package/src/core/styles/margin/marginsStyle.test.ts +2 -2
- package/src/core/styles/padding/paddingStyle.test.ts +2 -2
- package/src/core/theme/__workshop__/build/Root.tsx +20 -3
- package/src/core/theme/__workshop__/build/story.tsx +16 -10
- package/src/core/theme/__workshop__/canvas.tsx +7 -7
- package/src/core/theme/__workshop__/debug/story.tsx +159 -0
- package/src/core/theme/__workshop__/index.ts +5 -0
- package/src/core/theme/theme.test.tsx +2 -2
- package/src/core/types/avatar.ts +1 -1
- package/src/core/types/button.ts +1 -2
- package/src/core/{primitives/tooltip → utils/conditionalWrapper}/conditionalWrapper.tsx +3 -0
- package/src/core/utils/conditionalWrapper/index.ts +1 -0
- package/src/core/utils/index.ts +1 -0
- package/src/theme/build/_deprecated/color/factory.ts +3 -3
- package/src/theme/build/buildColorTheme.ts +16 -16
- package/src/theme/build/colorToken/colorToken.ts +19 -0
- package/src/theme/build/colorToken/compileColorToken.ts +21 -0
- package/src/theme/build/colorToken/index.ts +2 -0
- package/src/theme/build/colorToken/types.ts +6 -0
- package/src/theme/build/renderColorTheme.ts +14 -15
- package/src/theme/build/renderColorValue.ts +9 -2
- package/src/theme/config/system.ts +12 -10
- package/src/theme/config/tokens/color/types.ts +12 -1
- package/src/theme/config/tokens/parseTokenKey.ts +1 -0
- package/src/theme/config/tokens/parseTokenValue.test.ts +13 -16
- package/src/theme/config/tokens/parseTokenValue.ts +45 -14
- package/src/theme/config/tokens/types.ts +3 -2
- package/src/theme/defaults/colorTokens.ts +219 -211
- package/src/theme/defaults/config.ts +2 -1
- package/src/theme/defaults/fonts.ts +13 -5
- package/src/theme/index.ts +0 -7
- package/src/theme/system/color/_constants.ts +5 -2
- package/src/theme/system/color/_system.ts +2 -1
- package/src/theme/system/color/avatar.ts +2 -12
- package/src/theme/system/color/button.ts +4 -20
- package/src/theme/system/color/input.ts +3 -11
- package/src/theme/system/color/selectable.ts +3 -14
- package/src/theme/system/shadow.ts +0 -6
- package/src/theme/system/styles.ts +0 -6
- package/src/theme/system/theme.ts +2 -0
- package/src/theme/system/v0/avatar.ts +1 -1
- package/src/theme/system/v0/color/button.ts +4 -4
- package/src/theme/system/v0/color/card.ts +2 -2
- package/src/theme/system/v0/color/input.ts +3 -3
- package/src/theme/system/v0/color/muted.ts +2 -2
- package/src/theme/system/v0/color/solid.ts +2 -2
- package/src/theme/versioning/themeColor_v0_v2.ts +2 -2
- package/src/theme/versioning/v2_v0.ts +2 -2
- package/src/theme/build/colorToken.ts +0 -39
|
@@ -5,18 +5,18 @@ import {
|
|
|
5
5
|
ThemeColorBadgeTone_v2,
|
|
6
6
|
ThemeColorBadge_v2,
|
|
7
7
|
ThemeColorBlendModeKey,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
ThemeColorButtonMode_v2,
|
|
9
|
+
ThemeColorButtonTone_v2,
|
|
10
10
|
ThemeColorButton_v2,
|
|
11
11
|
ThemeColorCardToneKey,
|
|
12
12
|
ThemeColorCard_v2,
|
|
13
|
+
ThemeColorInputMode_v2,
|
|
13
14
|
ThemeColorInputState_v2,
|
|
14
|
-
ThemeColorInputStates_v2,
|
|
15
15
|
ThemeColorInput_v2,
|
|
16
16
|
ThemeColorKBD,
|
|
17
17
|
ThemeColorScheme_v2,
|
|
18
18
|
ThemeColorSchemes_v2,
|
|
19
|
-
|
|
19
|
+
ThemeColorSelectableTone_v2,
|
|
20
20
|
ThemeColorSelectable_v2,
|
|
21
21
|
ThemeColorShadow,
|
|
22
22
|
ThemeColorState_v2,
|
|
@@ -278,10 +278,9 @@ function renderThemeColorBadgeColor(
|
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
return {
|
|
281
|
-
// _blend: blendMode,
|
|
282
281
|
bg,
|
|
283
|
-
fg: renderColorValue(value.fg, colorOptions),
|
|
284
282
|
dot: renderColorValue(value.dot, colorOptions),
|
|
283
|
+
fg: renderColorValue(value.fg, colorOptions),
|
|
285
284
|
icon: renderColorValue(value.icon, colorOptions),
|
|
286
285
|
}
|
|
287
286
|
}
|
|
@@ -302,13 +301,13 @@ function renderThemeColorButton(
|
|
|
302
301
|
}
|
|
303
302
|
|
|
304
303
|
function renderThemeColorButtonTones(
|
|
305
|
-
value:
|
|
304
|
+
value: ThemeColorButtonMode_v2,
|
|
306
305
|
options: {
|
|
307
306
|
baseBg: string
|
|
308
307
|
blendMode: ThemeColorBlendModeKey
|
|
309
308
|
colorPalette: ThemeColorPalette
|
|
310
309
|
},
|
|
311
|
-
):
|
|
310
|
+
): ThemeColorButtonMode_v2 {
|
|
312
311
|
return {
|
|
313
312
|
default: renderThemeColorButtonStates(value.default, options),
|
|
314
313
|
primary: renderThemeColorButtonStates(value.primary, options),
|
|
@@ -319,13 +318,13 @@ function renderThemeColorButtonTones(
|
|
|
319
318
|
}
|
|
320
319
|
|
|
321
320
|
function renderThemeColorButtonStates(
|
|
322
|
-
value:
|
|
321
|
+
value: ThemeColorButtonTone_v2,
|
|
323
322
|
options: {
|
|
324
323
|
baseBg: string
|
|
325
324
|
blendMode: ThemeColorBlendModeKey
|
|
326
325
|
colorPalette: ThemeColorPalette
|
|
327
326
|
},
|
|
328
|
-
):
|
|
327
|
+
): ThemeColorButtonTone_v2 {
|
|
329
328
|
return {
|
|
330
329
|
enabled: renderThemeColorState(value.enabled, options),
|
|
331
330
|
hovered: renderThemeColorState(value.hovered, options),
|
|
@@ -366,7 +365,7 @@ function renderThemeColorState(
|
|
|
366
365
|
fg: renderColorValue(value.accent.fg, colorOptions),
|
|
367
366
|
},
|
|
368
367
|
avatar: renderThemeColorAvatar(value.avatar, {baseBg, colorPalette, blendMode}),
|
|
369
|
-
badge: renderThemeColorBadge(value.badge, {baseBg, colorPalette, blendMode}),
|
|
368
|
+
badge: renderThemeColorBadge(value.badge, {baseBg: bg, colorPalette, blendMode}),
|
|
370
369
|
bg,
|
|
371
370
|
border: renderColorValue(value.border, colorOptions),
|
|
372
371
|
code: {
|
|
@@ -409,13 +408,13 @@ function renderThemeColorInput(
|
|
|
409
408
|
}
|
|
410
409
|
|
|
411
410
|
function renderInputStatesColorTheme(
|
|
412
|
-
value:
|
|
411
|
+
value: ThemeColorInputMode_v2,
|
|
413
412
|
options: {
|
|
414
413
|
baseBg: string
|
|
415
414
|
blendMode: ThemeColorBlendModeKey
|
|
416
415
|
colorPalette: ThemeColorPalette
|
|
417
416
|
},
|
|
418
|
-
):
|
|
417
|
+
): ThemeColorInputMode_v2 {
|
|
419
418
|
return {
|
|
420
419
|
enabled: renderInputStateColorTheme(value.enabled, options),
|
|
421
420
|
hovered: renderInputStateColorTheme(value.hovered, options),
|
|
@@ -468,13 +467,13 @@ function renderThemeColorSelectable(
|
|
|
468
467
|
}
|
|
469
468
|
|
|
470
469
|
function renderThemeColorSelectableStates(
|
|
471
|
-
value:
|
|
470
|
+
value: ThemeColorSelectableTone_v2,
|
|
472
471
|
options: {
|
|
473
472
|
baseBg: string
|
|
474
473
|
blendMode: ThemeColorBlendModeKey
|
|
475
474
|
colorPalette: ThemeColorPalette
|
|
476
475
|
},
|
|
477
|
-
):
|
|
476
|
+
): ThemeColorSelectableTone_v2 {
|
|
478
477
|
return {
|
|
479
478
|
enabled: renderThemeColorState(value.enabled, options),
|
|
480
479
|
hovered: renderThemeColorState(value.hovered, options),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ColorTint as ColorPaletteValue} from '@sanity/color'
|
|
2
2
|
import {ThemeColorPalette, parseTokenValue} from '../config'
|
|
3
3
|
import {ThemeColorBlendModeKey} from '../system'
|
|
4
|
-
import {rgba} from './lib/color-fns'
|
|
4
|
+
import {hexToRgb, mix, rgbToHex, rgba} from './lib/color-fns'
|
|
5
5
|
import {mixThemeColor} from './mixThemeColor'
|
|
6
6
|
|
|
7
7
|
export interface RenderColorValueOptions {
|
|
@@ -53,9 +53,16 @@ export function renderColorValue(str: string, options: RenderColorValueOptions):
|
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
55
|
hex = mixThemeColor(hex, mixOptions)
|
|
56
|
+
|
|
57
|
+
if (bg && node.mix !== undefined) {
|
|
58
|
+
const from = hexToRgb(bg)
|
|
59
|
+
const to = hexToRgb(hex)
|
|
60
|
+
|
|
61
|
+
hex = rgbToHex(mix(from, to, node.mix))
|
|
62
|
+
}
|
|
56
63
|
} catch (err) {
|
|
57
64
|
// eslint-disable-next-line no-console
|
|
58
|
-
console.
|
|
65
|
+
console.warn('could not blend', hex, mixOptions)
|
|
59
66
|
throw err
|
|
60
67
|
}
|
|
61
68
|
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ThemeColorBlendModeKey,
|
|
10
10
|
} from '../system'
|
|
11
11
|
|
|
12
|
-
/** @
|
|
12
|
+
/** @public */
|
|
13
13
|
export const COLOR_CONFIG_STATE_KEYS = [
|
|
14
14
|
'_hue',
|
|
15
15
|
'bg',
|
|
@@ -30,7 +30,7 @@ export const COLOR_CONFIG_STATE_KEYS = [
|
|
|
30
30
|
/** @public */
|
|
31
31
|
export type ColorConfigStateKey = (typeof COLOR_CONFIG_STATE_KEYS)[number]
|
|
32
32
|
|
|
33
|
-
/** @
|
|
33
|
+
/** @public */
|
|
34
34
|
export const COLOR_CONFIG_CARD_KEYS = [
|
|
35
35
|
...COLOR_CONFIG_STATE_KEYS,
|
|
36
36
|
'_hue',
|
|
@@ -47,7 +47,7 @@ export const COLOR_CONFIG_CARD_KEYS = [
|
|
|
47
47
|
/** @public */
|
|
48
48
|
export type ColorConfigCardKey = (typeof COLOR_CONFIG_CARD_KEYS)[number]
|
|
49
49
|
|
|
50
|
-
/** @
|
|
50
|
+
/** @public */
|
|
51
51
|
export const COLOR_CONFIG_BLEND_KEYS = ['_blend'] as const
|
|
52
52
|
|
|
53
53
|
/** @public */
|
|
@@ -63,11 +63,13 @@ export type ColorConfigValue =
|
|
|
63
63
|
| `black/${ColorConfigOpacityValue}`
|
|
64
64
|
| `white/${ColorConfigOpacityValue}`
|
|
65
65
|
| `${ColorHueKey}`
|
|
66
|
+
| `${ColorHueKey} ${number}%`
|
|
66
67
|
| `${ColorHueKey}/${ColorTintKey}`
|
|
68
|
+
| `${ColorHueKey}/${ColorTintKey} ${number}%`
|
|
67
69
|
| `${ColorHueKey}/${ColorTintKey}/${ColorConfigOpacityValue}`
|
|
68
70
|
| `${ColorTintKey}`
|
|
71
|
+
| `${ColorTintKey} ${number}%`
|
|
69
72
|
| `${ColorTintKey}/${ColorConfigOpacityValue}`
|
|
70
|
-
| ThemeColorBlendModeKey
|
|
71
73
|
|
|
72
74
|
/** @public */
|
|
73
75
|
export type ThemeColorTokenValue = [ColorConfigValue, ColorConfigValue]
|
|
@@ -75,37 +77,37 @@ export type ThemeColorTokenValue = [ColorConfigValue, ColorConfigValue]
|
|
|
75
77
|
/** @public */
|
|
76
78
|
export type ColorBlendModeTokenValue = [ThemeColorBlendModeKey, ThemeColorBlendModeKey]
|
|
77
79
|
|
|
78
|
-
/** @
|
|
80
|
+
/** @public */
|
|
79
81
|
export const COLOR_CONFIG_AVATAR_COLORS = ['*', ...THEME_COLOR_AVATAR_COLORS] as const
|
|
80
82
|
|
|
81
83
|
/** @public */
|
|
82
84
|
export type ColorConfigAvatarColor = (typeof COLOR_CONFIG_AVATAR_COLORS)[number]
|
|
83
85
|
|
|
84
|
-
/** @
|
|
86
|
+
/** @public */
|
|
85
87
|
export const COLOR_CONFIG_CARD_TONES = ['*', ...THEME_COLOR_CARD_TONES] as const
|
|
86
88
|
|
|
87
89
|
/** @public */
|
|
88
90
|
export type ColorConfigCardTone = (typeof COLOR_CONFIG_CARD_TONES)[number]
|
|
89
91
|
|
|
90
|
-
/** @
|
|
92
|
+
/** @public */
|
|
91
93
|
export const COLOR_CONFIG_STATE_TONES = ['*', ...THEME_COLOR_STATE_TONES] as const
|
|
92
94
|
|
|
93
95
|
/** @public */
|
|
94
96
|
export type ColorConfigStateTone = (typeof COLOR_CONFIG_STATE_TONES)[number]
|
|
95
97
|
|
|
96
|
-
/** @
|
|
98
|
+
/** @public */
|
|
97
99
|
export const COLOR_CONFIG_STATES = ['*', ...THEME_COLOR_STATES] as const
|
|
98
100
|
|
|
99
101
|
/** @public */
|
|
100
102
|
export type ColorConfigState = (typeof COLOR_CONFIG_STATES)[number]
|
|
101
103
|
|
|
102
|
-
/** @
|
|
104
|
+
/** @public */
|
|
103
105
|
export const COLOR_CONFIG_INPUT_MODES = ['*', ...THEME_COLOR_INPUT_MODES] as const
|
|
104
106
|
|
|
105
107
|
/** @public */
|
|
106
108
|
export type ColorConfigInputMode = (typeof COLOR_CONFIG_INPUT_MODES)[number]
|
|
107
109
|
|
|
108
|
-
/** @
|
|
110
|
+
/** @public */
|
|
109
111
|
export const COLOR_CONFIG_INPUT_STATES = ['*', ...THEME_COLOR_INPUT_STATES] as const
|
|
110
112
|
|
|
111
113
|
/** @public */
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
ThemeColorTokenValue,
|
|
11
11
|
} from '../../system'
|
|
12
12
|
|
|
13
|
+
/** @public */
|
|
13
14
|
export interface ThemeColorAvatarHueTokens {
|
|
14
15
|
_blend?: ColorBlendModeTokenValue
|
|
15
16
|
_hue?: ColorHueKey
|
|
@@ -17,6 +18,7 @@ export interface ThemeColorAvatarHueTokens {
|
|
|
17
18
|
fg?: ThemeColorTokenValue
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
/** @public */
|
|
20
22
|
export interface ThemeColorAvatarTokens {
|
|
21
23
|
'*'?: ThemeColorAvatarHueTokens
|
|
22
24
|
gray?: ThemeColorAvatarHueTokens
|
|
@@ -30,8 +32,8 @@ export interface ThemeColorAvatarTokens {
|
|
|
30
32
|
cyan?: ThemeColorAvatarHueTokens
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
/** @public */
|
|
33
36
|
export interface ThemeColorBadgeTokens {
|
|
34
|
-
// _blend?: ColorBlendModeTokenValue
|
|
35
37
|
_hue?: ColorHueKey
|
|
36
38
|
bg?: ThemeColorTokenValue
|
|
37
39
|
fg?: ThemeColorTokenValue
|
|
@@ -39,6 +41,7 @@ export interface ThemeColorBadgeTokens {
|
|
|
39
41
|
icon?: ThemeColorTokenValue
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
/** @public */
|
|
42
45
|
export interface ThemeColorBaseTokens extends ThemeColorStateTokens {
|
|
43
46
|
focusRing?: ThemeColorTokenValue
|
|
44
47
|
backdrop?: ThemeColorTokenValue
|
|
@@ -50,6 +53,7 @@ export interface ThemeColorBaseTokens extends ThemeColorStateTokens {
|
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
|
|
56
|
+
/** @public */
|
|
53
57
|
export interface ThemeColorBadgeToneTokens {
|
|
54
58
|
_blend?: ColorBlendModeTokenValue
|
|
55
59
|
_hue?: ColorHueKey
|
|
@@ -59,6 +63,7 @@ export interface ThemeColorBadgeToneTokens {
|
|
|
59
63
|
icon?: ThemeColorTokenValue
|
|
60
64
|
}
|
|
61
65
|
|
|
66
|
+
/** @public */
|
|
62
67
|
export interface ThemeColorBadgeTokens {
|
|
63
68
|
'*'?: ThemeColorBadgeToneTokens
|
|
64
69
|
default?: ThemeColorBadgeToneTokens
|
|
@@ -68,6 +73,7 @@ export interface ThemeColorBadgeTokens {
|
|
|
68
73
|
critical?: ThemeColorBadgeToneTokens
|
|
69
74
|
}
|
|
70
75
|
|
|
76
|
+
/** @public */
|
|
71
77
|
export interface ThemeColorStateTokens {
|
|
72
78
|
_blend?: ColorBlendModeTokenValue
|
|
73
79
|
_hue?: ColorHueKey
|
|
@@ -102,13 +108,16 @@ export interface ThemeColorStateTokens {
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
|
|
111
|
+
/** @public */
|
|
105
112
|
export type ThemeColorStatesTokens = Partial<Record<ColorConfigState, ThemeColorStateTokens>>
|
|
106
113
|
|
|
114
|
+
/** @public */
|
|
107
115
|
export interface ThemeColorButtonTokens
|
|
108
116
|
extends Partial<Record<ColorConfigStateTone, ThemeColorStatesTokens>> {
|
|
109
117
|
_hue?: ColorHueKey
|
|
110
118
|
}
|
|
111
119
|
|
|
120
|
+
/** @public */
|
|
112
121
|
export interface ThemeColorInputStateTokens {
|
|
113
122
|
_blend?: ColorBlendModeTokenValue
|
|
114
123
|
_hue?: ColorHueKey
|
|
@@ -121,11 +130,13 @@ export interface ThemeColorInputStateTokens {
|
|
|
121
130
|
placeholder?: ThemeColorTokenValue
|
|
122
131
|
}
|
|
123
132
|
|
|
133
|
+
/** @public */
|
|
124
134
|
export interface ThemeColorInputTokens
|
|
125
135
|
extends Partial<Record<ColorConfigInputState, ThemeColorInputStateTokens>> {
|
|
126
136
|
_hue?: ColorHueKey
|
|
127
137
|
}
|
|
128
138
|
|
|
139
|
+
/** @public */
|
|
129
140
|
export interface ThemeColorTokens {
|
|
130
141
|
base?: Partial<Record<ColorConfigCardTone, ThemeColorBaseTokens>>
|
|
131
142
|
button?: Partial<Record<ThemeColorButtonModeKey, ThemeColorButtonTokens>>
|
|
@@ -11,13 +11,25 @@ test('parse color value', () => {
|
|
|
11
11
|
tint: '50',
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
+
expect(parseTokenValue('50 50%')).toEqual({
|
|
15
|
+
type: 'color',
|
|
16
|
+
tint: '50',
|
|
17
|
+
mix: 0.5,
|
|
18
|
+
})
|
|
19
|
+
|
|
14
20
|
expect(parseTokenValue('cyan/500')).toEqual({
|
|
15
21
|
type: 'color',
|
|
16
|
-
key: 'cyan/500',
|
|
17
22
|
hue: 'cyan',
|
|
18
23
|
tint: '500',
|
|
19
24
|
})
|
|
20
25
|
|
|
26
|
+
expect(parseTokenValue('cyan/500 50%')).toEqual({
|
|
27
|
+
type: 'color',
|
|
28
|
+
hue: 'cyan',
|
|
29
|
+
mix: 0.5,
|
|
30
|
+
tint: '500',
|
|
31
|
+
})
|
|
32
|
+
|
|
21
33
|
expect(parseTokenValue('screen')).toEqual({
|
|
22
34
|
type: 'blendMode',
|
|
23
35
|
value: 'screen',
|
|
@@ -27,19 +39,4 @@ test('parse color value', () => {
|
|
|
27
39
|
type: 'blendMode',
|
|
28
40
|
value: 'multiply',
|
|
29
41
|
})
|
|
30
|
-
|
|
31
|
-
expect(parseTokenValue('0')).toEqual({
|
|
32
|
-
type: 'color',
|
|
33
|
-
opacity: 0,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
expect(parseTokenValue('0.1')).toEqual({
|
|
37
|
-
type: 'color',
|
|
38
|
-
opacity: 0.1,
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
expect(parseTokenValue('1')).toEqual({
|
|
42
|
-
type: 'color',
|
|
43
|
-
opacity: 1,
|
|
44
|
-
})
|
|
45
42
|
})
|
|
@@ -2,14 +2,32 @@ import {isColorBlendModeValue, isColorHueKey, isColorTintKey} from '../../system
|
|
|
2
2
|
import {isColorOpacityValue, isColorValue} from '../helpers'
|
|
3
3
|
import {TokenValueNode} from './types'
|
|
4
4
|
|
|
5
|
+
function isColorMixPercentValue(str: string): str is `${number}%` {
|
|
6
|
+
return /^\d+%$/.test(str)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** @internal */
|
|
5
10
|
export function parseTokenValue(str: string): TokenValueNode | undefined {
|
|
6
11
|
const segments = str.split('/')
|
|
7
|
-
|
|
12
|
+
|
|
13
|
+
let nextSegment = segments.shift() || ''
|
|
14
|
+
|
|
15
|
+
const [segment0, segment0mix] = nextSegment.split(' ')
|
|
8
16
|
|
|
9
17
|
if (isColorTintKey(segment0)) {
|
|
10
18
|
const tint = segment0
|
|
11
19
|
const segment1 = segments.shift() || ''
|
|
12
20
|
|
|
21
|
+
if (isColorMixPercentValue(segment0mix)) {
|
|
22
|
+
const mix = Number(segment0mix.slice(0, -1)) / 100
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
type: 'color',
|
|
26
|
+
tint,
|
|
27
|
+
mix,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
13
31
|
if (isColorOpacityValue(segment1)) {
|
|
14
32
|
const opacity = Number(segment1)
|
|
15
33
|
|
|
@@ -30,6 +48,16 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
|
|
|
30
48
|
const key = segment0 as 'black' | 'white'
|
|
31
49
|
const segment1 = segments.shift() || ''
|
|
32
50
|
|
|
51
|
+
if (isColorMixPercentValue(segment0mix)) {
|
|
52
|
+
const mix = Number(segment0mix.slice(0, -1)) / 100
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
type: 'color',
|
|
56
|
+
key,
|
|
57
|
+
mix,
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
33
61
|
if (isColorOpacityValue(segment1)) {
|
|
34
62
|
const opacity = Number(segment1)
|
|
35
63
|
|
|
@@ -48,18 +76,31 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
|
|
|
48
76
|
|
|
49
77
|
if (isColorHueKey(segment0)) {
|
|
50
78
|
const hue = segment0
|
|
51
|
-
|
|
79
|
+
|
|
80
|
+
nextSegment = segments.shift() || ''
|
|
81
|
+
|
|
82
|
+
const [segment1, segment1mix] = nextSegment.split(' ')
|
|
52
83
|
|
|
53
84
|
if (isColorTintKey(segment1)) {
|
|
54
85
|
const tint = segment1
|
|
55
86
|
const segment2 = segments.shift() || ''
|
|
56
87
|
|
|
88
|
+
if (isColorMixPercentValue(segment1mix)) {
|
|
89
|
+
const mix = Number(segment1mix.slice(0, -1)) / 100
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
type: 'color',
|
|
93
|
+
hue,
|
|
94
|
+
tint,
|
|
95
|
+
mix,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
57
99
|
if (isColorOpacityValue(segment2)) {
|
|
58
100
|
const opacity = Number(segment2)
|
|
59
101
|
|
|
60
102
|
return {
|
|
61
103
|
type: 'color',
|
|
62
|
-
key: `${hue}/${tint}`,
|
|
63
104
|
hue,
|
|
64
105
|
tint,
|
|
65
106
|
opacity,
|
|
@@ -68,7 +109,6 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
|
|
|
68
109
|
|
|
69
110
|
return {
|
|
70
111
|
type: 'color',
|
|
71
|
-
key: `${hue}/${tint}`,
|
|
72
112
|
hue,
|
|
73
113
|
tint,
|
|
74
114
|
}
|
|
@@ -76,16 +116,7 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
|
|
|
76
116
|
|
|
77
117
|
return {
|
|
78
118
|
type: 'hue',
|
|
79
|
-
value:
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (isColorOpacityValue(segment0)) {
|
|
84
|
-
const opacity = Number(segment0)
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
type: 'color',
|
|
88
|
-
opacity,
|
|
119
|
+
value: hue,
|
|
89
120
|
}
|
|
90
121
|
}
|
|
91
122
|
|
|
@@ -29,10 +29,11 @@ export type TokenKeyNode = TokenBaseKeyNode | TokenButtonKeyNode
|
|
|
29
29
|
/** @internal */
|
|
30
30
|
export interface TokenColorValueNode {
|
|
31
31
|
type: 'color'
|
|
32
|
-
key?: 'black' | 'white'
|
|
32
|
+
key?: 'black' | 'white'
|
|
33
33
|
hue?: ColorHueKey
|
|
34
|
-
|
|
34
|
+
mix?: number
|
|
35
35
|
opacity?: number
|
|
36
|
+
tint?: ColorTintKey
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/** @internal */
|