@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.
Files changed (85) 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 +494 -354
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.js +503 -567
  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 +299 -252
  12. package/dist/theme.esm.js.map +1 -1
  13. package/dist/theme.js +299 -252
  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/tooltip/tooltip.tsx +47 -57
  35. package/src/core/primitives/tooltip/tooltipCard.tsx +104 -0
  36. package/src/core/styles/card/_cardColorStyle.ts +2 -0
  37. package/src/core/styles/margin/marginsStyle.test.ts +2 -2
  38. package/src/core/styles/padding/paddingStyle.test.ts +2 -2
  39. package/src/core/theme/__workshop__/build/Root.tsx +20 -3
  40. package/src/core/theme/__workshop__/build/story.tsx +16 -10
  41. package/src/core/theme/__workshop__/canvas.tsx +7 -7
  42. package/src/core/theme/__workshop__/debug/story.tsx +159 -0
  43. package/src/core/theme/__workshop__/index.ts +5 -0
  44. package/src/core/theme/theme.test.tsx +2 -2
  45. package/src/core/types/avatar.ts +1 -1
  46. package/src/core/types/button.ts +1 -2
  47. package/src/core/{primitives/tooltip → utils/conditionalWrapper}/conditionalWrapper.tsx +3 -0
  48. package/src/core/utils/conditionalWrapper/index.ts +1 -0
  49. package/src/core/utils/index.ts +1 -0
  50. package/src/theme/build/_deprecated/color/factory.ts +3 -3
  51. package/src/theme/build/buildColorTheme.ts +16 -16
  52. package/src/theme/build/colorToken/colorToken.ts +19 -0
  53. package/src/theme/build/colorToken/compileColorToken.ts +21 -0
  54. package/src/theme/build/colorToken/index.ts +2 -0
  55. package/src/theme/build/colorToken/types.ts +6 -0
  56. package/src/theme/build/renderColorTheme.ts +14 -15
  57. package/src/theme/build/renderColorValue.ts +9 -2
  58. package/src/theme/config/system.ts +12 -10
  59. package/src/theme/config/tokens/color/types.ts +12 -1
  60. package/src/theme/config/tokens/parseTokenKey.ts +1 -0
  61. package/src/theme/config/tokens/parseTokenValue.test.ts +13 -16
  62. package/src/theme/config/tokens/parseTokenValue.ts +45 -14
  63. package/src/theme/config/tokens/types.ts +3 -2
  64. package/src/theme/defaults/colorTokens.ts +219 -211
  65. package/src/theme/defaults/config.ts +2 -1
  66. package/src/theme/defaults/fonts.ts +13 -5
  67. package/src/theme/index.ts +0 -7
  68. package/src/theme/system/color/_constants.ts +5 -2
  69. package/src/theme/system/color/_system.ts +2 -1
  70. package/src/theme/system/color/avatar.ts +2 -12
  71. package/src/theme/system/color/button.ts +4 -20
  72. package/src/theme/system/color/input.ts +3 -11
  73. package/src/theme/system/color/selectable.ts +3 -14
  74. package/src/theme/system/shadow.ts +0 -6
  75. package/src/theme/system/styles.ts +0 -6
  76. package/src/theme/system/theme.ts +2 -0
  77. package/src/theme/system/v0/avatar.ts +1 -1
  78. package/src/theme/system/v0/color/button.ts +4 -4
  79. package/src/theme/system/v0/color/card.ts +2 -2
  80. package/src/theme/system/v0/color/input.ts +3 -3
  81. package/src/theme/system/v0/color/muted.ts +2 -2
  82. package/src/theme/system/v0/color/solid.ts +2 -2
  83. package/src/theme/versioning/themeColor_v0_v2.ts +2 -2
  84. package/src/theme/versioning/v2_v0.ts +2 -2
  85. package/src/theme/build/colorToken.ts +0 -39
@@ -159,6 +159,7 @@ export const Root = styled.div((props) => {
159
159
  --link-fg: var(--card-enabled-link-fg);
160
160
  --code-bg: var(--card-enabled-code-bg);
161
161
  --code-fg: var(--card-enabled-code-fg);
162
+ --kbd-bg: var(--card-enabled-kbd-bg);
162
163
  --skeleton-from: var(--card-enabled-skeleton-from);
163
164
  --skeleton-to: var(--card-enabled-skeleton-to);
164
165
 
@@ -322,15 +323,15 @@ export const Root = styled.div((props) => {
322
323
  color: var(--icon);
323
324
  }
324
325
 
325
- .muted-fg {
326
+ .muted {
326
327
  color: var(--muted-fg);
327
328
  }
328
329
 
329
- .accent-fg {
330
+ .accent {
330
331
  color: var(--accent-fg);
331
332
  }
332
333
 
333
- .link-fg {
334
+ .link {
334
335
  color: var(--link-fg);
335
336
  }
336
337
 
@@ -339,6 +340,22 @@ export const Root = styled.div((props) => {
339
340
  color: var(--code-fg);
340
341
  }
341
342
 
343
+ .kbd {
344
+ background-color: var(--kbd-bg);
345
+ color: var(--kbd-fg);
346
+ }
347
+
348
+ .badge {
349
+ background-color: var(--badge-bg);
350
+ color: var(--badge-fg);
351
+ }
352
+
353
+ .badge--default {
354
+ --badge-bg: var(--badge-default-bg);
355
+ --badge-fg: var(--badge-default-fg);
356
+ --badge-border: var(--badge-default-border);
357
+ }
358
+
342
359
  .skeleton-from {
343
360
  color: var(--skeleton-from);
344
361
  }
@@ -1,27 +1,27 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
 
3
3
  import {
4
- ThemeColorButtonStates_v2,
4
+ ThemeColorButtonTone_v2,
5
5
  ThemeColorCard_v2,
6
- ThemeColorInputStates_v2,
6
+ ThemeColorInputMode_v2,
7
7
  ThemeColorState_v2,
8
8
  } from '@sanity/ui/theme'
9
9
  import {
10
- THEME_COLOR_CARD_TONES,
11
10
  THEME_COLOR_BUTTON_MODES,
11
+ THEME_COLOR_CARD_TONES,
12
12
  THEME_COLOR_INPUT_MODES,
13
13
  THEME_COLOR_STATE_TONES,
14
14
  ThemeColorCardToneKey,
15
15
  ThemeColorInputModeKey,
16
16
  } from '@sanity/ui/theme'
17
- import {defaultTheme} from '@sanity/ui/theme'
17
+ import {buildTheme} from '@sanity/ui/theme'
18
18
  import {ReactElement} from 'react'
19
19
  import {rem} from '../../../styles'
20
20
  import {useTheme_v2} from '../../useTheme'
21
21
  import {getCSSProps} from './helpers'
22
22
  import {Root} from './Root'
23
23
 
24
- const theme = defaultTheme
24
+ const theme = buildTheme()
25
25
 
26
26
  export default function BuildStory(): ReactElement {
27
27
  return (
@@ -268,7 +268,7 @@ function StatePreview(props: {theme: ThemeColorState_v2}) {
268
268
  )
269
269
  }
270
270
 
271
- function ButtonPreview(props: {theme: ThemeColorButtonStates_v2}) {
271
+ function ButtonPreview(props: {theme: ThemeColorButtonTone_v2}) {
272
272
  const {theme: button} = props
273
273
 
274
274
  return (
@@ -289,18 +289,24 @@ function ButtonPreview(props: {theme: ThemeColorButtonStates_v2}) {
289
289
  <div className="icon" style={{flex: 'none'}}>
290
290
  &copy;
291
291
  </div>
292
- <div className="muted-fg" style={{flex: 'none'}}>
292
+ <div className="muted" style={{flex: 'none'}}>
293
293
  m
294
294
  </div>
295
- <div className="accent-fg" style={{flex: 'none'}}>
295
+ <div className="accent" style={{flex: 'none'}}>
296
296
  a
297
297
  </div>
298
- <div className="link-fg" style={{flex: 'none'}}>
298
+ <div className="link" style={{flex: 'none'}}>
299
299
  l
300
300
  </div>
301
301
  <div className="code" style={{flex: 'none'}}>
302
302
  c
303
303
  </div>
304
+ <div className="kbd" style={{flex: 'none'}}>
305
+ k
306
+ </div>
307
+ <div className="badge badge--default" style={{flex: 'none'}}>
308
+ b
309
+ </div>
304
310
  <div style={{flex: 'none'}}>
305
311
  <CheckeredBackground />
306
312
  </div>
@@ -424,7 +430,7 @@ function Skeleton() {
424
430
  )
425
431
  }
426
432
 
427
- function InputPreview(props: {mode: ThemeColorInputModeKey; theme: ThemeColorInputStates_v2}) {
433
+ function InputPreview(props: {mode: ThemeColorInputModeKey; theme: ThemeColorInputMode_v2}) {
428
434
  const {mode, theme: input} = props
429
435
 
430
436
  return (
@@ -10,14 +10,14 @@ import {
10
10
  useRootTheme,
11
11
  } from '@sanity/ui'
12
12
  import {
13
- ThemeColorButtonStates_v2,
14
- ThemeColorButtonTones_v2,
13
+ ThemeColorButtonMode_v2,
14
+ ThemeColorButtonTone_v2,
15
15
  ThemeColorButton_v2,
16
+ ThemeColorCard_v2,
16
17
  ThemeColorScheme_v2,
17
- ThemeColorSelectableStates_v2,
18
+ ThemeColorSelectableTone_v2,
18
19
  ThemeColorSelectable_v2,
19
20
  ThemeColorState_v2,
20
- ThemeColorCard_v2,
21
21
  getContrastRatio,
22
22
  mix,
23
23
  parseColor,
@@ -202,7 +202,7 @@ function ColorButton(props: {color: ThemeColorButton_v2}) {
202
202
  )
203
203
  }
204
204
 
205
- function ColorButtonMode(props: {color: ThemeColorButtonTones_v2}) {
205
+ function ColorButtonMode(props: {color: ThemeColorButtonMode_v2}) {
206
206
  const {color} = props
207
207
 
208
208
  return (
@@ -243,7 +243,7 @@ function ColorButtonMode(props: {color: ThemeColorButtonTones_v2}) {
243
243
  )
244
244
  }
245
245
 
246
- function ColorGenericStates(props: {color: ThemeColorButtonStates_v2}) {
246
+ function ColorGenericStates(props: {color: ThemeColorButtonTone_v2}) {
247
247
  const {color} = props
248
248
 
249
249
  return (
@@ -335,7 +335,7 @@ function ColorSelectable(props: {color: ThemeColorSelectable_v2}) {
335
335
  )
336
336
  }
337
337
 
338
- function ColorSelectableTone(props: {color: ThemeColorSelectableStates_v2}) {
338
+ function ColorSelectableTone(props: {color: ThemeColorSelectableTone_v2}) {
339
339
  const {color} = props
340
340
 
341
341
  return (
@@ -0,0 +1,159 @@
1
+ import {
2
+ THEME_COLOR_BUTTON_MODES,
3
+ THEME_COLOR_CARD_TONES,
4
+ THEME_COLOR_SCHEMES,
5
+ THEME_COLOR_STATES,
6
+ THEME_COLOR_STATE_TONES,
7
+ ThemeColorCard_v2,
8
+ ThemeColorScheme_v2,
9
+ ThemeColorState_v2,
10
+ } from '@sanity/ui/theme'
11
+ import {CSSProperties} from 'react'
12
+ import {Badge, Box, Flex, KBD, Stack, Text} from '../../../primitives'
13
+ import {useRootTheme} from '../../useRootTheme'
14
+
15
+ export default function DebugStory() {
16
+ const {color} = useRootTheme().theme.v2!
17
+
18
+ return (
19
+ <Flex>
20
+ {THEME_COLOR_SCHEMES.map((scheme) => (
21
+ <DebugScheme key={scheme} scheme={color[scheme]} />
22
+ ))}
23
+ </Flex>
24
+ )
25
+ }
26
+
27
+ function DebugScheme(props: {scheme: ThemeColorScheme_v2}) {
28
+ const {scheme} = props
29
+
30
+ return (
31
+ <Box flex={1} style={{backgroundColor: scheme.default.bg}}>
32
+ {THEME_COLOR_CARD_TONES.map((tone) => (
33
+ <DebugCard card={scheme[tone]} key={tone} />
34
+ ))}
35
+ </Box>
36
+ )
37
+ }
38
+
39
+ function DebugCard(props: {card: ThemeColorCard_v2}) {
40
+ const {card} = props
41
+
42
+ // card.avatar
43
+ // card.backdrop
44
+ // card.badge
45
+ // card.button
46
+ // card.focusRing
47
+ // card.icon
48
+ // card.input
49
+ // card.kbd
50
+ // card.link
51
+ // card.selectable
52
+ // card.shadow
53
+ // card.skeleton
54
+ // card.syntax
55
+
56
+ return (
57
+ <Box style={getStateVars(card)}>
58
+ <DebugState />
59
+ <Stack padding={2} space={1}>
60
+ {THEME_COLOR_BUTTON_MODES.map((mode) => (
61
+ <Stack key={mode} space={1}>
62
+ {THEME_COLOR_STATE_TONES.map((stateTone) => (
63
+ <Flex key={stateTone} gap={1}>
64
+ {/* {mode} */}
65
+ {THEME_COLOR_STATES.map((state) => (
66
+ <Box
67
+ flex={1}
68
+ key={state}
69
+ style={getStateVars(card.button[mode][stateTone][state])}
70
+ >
71
+ <DebugState />
72
+ {/* {state} */}
73
+ </Box>
74
+ ))}
75
+ </Flex>
76
+ ))}
77
+ </Stack>
78
+ ))}
79
+ </Stack>
80
+ </Box>
81
+ )
82
+ }
83
+
84
+ function DebugState() {
85
+ return (
86
+ <Stack
87
+ overflow="auto"
88
+ padding={4}
89
+ space={3}
90
+ style={{border: '1px solid var(--card-border-color)'}}
91
+ >
92
+ <Text size={1}>Text</Text>
93
+ <Text muted size={1}>
94
+ Muted
95
+ </Text>
96
+ <Text accent size={1}>
97
+ Accent
98
+ </Text>
99
+ <Text size={1}>
100
+ <code>Code</code>
101
+ </Text>
102
+ <div>
103
+ <KBD>Cmd</KBD>
104
+ </div>
105
+ <Flex gap={1}>
106
+ {THEME_COLOR_STATE_TONES.map((stateTone) => (
107
+ <Box flex="none" key={stateTone}>
108
+ <Badge tone={stateTone}>{stateTone}</Badge>
109
+ </Box>
110
+ ))}
111
+ </Flex>
112
+ <div style={{borderBottom: '1px solid var(--card-border-color)'}} />
113
+ </Stack>
114
+ )
115
+ }
116
+
117
+ function getStateVars(state: ThemeColorState_v2) {
118
+ return {
119
+ '--card-bg-color': state.bg,
120
+ '--card-border-color': state.border,
121
+ '--card-fg-color': state.fg,
122
+ '--card-accent-fg-color': state.accent.fg,
123
+ '--card-muted-fg-color': state.muted.fg,
124
+ '--card-code-bg-color': state.code.bg,
125
+ '--card-code-fg-color': state.code.fg,
126
+
127
+ '--card-kbd-bg-color': state.kbd.bg,
128
+ '--card-kbd-border-color': state.kbd.border,
129
+ '--card-kbd-fg-color': state.kbd.fg,
130
+
131
+ '--card-badge-default-bg-color': state.badge.default.bg,
132
+ '--card-badge-default-dot-color': state.badge.default.dot,
133
+ '--card-badge-default-fg-color': state.badge.default.fg,
134
+ '--card-badge-default-icon-color': state.badge.default.icon,
135
+
136
+ '--card-badge-primary-bg-color': state.badge.primary.bg,
137
+ '--card-badge-primary-dot-color': state.badge.primary.dot,
138
+ '--card-badge-primary-fg-color': state.badge.primary.fg,
139
+ '--card-badge-primary-icon-color': state.badge.primary.icon,
140
+
141
+ '--card-badge-positive-bg-color': state.badge.positive.bg,
142
+ '--card-badge-positive-dot-color': state.badge.positive.dot,
143
+ '--card-badge-positive-fg-color': state.badge.positive.fg,
144
+ '--card-badge-positive-icon-color': state.badge.positive.icon,
145
+
146
+ '--card-badge-caution-bg-color': state.badge.caution.bg,
147
+ '--card-badge-caution-dot-color': state.badge.caution.dot,
148
+ '--card-badge-caution-fg-color': state.badge.caution.fg,
149
+ '--card-badge-caution-icon-color': state.badge.caution.icon,
150
+
151
+ '--card-badge-critical-bg-color': state.badge.critical.bg,
152
+ '--card-badge-critical-dot-color': state.badge.critical.dot,
153
+ '--card-badge-critical-fg-color': state.badge.critical.fg,
154
+ '--card-badge-critical-icon-color': state.badge.critical.icon,
155
+
156
+ backgroundColor: 'var(--card-bg-color)',
157
+ color: 'var(--card-fg-color)',
158
+ } as CSSProperties
159
+ }
@@ -5,6 +5,11 @@ export default defineScope({
5
5
  name: 'theme',
6
6
  title: 'Theme',
7
7
  stories: [
8
+ {
9
+ name: 'debug',
10
+ title: 'Debug',
11
+ component: lazy(() => import('./debug/story')),
12
+ },
8
13
  {
9
14
  name: 'build',
10
15
  title: 'Build theme',
@@ -1,7 +1,7 @@
1
1
  /** @jest-environment jsdom */
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
 
4
- import {defaultTheme} from '@sanity/ui/theme'
4
+ import {buildTheme} from '@sanity/ui/theme'
5
5
  import {render} from '../../../test'
6
6
  import {ThemeContext} from './themeContext'
7
7
  import {ThemeContextValue} from './types'
@@ -24,7 +24,7 @@ describe('theme', () => {
24
24
  const value: ThemeContextValue = {
25
25
  version: 0.0,
26
26
  scheme: 'light',
27
- theme: defaultTheme,
27
+ theme: buildTheme(),
28
28
  tone: 'default',
29
29
  }
30
30
 
@@ -6,7 +6,7 @@ export type AvatarPosition = 'top' | 'bottom' | 'inside'
6
6
  /**
7
7
  * @public
8
8
  */
9
- export type AvatarSize = 0 | 1 | 2
9
+ export type AvatarSize = 0 | 1 | 2 | 3
10
10
 
11
11
  /**
12
12
  * @public
@@ -1,5 +1,4 @@
1
- import {ThemeColorStateToneKey} from '@sanity/ui/theme'
2
- import {ThemeColorButtonModeKey} from '../_compat'
1
+ import {ThemeColorButtonModeKey, ThemeColorStateToneKey} from '@sanity/ui/theme'
3
2
 
4
3
  /**
5
4
  * @public
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @internal
3
+ */
1
4
  export function ConditionalWrapper({
2
5
  children,
3
6
  condition,
@@ -0,0 +1 @@
1
+ export * from './conditionalWrapper'
@@ -1,5 +1,6 @@
1
1
  export * from './arrow'
2
2
  export * from './boundaryElement'
3
+ export * from './conditionalWrapper'
3
4
  export * from './elementQuery'
4
5
  export * from './errorBoundary'
5
6
  export * from './layer'
@@ -27,7 +27,7 @@ import {createSpot} from './spot/createSpot'
27
27
 
28
28
  /**
29
29
  * @public
30
- * @deprecated
30
+ * @deprecated Use `buildColorTheme` instead.
31
31
  */
32
32
  export interface ThemeColorBuilderOpts {
33
33
  base: (opts: {dark: boolean; name: ThemeColorName}) => ThemeColorBase
@@ -82,13 +82,13 @@ export interface ThemeColorBuilderOpts {
82
82
 
83
83
  /**
84
84
  * @public
85
- * @deprecated
85
+ * @deprecated Use `ThemeConfig` instead.
86
86
  */
87
87
  export type PartialThemeColorBuilderOpts = Partial<ThemeColorBuilderOpts>
88
88
 
89
89
  /**
90
90
  * @public
91
- * @deprecated Use `buildTheme` instead
91
+ * @deprecated Use `buildColorTheme` instead.
92
92
  */
93
93
  export function createColorTheme(
94
94
  partialOpts: PartialThemeColorBuilderOpts = {},
@@ -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
+ }