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

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 (67) hide show
  1. package/dist/index.cjs.mjs +10 -36
  2. package/dist/index.d.ts +180 -239
  3. package/dist/index.esm.js +105 -84
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +113 -297
  6. package/dist/index.js.map +1 -1
  7. package/dist/theme.cjs.mjs +1 -1
  8. package/dist/theme.d.ts +75 -111
  9. package/dist/theme.esm.js +169 -97
  10. package/dist/theme.esm.js.map +1 -1
  11. package/dist/theme.js +169 -97
  12. package/dist/theme.js.map +1 -1
  13. package/package.json +1 -1
  14. package/src/core/__workshop__/constants.ts +3 -2
  15. package/src/core/_compat.ts +236 -87
  16. package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +6 -3
  17. package/src/core/primitives/avatar/__workshop__/asButton.tsx +1 -1
  18. package/src/core/primitives/avatar/__workshop__/stack.tsx +1 -1
  19. package/src/core/primitives/avatar/avatar.tsx +14 -4
  20. package/src/core/primitives/avatar/avatarCounter.tsx +16 -5
  21. package/src/core/primitives/avatar/avatarStack.tsx +2 -2
  22. package/src/core/primitives/kbd/kbd.tsx +2 -0
  23. package/src/core/primitives/tooltip/tooltip.tsx +1 -1
  24. package/src/core/styles/margin/marginsStyle.test.ts +2 -2
  25. package/src/core/styles/padding/paddingStyle.test.ts +2 -2
  26. package/src/core/theme/__workshop__/build/Root.tsx +20 -3
  27. package/src/core/theme/__workshop__/build/story.tsx +16 -10
  28. package/src/core/theme/__workshop__/canvas.tsx +7 -7
  29. package/src/core/theme/__workshop__/debug/story.tsx +159 -0
  30. package/src/core/theme/__workshop__/index.ts +5 -0
  31. package/src/core/theme/theme.test.tsx +2 -2
  32. package/src/core/types/avatar.ts +1 -1
  33. package/src/core/types/button.ts +1 -2
  34. package/src/theme/build/_deprecated/color/factory.ts +3 -3
  35. package/src/theme/build/buildColorTheme.ts +16 -16
  36. package/src/theme/build/colorToken/colorToken.ts +19 -0
  37. package/src/theme/build/colorToken/compileColorToken.ts +17 -0
  38. package/src/theme/build/colorToken/index.ts +2 -0
  39. package/src/theme/build/colorToken/types.ts +6 -0
  40. package/src/theme/build/renderColorTheme.ts +14 -15
  41. package/src/theme/build/renderColorValue.ts +1 -1
  42. package/src/theme/config/system.ts +9 -9
  43. package/src/theme/config/tokens/color/types.ts +12 -1
  44. package/src/theme/config/tokens/parseTokenKey.ts +1 -0
  45. package/src/theme/config/tokens/parseTokenValue.ts +1 -0
  46. package/src/theme/defaults/colorTokens.ts +127 -66
  47. package/src/theme/defaults/config.ts +1 -0
  48. package/src/theme/defaults/fonts.ts +13 -5
  49. package/src/theme/index.ts +0 -7
  50. package/src/theme/system/color/_constants.ts +5 -2
  51. package/src/theme/system/color/_system.ts +2 -1
  52. package/src/theme/system/color/avatar.ts +2 -12
  53. package/src/theme/system/color/button.ts +4 -20
  54. package/src/theme/system/color/input.ts +3 -11
  55. package/src/theme/system/color/selectable.ts +3 -14
  56. package/src/theme/system/shadow.ts +0 -6
  57. package/src/theme/system/styles.ts +0 -6
  58. package/src/theme/system/theme.ts +2 -0
  59. package/src/theme/system/v0/avatar.ts +1 -1
  60. package/src/theme/system/v0/color/button.ts +4 -4
  61. package/src/theme/system/v0/color/card.ts +2 -2
  62. package/src/theme/system/v0/color/input.ts +3 -3
  63. package/src/theme/system/v0/color/muted.ts +2 -2
  64. package/src/theme/system/v0/color/solid.ts +2 -2
  65. package/src/theme/versioning/themeColor_v0_v2.ts +2 -2
  66. package/src/theme/versioning/v2_v0.ts +2 -2
  67. package/src/theme/build/colorToken.ts +0 -39
@@ -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
@@ -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,17 @@
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.opacity !== undefined) {
13
+ key += `/${node.opacity}`
14
+ }
15
+
16
+ return key
17
+ }
@@ -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),
@@ -55,7 +55,7 @@ export function renderColorValue(str: string, options: RenderColorValueOptions):
55
55
  hex = mixThemeColor(hex, mixOptions)
56
56
  } catch (err) {
57
57
  // eslint-disable-next-line no-console
58
- console.log('could not blend', hex, mixOptions)
58
+ console.warn('could not blend', hex, mixOptions)
59
59
  throw err
60
60
  }
61
61