@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
@@ -7,6 +7,7 @@ export const defaultThemeConfig: Omit<RootTheme_v2, 'color' | 'font'> = {
7
7
  _version: 2,
8
8
  avatar: {
9
9
  sizes: [
10
+ {distance: -4, size: 19},
10
11
  {distance: -4, size: 25},
11
12
  {distance: -8, size: 33},
12
13
  {distance: -12, size: 49},
@@ -56,7 +57,7 @@ export const defaultThemeConfig: Omit<RootTheme_v2, 'color' | 'font'> = {
56
57
  switch: {
57
58
  width: 25,
58
59
  height: 17,
59
- padding: 2,
60
+ padding: 5,
60
61
  transitionDurationMs: 150,
61
62
  transitionTimingFunction: 'ease-out',
62
63
  focusRing: {offset: 1, width: 1},
@@ -125,7 +125,15 @@ export const defaultThemeFonts: ThemeFonts = {
125
125
  {
126
126
  ascenderHeight: 2,
127
127
  descenderHeight: 2,
128
- fontSize: 9.8,
128
+ fontSize: 8.1,
129
+ iconSize: 13,
130
+ lineHeight: 10,
131
+ letterSpacing: 0.5,
132
+ },
133
+ {
134
+ ascenderHeight: 2,
135
+ descenderHeight: 2,
136
+ fontSize: 9.5,
129
137
  iconSize: 15,
130
138
  lineHeight: 11,
131
139
  letterSpacing: 0.5,
@@ -133,7 +141,7 @@ export const defaultThemeFonts: ThemeFonts = {
133
141
  {
134
142
  ascenderHeight: 2,
135
143
  descenderHeight: 2,
136
- fontSize: 11.25,
144
+ fontSize: 10.8,
137
145
  iconSize: 17,
138
146
  lineHeight: 12,
139
147
  letterSpacing: 0.5,
@@ -141,7 +149,7 @@ export const defaultThemeFonts: ThemeFonts = {
141
149
  {
142
150
  ascenderHeight: 2,
143
151
  descenderHeight: 2,
144
- fontSize: 12.75,
152
+ fontSize: 12.25,
145
153
  iconSize: 19,
146
154
  lineHeight: 13,
147
155
  letterSpacing: 0.5,
@@ -149,7 +157,7 @@ export const defaultThemeFonts: ThemeFonts = {
149
157
  {
150
158
  ascenderHeight: 2,
151
159
  descenderHeight: 2,
152
- fontSize: 14,
160
+ fontSize: 13.6,
153
161
  iconSize: 21,
154
162
  lineHeight: 14,
155
163
  letterSpacing: 0.5,
@@ -157,7 +165,7 @@ export const defaultThemeFonts: ThemeFonts = {
157
165
  {
158
166
  ascenderHeight: 2,
159
167
  descenderHeight: 2,
160
- fontSize: 15.5,
168
+ fontSize: 15,
161
169
  iconSize: 23,
162
170
  lineHeight: 15,
163
171
  letterSpacing: 0.5,
@@ -1,12 +1,5 @@
1
- import {buildTheme} from './build'
2
-
3
1
  export * from './build'
4
2
  export * from './config'
5
3
  export * from './getScopedTheme'
6
4
  export * from './system'
7
5
  export * from './versioning'
8
-
9
- /**
10
- * @public
11
- */
12
- export const defaultTheme = buildTheme()
@@ -1,5 +1,8 @@
1
1
  import {COLOR_HUES} from '@sanity/color'
2
2
 
3
+ /** @public */
4
+ export const THEME_COLOR_SCHEMES = ['light', 'dark'] as const
5
+
3
6
  /** @public */
4
7
  export const THEME_COLOR_BLEND_MODES = ['multiply', 'screen'] as const
5
8
 
@@ -7,7 +10,7 @@ export const THEME_COLOR_BLEND_MODES = ['multiply', 'screen'] as const
7
10
  export const THEME_COLOR_CARD_TONES = [
8
11
  'transparent',
9
12
  'default',
10
- 'primary', // todo: rename to `accent` in the next breaking major version
13
+ 'primary',
11
14
  'positive',
12
15
  'caution',
13
16
  'critical',
@@ -16,7 +19,7 @@ export const THEME_COLOR_CARD_TONES = [
16
19
  /** @public */
17
20
  export const THEME_COLOR_STATE_TONES = [
18
21
  'default',
19
- 'primary', // todo: rename to `accent` in the next breaking major version
22
+ 'primary',
20
23
  'positive',
21
24
  'caution',
22
25
  'critical',
@@ -5,6 +5,7 @@ import {
5
5
  THEME_COLOR_CARD_TONES,
6
6
  THEME_COLOR_INPUT_MODES,
7
7
  THEME_COLOR_INPUT_STATES,
8
+ THEME_COLOR_SCHEMES,
8
9
  THEME_COLOR_STATES,
9
10
  THEME_COLOR_STATE_TONES,
10
11
  } from './_constants'
@@ -12,7 +13,7 @@ import {
12
13
  /**
13
14
  * @public
14
15
  */
15
- export type ThemeColorSchemeKey = 'dark' | 'light'
16
+ export type ThemeColorSchemeKey = (typeof THEME_COLOR_SCHEMES)[number]
16
17
 
17
18
  /** @public */
18
19
  export type ThemeColorBlendModeKey = (typeof THEME_COLOR_BLEND_MODES)[number]
@@ -1,4 +1,4 @@
1
- import {ThemeColorBlendModeKey} from './_system'
1
+ import {ThemeColorAvatarColorKey, ThemeColorBlendModeKey} from './_system'
2
2
 
3
3
  /**
4
4
  * @public
@@ -12,14 +12,4 @@ export interface ThemeColorAvatarHue_v2 {
12
12
  /**
13
13
  * @public
14
14
  */
15
- export interface ThemeColorAvatar_v2 {
16
- gray: ThemeColorAvatarHue_v2
17
- blue: ThemeColorAvatarHue_v2
18
- purple: ThemeColorAvatarHue_v2
19
- magenta: ThemeColorAvatarHue_v2
20
- red: ThemeColorAvatarHue_v2
21
- orange: ThemeColorAvatarHue_v2
22
- yellow: ThemeColorAvatarHue_v2
23
- green: ThemeColorAvatarHue_v2
24
- cyan: ThemeColorAvatarHue_v2
25
- }
15
+ export type ThemeColorAvatar_v2 = Record<ThemeColorAvatarColorKey, ThemeColorAvatarHue_v2>
@@ -1,33 +1,17 @@
1
+ import {ThemeColorButtonModeKey, ThemeColorStateKey, ThemeColorStateToneKey} from './_system'
1
2
  import {ThemeColorState_v2} from './state'
2
3
 
3
4
  /**
4
5
  * @public
5
6
  */
6
- export interface ThemeColorButtonStates_v2 {
7
- enabled: ThemeColorState_v2
8
- hovered: ThemeColorState_v2
9
- pressed: ThemeColorState_v2
10
- selected: ThemeColorState_v2
11
- disabled: ThemeColorState_v2
12
- }
7
+ export type ThemeColorButtonTone_v2 = Record<ThemeColorStateKey, ThemeColorState_v2>
13
8
 
14
9
  /**
15
- * TODO: Rename to `ThemeColorButtonMode`.
16
10
  * @public
17
11
  */
18
- export interface ThemeColorButtonTones_v2 {
19
- default: ThemeColorButtonStates_v2
20
- primary: ThemeColorButtonStates_v2
21
- positive: ThemeColorButtonStates_v2
22
- caution: ThemeColorButtonStates_v2
23
- critical: ThemeColorButtonStates_v2
24
- }
12
+ export type ThemeColorButtonMode_v2 = Record<ThemeColorStateToneKey, ThemeColorButtonTone_v2>
25
13
 
26
14
  /**
27
15
  * @public
28
16
  */
29
- export interface ThemeColorButton_v2 {
30
- default: ThemeColorButtonTones_v2
31
- ghost: ThemeColorButtonTones_v2
32
- bleed: ThemeColorButtonTones_v2
33
- }
17
+ export type ThemeColorButton_v2 = Record<ThemeColorButtonModeKey, ThemeColorButtonMode_v2>
@@ -1,4 +1,4 @@
1
- import {ThemeColorBlendModeKey} from './_system'
1
+ import {ThemeColorBlendModeKey, ThemeColorInputModeKey, ThemeColorInputStateKey} from './_system'
2
2
 
3
3
  /**
4
4
  * @public
@@ -17,17 +17,9 @@ export interface ThemeColorInputState_v2 {
17
17
  /**
18
18
  * @public
19
19
  */
20
- export interface ThemeColorInputStates_v2 {
21
- enabled: ThemeColorInputState_v2
22
- disabled: ThemeColorInputState_v2
23
- hovered: ThemeColorInputState_v2
24
- readOnly: ThemeColorInputState_v2
25
- }
20
+ export type ThemeColorInputMode_v2 = Record<ThemeColorInputStateKey, ThemeColorInputState_v2>
26
21
 
27
22
  /**
28
23
  * @public
29
24
  */
30
- export interface ThemeColorInput_v2 {
31
- default: ThemeColorInputStates_v2
32
- invalid: ThemeColorInputStates_v2
33
- }
25
+ export type ThemeColorInput_v2 = Record<ThemeColorInputModeKey, ThemeColorInputMode_v2>
@@ -1,23 +1,12 @@
1
+ import {ThemeColorStateKey, ThemeColorStateToneKey} from './_system'
1
2
  import {ThemeColorState_v2} from './state'
2
3
 
3
4
  /**
4
5
  * @public
5
6
  */
6
- export interface ThemeColorSelectableStates_v2 {
7
- enabled: ThemeColorState_v2
8
- hovered: ThemeColorState_v2
9
- pressed: ThemeColorState_v2
10
- selected: ThemeColorState_v2
11
- disabled: ThemeColorState_v2
12
- }
7
+ export type ThemeColorSelectableTone_v2 = Record<ThemeColorStateKey, ThemeColorState_v2>
13
8
 
14
9
  /**
15
10
  * @public
16
11
  */
17
- export interface ThemeColorSelectable_v2 {
18
- default: ThemeColorSelectableStates_v2
19
- primary: ThemeColorSelectableStates_v2
20
- positive: ThemeColorSelectableStates_v2
21
- caution: ThemeColorSelectableStates_v2
22
- critical: ThemeColorSelectableStates_v2
23
- }
12
+ export type ThemeColorSelectable_v2 = Record<ThemeColorStateToneKey, ThemeColorSelectableTone_v2>
@@ -9,12 +9,6 @@ export type ThemeBoxShadow = [
9
9
  number,
10
10
  ]
11
11
 
12
- /**
13
- * @public
14
- * @deprecated Use `ThemeBoxShadow` instead
15
- */
16
- export type BoxShadow = ThemeBoxShadow
17
-
18
12
  /**
19
13
  * @public
20
14
  */
@@ -11,9 +11,3 @@ export interface ThemeStyles {
11
11
  root?: CSSObject
12
12
  }
13
13
  }
14
-
15
- /**
16
- * @deprecated Use `ThemeStyles` instead
17
- * @internal
18
- */
19
- export type Styles = ThemeStyles
@@ -33,6 +33,7 @@ export interface RootTheme_v2 {
33
33
  radius: number[]
34
34
  shadow: Array<ThemeShadow | null>
35
35
  space: number[]
36
+ /** @internal */
36
37
  style?: ThemeStyles
37
38
  }
38
39
 
@@ -97,6 +98,7 @@ export interface BaseTheme {
97
98
  */
98
99
  space: number[]
99
100
  /**
101
+ * @internal
100
102
  * @deprecated Use `v2.style` instead
101
103
  */
102
104
  styles?: ThemeStyles
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @public
3
- * @deprecated Use `ThemeAvatar_v2` instead
3
+ * @deprecated Use `ThemeAvatar_v2` from `@sanity/ui/theme` instead.
4
4
  */
5
5
  export interface ThemeAvatar {
6
6
  sizes: {
@@ -2,13 +2,13 @@ import {ThemeColorGenericState} from './_generic'
2
2
 
3
3
  /**
4
4
  * @public
5
- * @deprecated Use `ThemeColorGenericState` instead.
5
+ * @deprecated Use `ThemeColorState_v2` instead.
6
6
  */
7
7
  export type ThemeColorButtonState = ThemeColorGenericState
8
8
 
9
9
  /**
10
10
  * @public
11
- * @deprecated
11
+ * @deprecated Use `ThemeColorButtonStates_v2` instead.
12
12
  */
13
13
  export interface ThemeColorButtonStates {
14
14
  enabled: ThemeColorGenericState
@@ -21,7 +21,7 @@ export interface ThemeColorButtonStates {
21
21
  /**
22
22
  * TODO: Rename to `ThemeColorButtonMode`.
23
23
  * @public
24
- * @deprecated
24
+ * @deprecated Use `ThemeColorButtonTones_v2` instead.
25
25
  */
26
26
  export interface ThemeColorButtonTones {
27
27
  default: ThemeColorButtonStates
@@ -33,7 +33,7 @@ export interface ThemeColorButtonTones {
33
33
 
34
34
  /**
35
35
  * @public
36
- * @deprecated
36
+ * @deprecated Use `ThemeColorButton_v2` instead.
37
37
  */
38
38
  export interface ThemeColorButton {
39
39
  default: ThemeColorButtonTones
@@ -2,13 +2,13 @@ import {ThemeColorGenericState} from './_generic'
2
2
 
3
3
  /**
4
4
  * @public
5
- * @deprecated Use `ThemeColorGenericState` instead.
5
+ * @deprecated Use `ThemeColorState_v2` instead.
6
6
  */
7
7
  export type ThemeColorCardState = ThemeColorGenericState
8
8
 
9
9
  /**
10
10
  * @public
11
- * @deprecated
11
+ * @deprecated Use `ThemeColorSelectable_v2` instead.
12
12
  */
13
13
  export interface ThemeColorCard {
14
14
  enabled: ThemeColorGenericState
@@ -2,7 +2,7 @@ import {ThemeColorBlendModeKey} from '../../color/_system'
2
2
 
3
3
  /**
4
4
  * @public
5
- * @deprecated
5
+ * @deprecated Use `ThemeColorInputState_v2` instead.
6
6
  */
7
7
  export interface ThemeColorInputState {
8
8
  _blend?: ThemeColorBlendModeKey
@@ -15,7 +15,7 @@ export interface ThemeColorInputState {
15
15
 
16
16
  /**
17
17
  * @public
18
- * @deprecated
18
+ * @deprecated Use `ThemeColorInputMode_v2` instead.
19
19
  */
20
20
  export interface ThemeColorInputStates {
21
21
  enabled: ThemeColorInputState
@@ -26,7 +26,7 @@ export interface ThemeColorInputStates {
26
26
 
27
27
  /**
28
28
  * @public
29
- * @deprecated
29
+ * @deprecated Use `ThemeColorInput_v2` instead.
30
30
  */
31
31
  export interface ThemeColorInput {
32
32
  default: ThemeColorInputStates
@@ -2,7 +2,7 @@ import {ThemeColorGenericState} from './_generic'
2
2
 
3
3
  /**
4
4
  * @public
5
- * @deprecated
5
+ * @deprecated Use `ThemeColorSelectableTone_v2` instead.
6
6
  */
7
7
  export interface ThemeColorMutedTone {
8
8
  enabled: ThemeColorGenericState
@@ -14,7 +14,7 @@ export interface ThemeColorMutedTone {
14
14
 
15
15
  /**
16
16
  * @public
17
- * @deprecated
17
+ * @deprecated Use `ThemeColorSelectable_v2` instead.
18
18
  */
19
19
  export interface ThemeColorMuted {
20
20
  default: ThemeColorMutedTone
@@ -2,7 +2,7 @@ import {ThemeColorGenericState} from './_generic'
2
2
 
3
3
  /**
4
4
  * @public
5
- * @deprecated
5
+ * @deprecated Use `ThemeColorSelectableTone_v2` instead.
6
6
  */
7
7
  export interface ThemeColorSolidTone {
8
8
  enabled: ThemeColorGenericState
@@ -14,7 +14,7 @@ export interface ThemeColorSolidTone {
14
14
 
15
15
  /**
16
16
  * @public
17
- * @deprecated
17
+ * @deprecated Use `ThemeColorSelectable_v2` instead.
18
18
  */
19
19
  export interface ThemeColorSolid {
20
20
  default: ThemeColorSolidTone
@@ -6,7 +6,7 @@ import {
6
6
  ThemeColorState_v2,
7
7
  ThemeColorCard_v2,
8
8
  ThemeColorInputStates,
9
- ThemeColorInputStates_v2,
9
+ ThemeColorInputMode_v2,
10
10
  ThemeColorInputState,
11
11
  ThemeColorInputState_v2,
12
12
  } from '../system'
@@ -195,7 +195,7 @@ function stateThemeColor_v0_v2(v0: ThemeColor, state: ThemeColorGenericState): T
195
195
  }
196
196
  }
197
197
 
198
- function inputStatesThemeColor_v0_v2(states: ThemeColorInputStates): ThemeColorInputStates_v2 {
198
+ function inputStatesThemeColor_v0_v2(states: ThemeColorInputStates): ThemeColorInputMode_v2 {
199
199
  return {
200
200
  enabled: inputStateThemeColor_v0_v2(states.enabled),
201
201
  disabled: inputStateThemeColor_v0_v2(states.disabled),
@@ -3,10 +3,10 @@ import {
3
3
  RootTheme_v2,
4
4
  ThemeColor,
5
5
  ThemeColorCard_v2,
6
+ ThemeColorInputMode_v2,
6
7
  ThemeColorInputState,
7
8
  ThemeColorInputState_v2,
8
9
  ThemeColorInputStates,
9
- ThemeColorInputStates_v2,
10
10
  } from '../system'
11
11
 
12
12
  const cache = new WeakMap<RootTheme_v2, RootTheme>()
@@ -106,7 +106,7 @@ function themeColor_v2_v0(color_v2: ThemeColorCard_v2): ThemeColor {
106
106
  }
107
107
  }
108
108
 
109
- function inputStatesThemeColor_v2_v0(t: ThemeColorInputStates_v2): ThemeColorInputStates {
109
+ function inputStatesThemeColor_v2_v0(t: ThemeColorInputMode_v2): ThemeColorInputStates {
110
110
  return {
111
111
  enabled: inputStateThemeColor_v2_v0(t.enabled),
112
112
  disabled: inputStateThemeColor_v2_v0(t.disabled),
@@ -1,39 +0,0 @@
1
- import {ColorHueKey} from '@sanity/color'
2
- import {ThemeColorTokenValue, parseTokenValue, TokenColorValueNode} from '../config'
3
-
4
- export interface ColorTokenContext {
5
- hue: ColorHueKey
6
- scheme: 'light' | 'dark'
7
- }
8
-
9
- const DEFAULT_COLOR_TOKEN_VALUE: ThemeColorTokenValue = ['500', '500']
10
-
11
- export function resolveColorTokenValue(
12
- context: ColorTokenContext,
13
- value: ThemeColorTokenValue = DEFAULT_COLOR_TOKEN_VALUE,
14
- ): string {
15
- const {hue, scheme} = context
16
- const node = parseTokenValue(value[scheme === 'light' ? 0 : 1])
17
-
18
- if (!node || node.type !== 'color') {
19
- throw new Error(`Invalid color token: ${value[0]}`)
20
- }
21
-
22
- return compileColorTokenValue({...node, hue: node.hue || hue})
23
- }
24
-
25
- export function compileColorTokenValue(node: TokenColorValueNode): string {
26
- let key = ''
27
-
28
- if (node.key === 'black' || node.key === 'white') {
29
- key = node.key
30
- } else {
31
- key = `${node.hue}/${node.tint}`
32
- }
33
-
34
- if (node.opacity !== undefined) {
35
- key += `/${node.opacity}`
36
- }
37
-
38
- return key
39
- }