@sanity/ui 2.0.0-beta.1 → 2.0.0-beta.11

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 (89) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +6 -3
  3. package/dist/index.cjs.mjs +11 -36
  4. package/dist/index.d.ts +248 -268
  5. package/dist/index.esm.js +502 -356
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.js +511 -569
  8. package/dist/index.js.map +1 -1
  9. package/dist/theme.cjs.mjs +1 -1
  10. package/dist/theme.d.ts +81 -114
  11. package/dist/theme.esm.js +355 -290
  12. package/dist/theme.esm.js.map +1 -1
  13. package/dist/theme.js +355 -290
  14. package/dist/theme.js.map +1 -1
  15. package/package.json +6 -3
  16. package/src/core/__workshop__/constants.ts +3 -2
  17. package/src/core/_compat.ts +236 -87
  18. package/src/core/components/menu/__workshop__/selectedItem.tsx +7 -2
  19. package/src/core/components/menu/menuButton.tsx +12 -1
  20. package/src/core/constants.ts +18 -0
  21. package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +6 -3
  22. package/src/core/middleware/origin.ts +47 -0
  23. package/src/core/primitives/avatar/__workshop__/asButton.tsx +1 -1
  24. package/src/core/primitives/avatar/__workshop__/stack.tsx +1 -1
  25. package/src/core/primitives/avatar/avatar.tsx +14 -4
  26. package/src/core/primitives/avatar/avatarCounter.tsx +16 -5
  27. package/src/core/primitives/avatar/avatarStack.tsx +2 -2
  28. package/src/core/primitives/badge/badge.tsx +1 -3
  29. package/src/core/primitives/kbd/kbd.tsx +2 -0
  30. package/src/core/primitives/popover/popover.tsx +67 -13
  31. package/src/core/primitives/popover/popoverCard.tsx +26 -15
  32. package/src/core/primitives/select/select.tsx +1 -1
  33. package/src/core/primitives/switch/styles.ts +6 -1
  34. package/src/core/primitives/textInput/__workshop__/plain.tsx +1 -1
  35. package/src/core/primitives/textInput/__workshop__/states.tsx +10 -2
  36. package/src/core/primitives/tooltip/tooltip.tsx +47 -57
  37. package/src/core/primitives/tooltip/tooltipCard.tsx +104 -0
  38. package/src/core/styles/card/_cardColorStyle.ts +2 -0
  39. package/src/core/styles/input/textInputStyle.ts +33 -2
  40. package/src/core/styles/margin/marginsStyle.test.ts +2 -2
  41. package/src/core/styles/padding/paddingStyle.test.ts +2 -2
  42. package/src/core/theme/__workshop__/build/Root.tsx +20 -3
  43. package/src/core/theme/__workshop__/build/story.tsx +16 -10
  44. package/src/core/theme/__workshop__/canvas.tsx +7 -7
  45. package/src/core/theme/__workshop__/debug/story.tsx +196 -0
  46. package/src/core/theme/__workshop__/index.ts +5 -0
  47. package/src/core/theme/theme.test.tsx +2 -2
  48. package/src/core/types/avatar.ts +1 -1
  49. package/src/core/types/button.ts +1 -2
  50. package/src/core/{primitives/tooltip → utils/conditionalWrapper}/conditionalWrapper.tsx +3 -0
  51. package/src/core/utils/conditionalWrapper/index.ts +1 -0
  52. package/src/core/utils/index.ts +1 -0
  53. package/src/theme/build/_deprecated/color/factory.ts +3 -3
  54. package/src/theme/build/buildColorTheme.test.ts +2 -2
  55. package/src/theme/build/buildColorTheme.ts +16 -16
  56. package/src/theme/build/colorToken/colorToken.ts +19 -0
  57. package/src/theme/build/colorToken/compileColorToken.ts +21 -0
  58. package/src/theme/build/colorToken/index.ts +2 -0
  59. package/src/theme/build/colorToken/types.ts +6 -0
  60. package/src/theme/build/renderColorTheme.ts +14 -15
  61. package/src/theme/build/renderColorValue.ts +9 -2
  62. package/src/theme/config/system.ts +12 -10
  63. package/src/theme/config/tokens/color/types.ts +12 -1
  64. package/src/theme/config/tokens/parseTokenKey.ts +1 -0
  65. package/src/theme/config/tokens/parseTokenValue.test.ts +13 -16
  66. package/src/theme/config/tokens/parseTokenValue.ts +45 -14
  67. package/src/theme/config/tokens/types.ts +3 -2
  68. package/src/theme/defaults/colorTokens.ts +278 -252
  69. package/src/theme/defaults/config.ts +2 -1
  70. package/src/theme/defaults/fonts.ts +13 -5
  71. package/src/theme/index.ts +0 -7
  72. package/src/theme/system/color/_constants.ts +5 -2
  73. package/src/theme/system/color/_system.ts +2 -1
  74. package/src/theme/system/color/avatar.ts +2 -12
  75. package/src/theme/system/color/button.ts +4 -20
  76. package/src/theme/system/color/input.ts +3 -11
  77. package/src/theme/system/color/selectable.ts +3 -14
  78. package/src/theme/system/shadow.ts +0 -6
  79. package/src/theme/system/styles.ts +0 -6
  80. package/src/theme/system/theme.ts +2 -0
  81. package/src/theme/system/v0/avatar.ts +1 -1
  82. package/src/theme/system/v0/color/button.ts +4 -4
  83. package/src/theme/system/v0/color/card.ts +2 -2
  84. package/src/theme/system/v0/color/input.ts +3 -3
  85. package/src/theme/system/v0/color/muted.ts +2 -2
  86. package/src/theme/system/v0/color/solid.ts +2 -2
  87. package/src/theme/versioning/themeColor_v0_v2.ts +2 -2
  88. package/src/theme/versioning/v2_v0.ts +2 -2
  89. package/src/theme/build/colorToken.ts +0 -39
@@ -18,11 +18,11 @@ import {
18
18
  ThemeColorShadow,
19
19
  ThemeColorState_v2,
20
20
  ThemeColorButton_v2,
21
- ThemeColorButtonTones_v2,
22
- ThemeColorButtonStates_v2,
21
+ ThemeColorButtonMode_v2,
22
+ ThemeColorButtonTone_v2,
23
23
  ThemeColorAvatarHue_v2,
24
24
  ThemeColorInput_v2,
25
- ThemeColorInputStates_v2,
25
+ ThemeColorInputMode_v2,
26
26
  ThemeColorInputState_v2,
27
27
  } from '../system'
28
28
  import {ColorTokenContext, resolveColorTokenValue as _color} from './colorToken'
@@ -215,16 +215,16 @@ function buildButtonTonesColorTheme(
215
215
  mode: ThemeColorButtonModeKey
216
216
  },
217
217
  config?: ThemeConfig,
218
- ): ThemeColorButtonTones_v2 {
218
+ ): ThemeColorButtonMode_v2 {
219
219
  const {mode, scheme} = options
220
220
 
221
- const tones: Partial<ThemeColorButtonTones_v2> = {}
221
+ const tones: Partial<ThemeColorButtonMode_v2> = {}
222
222
 
223
223
  for (const tone of THEME_COLOR_STATE_TONES) {
224
224
  tones[tone] = buildButtonStatesColorTheme({mode, scheme, tone}, config)
225
225
  }
226
226
 
227
- return tones as ThemeColorButtonTones_v2
227
+ return tones as ThemeColorButtonMode_v2
228
228
  }
229
229
 
230
230
  function buildButtonStatesColorTheme(
@@ -234,16 +234,16 @@ function buildButtonStatesColorTheme(
234
234
  tone: ThemeColorStateToneKey
235
235
  },
236
236
  config?: ThemeConfig,
237
- ): ThemeColorButtonStates_v2 {
237
+ ): ThemeColorButtonTone_v2 {
238
238
  const {mode, scheme, tone} = options
239
239
 
240
- const states: Partial<ThemeColorButtonStates_v2> = {}
240
+ const states: Partial<ThemeColorButtonTone_v2> = {}
241
241
 
242
242
  for (const state of THEME_COLOR_STATES) {
243
243
  states[state] = buildButtonStateColorTheme({mode, tone, scheme, state}, config)
244
244
  }
245
245
 
246
- return states as ThemeColorButtonStates_v2
246
+ return states as ThemeColorButtonTone_v2
247
247
  }
248
248
 
249
249
  function buildButtonStateColorTheme(
@@ -314,7 +314,7 @@ function buildInputStatesColorTheme(
314
314
  tone: ThemeColorCardToneKey
315
315
  },
316
316
  config?: ThemeConfig,
317
- ): ThemeColorInputStates_v2 {
317
+ ): ThemeColorInputMode_v2 {
318
318
  const {mode, scheme, tone} = options
319
319
 
320
320
  return {
@@ -357,16 +357,16 @@ function buildSelectableColorTheme(
357
357
  scheme: ThemeColorSchemeKey
358
358
  },
359
359
  config?: ThemeConfig,
360
- ): ThemeColorButtonTones_v2 {
360
+ ): ThemeColorButtonMode_v2 {
361
361
  const {scheme} = options
362
362
 
363
- const tones: Partial<ThemeColorButtonTones_v2> = {}
363
+ const tones: Partial<ThemeColorButtonMode_v2> = {}
364
364
 
365
365
  for (const tone of THEME_COLOR_STATE_TONES) {
366
366
  tones[tone] = buildSelectableStatesColorTheme({scheme, tone}, config)
367
367
  }
368
368
 
369
- return tones as ThemeColorButtonTones_v2
369
+ return tones as ThemeColorButtonMode_v2
370
370
  }
371
371
 
372
372
  function buildSelectableStatesColorTheme(
@@ -375,16 +375,16 @@ function buildSelectableStatesColorTheme(
375
375
  tone: ThemeColorStateToneKey
376
376
  },
377
377
  config?: ThemeConfig,
378
- ): ThemeColorButtonStates_v2 {
378
+ ): ThemeColorButtonTone_v2 {
379
379
  const {scheme, tone} = options
380
380
 
381
- const states: Partial<ThemeColorButtonStates_v2> = {}
381
+ const states: Partial<ThemeColorButtonTone_v2> = {}
382
382
 
383
383
  for (const state of THEME_COLOR_STATES) {
384
384
  states[state] = buildSelectableStateColorTheme({tone, scheme, state}, config)
385
385
  }
386
386
 
387
- return states as ThemeColorButtonStates_v2
387
+ return states as ThemeColorButtonTone_v2
388
388
  }
389
389
 
390
390
  function buildSelectableStateColorTheme(
@@ -0,0 +1,19 @@
1
+ import {ThemeColorTokenValue, parseTokenValue} from '../../config'
2
+ import {compileColorTokenValue} from './compileColorToken'
3
+ import {ColorTokenContext} from './types'
4
+
5
+ const DEFAULT_COLOR_TOKEN_VALUE: ThemeColorTokenValue = ['500', '500']
6
+
7
+ export function resolveColorTokenValue(
8
+ context: ColorTokenContext,
9
+ value: ThemeColorTokenValue = DEFAULT_COLOR_TOKEN_VALUE,
10
+ ): string {
11
+ const {hue, scheme} = context
12
+ const node = parseTokenValue(value[scheme === 'light' ? 0 : 1])
13
+
14
+ if (!node || node.type !== 'color') {
15
+ throw new Error(`Invalid color token: ${value[0]}`)
16
+ }
17
+
18
+ return compileColorTokenValue({...node, hue: node.hue || hue})
19
+ }
@@ -0,0 +1,21 @@
1
+ import {TokenColorValueNode} from '../../config'
2
+
3
+ export function compileColorTokenValue(node: TokenColorValueNode): string {
4
+ let key = ''
5
+
6
+ if (node.key === 'black' || node.key === 'white') {
7
+ key = node.key
8
+ } else {
9
+ key = `${node.hue}/${node.tint}`
10
+ }
11
+
12
+ if (node.mix !== undefined) {
13
+ return `${key} ${node.mix * 100}%`
14
+ }
15
+
16
+ if (node.opacity !== undefined) {
17
+ key += `/${node.opacity}`
18
+ }
19
+
20
+ return key
21
+ }
@@ -0,0 +1,2 @@
1
+ export * from './colorToken'
2
+ export * from './types'
@@ -0,0 +1,6 @@
1
+ import {ColorHueKey} from '@sanity/color'
2
+
3
+ export interface ColorTokenContext {
4
+ hue: ColorHueKey
5
+ scheme: 'light' | 'dark'
6
+ }
@@ -5,18 +5,18 @@ import {
5
5
  ThemeColorBadgeTone_v2,
6
6
  ThemeColorBadge_v2,
7
7
  ThemeColorBlendModeKey,
8
- ThemeColorButtonStates_v2,
9
- ThemeColorButtonTones_v2,
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
- ThemeColorSelectableStates_v2,
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: ThemeColorButtonTones_v2,
304
+ value: ThemeColorButtonMode_v2,
306
305
  options: {
307
306
  baseBg: string
308
307
  blendMode: ThemeColorBlendModeKey
309
308
  colorPalette: ThemeColorPalette
310
309
  },
311
- ): ThemeColorButtonTones_v2 {
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: ThemeColorButtonStates_v2,
321
+ value: ThemeColorButtonTone_v2,
323
322
  options: {
324
323
  baseBg: string
325
324
  blendMode: ThemeColorBlendModeKey
326
325
  colorPalette: ThemeColorPalette
327
326
  },
328
- ): ThemeColorButtonStates_v2 {
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: ThemeColorInputStates_v2,
411
+ value: ThemeColorInputMode_v2,
413
412
  options: {
414
413
  baseBg: string
415
414
  blendMode: ThemeColorBlendModeKey
416
415
  colorPalette: ThemeColorPalette
417
416
  },
418
- ): ThemeColorInputStates_v2 {
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: ThemeColorSelectableStates_v2,
470
+ value: ThemeColorSelectableTone_v2,
472
471
  options: {
473
472
  baseBg: string
474
473
  blendMode: ThemeColorBlendModeKey
475
474
  colorPalette: ThemeColorPalette
476
475
  },
477
- ): ThemeColorSelectableStates_v2 {
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.log('could not blend', hex, mixOptions)
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
- /** @internal */
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
- /** @internal */
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
- /** @internal */
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
- /** @internal */
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
- /** @internal */
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
- /** @internal */
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
- /** @internal */
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
- /** @internal */
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
- /** @internal */
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>>
@@ -8,6 +8,7 @@ import {
8
8
  } from '../helpers'
9
9
  import {TokenKeyNode} from './types'
10
10
 
11
+ /** @internal */
11
12
  export function parseTokenKey(str: string): TokenKeyNode | undefined {
12
13
  const segments = str.split('/')
13
14
  const segment0 = segments.shift() || ''
@@ -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
- const segment0 = segments.shift() || ''
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
- const segment1 = segments.shift() || ''
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: `${hue}`,
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' | `${ColorHueKey}/${ColorTintKey}` | ColorTintKey
32
+ key?: 'black' | 'white'
33
33
  hue?: ColorHueKey
34
- tint?: ColorTintKey
34
+ mix?: number
35
35
  opacity?: number
36
+ tint?: ColorTintKey
36
37
  }
37
38
 
38
39
  /** @internal */