@sanity/ui 2.0.0-alpha.34 → 2.0.0-alpha.35

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 (163) hide show
  1. package/dist/index.cjs.mjs +4 -3
  2. package/dist/index.d.ts +29 -22
  3. package/dist/index.esm.js +397 -518
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +413 -534
  6. package/dist/index.js.map +1 -1
  7. package/dist/theme.cjs.mjs +10 -4
  8. package/dist/theme.d.ts +450 -187
  9. package/dist/theme.esm.js +2933 -2750
  10. package/dist/theme.esm.js.map +1 -1
  11. package/dist/theme.js +2942 -2753
  12. package/dist/theme.js.map +1 -1
  13. package/package.json +3 -3
  14. package/src/core/_compat.ts +7 -7
  15. package/src/core/components/dialog/dialog.tsx +5 -5
  16. package/src/core/components/dialog/styles.ts +4 -5
  17. package/src/core/components/hotkeys/hotkeys.tsx +4 -2
  18. package/src/core/components/menu/__workshop__/avatarMenu.tsx +50 -0
  19. package/src/core/components/menu/__workshop__/index.ts +5 -0
  20. package/src/core/components/menu/menuItem.tsx +7 -1
  21. package/src/core/components/skeleton/textSkeleton.tsx +12 -14
  22. package/src/core/components/tree/style.ts +14 -17
  23. package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +3 -3
  24. package/src/core/hooks/useMediaIndex/useMediaIndex.ts +2 -3
  25. package/src/core/primitives/_selectable/style.ts +18 -18
  26. package/src/core/primitives/avatar/avatar.tsx +3 -3
  27. package/src/core/primitives/avatar/avatarCounter.tsx +4 -4
  28. package/src/core/primitives/avatar/avatarStack.tsx +2 -2
  29. package/src/core/primitives/avatar/styles.ts +7 -8
  30. package/src/core/primitives/avatar/types.ts +2 -2
  31. package/src/core/primitives/badge/__workshop__/props.tsx +1 -1
  32. package/src/core/primitives/badge/__workshop__/tones.tsx +1 -1
  33. package/src/core/primitives/badge/badge.tsx +1 -1
  34. package/src/core/primitives/badge/styles.ts +5 -6
  35. package/src/core/primitives/button/button.tsx +3 -4
  36. package/src/core/primitives/button/styles.ts +22 -23
  37. package/src/core/primitives/card/__workshop__/selected.tsx +15 -15
  38. package/src/core/primitives/card/card.tsx +1 -1
  39. package/src/core/primitives/card/styles.ts +22 -22
  40. package/src/core/primitives/checkbox/styles.ts +21 -22
  41. package/src/core/primitives/code/styles.ts +4 -1
  42. package/src/core/primitives/container/styles.ts +2 -3
  43. package/src/core/primitives/heading/styles.ts +4 -2
  44. package/src/core/primitives/inline/styles.ts +6 -6
  45. package/src/core/primitives/kbd/kbd.tsx +7 -11
  46. package/src/core/primitives/label/styles.ts +4 -3
  47. package/src/core/primitives/popover/helpers.ts +3 -4
  48. package/src/core/primitives/popover/popover.tsx +8 -4
  49. package/src/core/primitives/popover/types.ts +1 -1
  50. package/src/core/primitives/radio/styles.ts +17 -19
  51. package/src/core/primitives/select/styles.ts +27 -32
  52. package/src/core/primitives/stack/styles.ts +2 -3
  53. package/src/core/primitives/switch/__workshop__/props.tsx +11 -31
  54. package/src/core/primitives/switch/styles.ts +18 -21
  55. package/src/core/primitives/text/__workshop__/colored.tsx +10 -10
  56. package/src/core/primitives/text/styles.ts +9 -4
  57. package/src/core/primitives/tooltip/tooltip.tsx +3 -3
  58. package/src/core/styles/border/borderStyle.ts +6 -11
  59. package/src/core/styles/box/boxStyle.ts +5 -9
  60. package/src/core/styles/card/_cardColorStyle.ts +99 -0
  61. package/src/core/styles/card/index.ts +1 -0
  62. package/src/core/styles/flex/flexItemStyle.ts +2 -3
  63. package/src/core/styles/flex/flexStyle.ts +6 -11
  64. package/src/core/styles/font/responsiveFont.ts +4 -4
  65. package/src/core/styles/font/textAlignStyle.ts +3 -3
  66. package/src/core/styles/grid/gridItemStyle.ts +7 -13
  67. package/src/core/styles/grid/gridStyle.ts +9 -17
  68. package/src/core/styles/helpers.ts +5 -3
  69. package/src/core/styles/input/responsiveInputPaddingStyle.ts +6 -6
  70. package/src/core/styles/input/textInputStyle.ts +36 -40
  71. package/src/core/styles/margin/marginsStyle.test.ts +2 -3
  72. package/src/core/styles/padding/paddingStyle.test.ts +2 -3
  73. package/src/core/styles/radius/radiusStyle.ts +2 -3
  74. package/src/core/styles/shadow/shadowStyle.ts +4 -5
  75. package/src/core/theme/__workshop__/build/Root.tsx +24 -20
  76. package/src/core/theme/__workshop__/build/story.tsx +22 -26
  77. package/src/core/theme/__workshop__/canvas.tsx +21 -40
  78. package/src/core/theme/theme.test.tsx +2 -35
  79. package/src/core/theme/themeColorProvider.tsx +2 -2
  80. package/src/core/theme/themeContext.ts +2 -2
  81. package/src/core/theme/themeProvider.tsx +25 -25
  82. package/src/core/theme/types.ts +3 -2
  83. package/src/core/theme/useRootTheme.ts +1 -9
  84. package/src/core/theme/useTheme.ts +8 -1
  85. package/src/core/types/card.ts +2 -2
  86. package/src/core/utils/arrow/arrow.tsx +3 -3
  87. package/src/core/utils/elementQuery/elementQuery.tsx +3 -3
  88. package/src/core/utils/virtualList/virtualList.tsx +2 -2
  89. package/src/theme/build/_deprecated/color/muted/createMuted.ts +2 -2
  90. package/src/theme/build/buildColorTheme.test.ts +14 -15
  91. package/src/theme/build/buildColorTheme.ts +239 -292
  92. package/src/theme/build/buildTheme.test.ts +9 -7
  93. package/src/theme/build/buildTheme.ts +12 -9
  94. package/src/theme/build/colorToken.ts +3 -1
  95. package/src/theme/build/lib/color-fns/contrastRatio.ts +1 -0
  96. package/src/theme/build/lib/isRecord.ts +3 -0
  97. package/src/theme/build/merge.ts +18 -13
  98. package/src/theme/build/renderColorTheme.ts +205 -213
  99. package/src/theme/build/renderColorValue.ts +15 -8
  100. package/src/theme/build/resolveColorTokens.ts +177 -198
  101. package/src/theme/build/theme.test.ts +27 -0
  102. package/src/theme/config/helpers.ts +16 -8
  103. package/src/theme/config/system.ts +46 -17
  104. package/src/theme/config/tokens/color/types.ts +55 -32
  105. package/src/theme/config/tokens/types.ts +11 -4
  106. package/src/theme/config/types.ts +5 -11
  107. package/src/theme/{build/defaults → defaults}/colorPalette.ts +1 -1
  108. package/src/theme/{build/defaults → defaults}/colorTokens.ts +189 -136
  109. package/src/theme/{build/defaults → defaults}/config.ts +14 -12
  110. package/src/theme/{build/defaults → defaults}/fonts.ts +6 -6
  111. package/src/theme/getScopedTheme.ts +81 -0
  112. package/src/theme/index.ts +9 -1
  113. package/src/theme/system/avatar.ts +1 -1
  114. package/src/theme/system/color/_constants.ts +11 -11
  115. package/src/theme/system/color/_system.ts +10 -71
  116. package/src/theme/system/color/avatar.ts +22 -10
  117. package/src/theme/system/color/badge.ts +18 -7
  118. package/src/theme/system/color/button.ts +17 -23
  119. package/src/theme/system/color/color.ts +34 -0
  120. package/src/theme/system/color/index.ts +3 -10
  121. package/src/theme/system/color/input.ts +13 -11
  122. package/src/theme/system/color/kbd.ts +3 -3
  123. package/src/theme/system/color/selectable.ts +13 -19
  124. package/src/theme/system/color/shadow.ts +7 -0
  125. package/src/theme/system/color/state.ts +37 -0
  126. package/src/theme/system/css.ts +9 -0
  127. package/src/theme/system/focusRing.ts +7 -0
  128. package/src/theme/system/index.ts +5 -1
  129. package/src/theme/system/input.ts +1 -1
  130. package/src/theme/system/layer.ts +1 -2
  131. package/src/theme/system/shadow.ts +1 -0
  132. package/src/theme/system/styles.ts +19 -0
  133. package/src/theme/system/theme.ts +97 -0
  134. package/src/theme/system/{color → v0/color}/_generic.ts +2 -1
  135. package/src/theme/system/v0/color/_system.ts +13 -0
  136. package/src/theme/system/{color → v0/color}/base.ts +2 -0
  137. package/src/theme/system/v0/color/button.ts +42 -0
  138. package/src/theme/system/{color → v0/color}/card.ts +2 -1
  139. package/src/theme/system/v0/color/color.ts +40 -0
  140. package/src/theme/system/v0/color/index.ts +11 -0
  141. package/src/theme/system/v0/color/input.ts +34 -0
  142. package/src/theme/system/{color/_deprecated → v0/color}/muted.ts +1 -1
  143. package/src/theme/system/v0/color/selectable.ts +31 -0
  144. package/src/theme/system/{color/_deprecated → v0/color}/solid.ts +1 -1
  145. package/src/theme/system/v0/color/spot.ts +13 -0
  146. package/src/theme/system/v0/index.ts +1 -0
  147. package/src/theme/versioning/getTheme_v2.ts +35 -0
  148. package/src/theme/versioning/index.ts +5 -0
  149. package/src/theme/versioning/is_v0.ts +6 -0
  150. package/src/theme/versioning/is_v2.ts +6 -0
  151. package/src/theme/versioning/themeColor_v0_v2.ts +217 -0
  152. package/src/theme/versioning/v0_v2.ts +70 -0
  153. package/src/theme/versioning/v2_v0.ts +128 -0
  154. package/src/core/styles/colorVars/colorVarsStyle.ts +0 -43
  155. package/src/core/styles/colorVars/index.ts +0 -1
  156. package/src/core/theme/defaults.ts +0 -7
  157. package/src/theme/system/_system.ts +0 -95
  158. package/src/theme/system/color/_deprecated/spot.ts +0 -13
  159. package/src/theme/themes/studio/config.ts +0 -69
  160. package/src/theme/themes/studio/fonts.ts +0 -219
  161. package/src/theme/themes/studio/index.ts +0 -1
  162. package/src/theme/themes/studio/studioTheme.test.ts +0 -27
  163. package/src/theme/themes/studio/studioTheme.ts +0 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.0.0-alpha.34",
3
+ "version": "2.0.0-alpha.35",
4
4
  "sideEffects": false,
5
5
  "types": "./dist/index.d.ts",
6
6
  "source": "./exports/index.ts",
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@floating-ui/react-dom": "^2.0.4",
75
- "@sanity/color": "3.0.0-beta.7",
75
+ "@sanity/color": "3.0.0-beta.8",
76
76
  "@sanity/icons": "^2.4.1",
77
77
  "csstype": "^3.1.2",
78
78
  "framer-motion": "^10.16.2",
@@ -88,7 +88,7 @@
88
88
  "@juggle/resize-observer": "^3.4.0",
89
89
  "@sanity/pkg-utils": "^2.4.8",
90
90
  "@sanity/semantic-release-preset": "^4.1.4",
91
- "@sanity/ui-workshop": "^2.0.2",
91
+ "@sanity/ui-workshop": "^2.0.3",
92
92
  "@storybook/addon-a11y": "^7.6.1",
93
93
  "@storybook/addon-docs": "^7.6.1",
94
94
  "@storybook/addon-essentials": "^7.6.1",
@@ -1,11 +1,11 @@
1
1
  // re-export for backwards compatibility
2
2
  export {
3
- COLOR_CONFIG_BASE_KEYS,
4
- COLOR_CONFIG_BASE_TONES,
3
+ COLOR_CONFIG_CARD_KEYS,
4
+ COLOR_CONFIG_CARD_TONES,
5
5
  COLOR_CONFIG_BLEND_KEYS,
6
6
  COLOR_CONFIG_STATE_KEYS,
7
7
  COLOR_CONFIG_STATE_TONES,
8
- THEME_COLOR_BASE_TONES,
8
+ THEME_COLOR_CARD_TONES,
9
9
  THEME_COLOR_BLEND_MODES,
10
10
  THEME_COLOR_BUTTON_MODES,
11
11
  THEME_COLOR_STATES,
@@ -35,13 +35,13 @@ export {
35
35
  rgba,
36
36
  rgbaToRGBA,
37
37
  screen,
38
- studioTheme,
38
+ defaultTheme as studioTheme,
39
39
  type BaseTheme,
40
40
  type BoxShadow,
41
41
  type CSSObject,
42
42
  type ColorBlendModeTokenValue,
43
- type ColorConfigBaseKey,
44
- type ColorConfigBaseTone,
43
+ type ColorConfigCardKey,
44
+ type ColorConfigCardTone,
45
45
  type ColorConfigBlendKey,
46
46
  type ColorConfigOpacityValue,
47
47
  type ColorConfigStateKey,
@@ -57,7 +57,7 @@ export {
57
57
  type ThemeColor,
58
58
  type ThemeColorBase,
59
59
  type ThemeColorBaseTokens,
60
- type ThemeColorBaseToneKey,
60
+ type ThemeColorCardToneKey,
61
61
  type ThemeColorBlendModeKey,
62
62
  type ThemeColorBuilderOpts,
63
63
  type ThemeColorButton,
@@ -12,7 +12,7 @@ import {useArrayProp, useClickOutside, useForwardedRef, useGlobalKeyDown} from '
12
12
  import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
13
13
  import {ResponsivePaddingProps, ResponsiveWidthProps} from '../../primitives/types'
14
14
  import {responsivePaddingStyle, ResponsivePaddingStyleProps} from '../../styles/internal'
15
- import {useTheme} from '../../theme'
15
+ import {useTheme_v2} from '../../theme'
16
16
  import {DialogPosition, Radius} from '../../types'
17
17
  import {Layer, LayerProps, Portal, useBoundaryElement, useLayer, usePortal} from '../../utils'
18
18
  import {
@@ -296,12 +296,12 @@ export const Dialog = forwardRef(function Dialog(
296
296
  ref: React.Ref<HTMLDivElement>,
297
297
  ) {
298
298
  const dialog = useDialog()
299
- const theme = useTheme()
299
+ const {layer} = useTheme_v2()
300
300
  const {
301
301
  __unstable_autoFocus: autoFocus = true,
302
302
  __unstable_hideCloseButton: hideCloseButton = false,
303
- cardRadius: cardRadiusProp = 3,
304
- cardShadow = 4,
303
+ cardRadius: cardRadiusProp = 4,
304
+ cardShadow = 3,
305
305
  children,
306
306
  contentRef,
307
307
  footer,
@@ -316,7 +316,7 @@ export const Dialog = forwardRef(function Dialog(
316
316
  position: positionProp = dialog.position || 'fixed',
317
317
  scheme,
318
318
  width: widthProp = 0,
319
- zOffset: zOffsetProp = dialog.zOffset || theme.sanity.layer?.dialog.zOffset,
319
+ zOffset: zOffsetProp = dialog.zOffset || layer.dialog.zOffset,
320
320
  animate = false,
321
321
  ...restProps
322
322
  } = props
@@ -1,4 +1,4 @@
1
- import {CSSObject} from '@sanity/ui/theme'
1
+ import {CSSObject, getTheme_v2} from '@sanity/ui/theme'
2
2
  import {css} from 'styled-components'
3
3
  import {_responsive, ThemeProps} from '../../styles'
4
4
  import {DialogPosition} from '../../types'
@@ -11,7 +11,7 @@ export interface ResponsiveDialogPositionStyleProps {
11
11
  }
12
12
 
13
13
  export function dialogStyle({theme}: ThemeProps): CSSObject {
14
- const color = theme.sanity.color.base
14
+ const {color} = getTheme_v2(theme)
15
15
 
16
16
  return {
17
17
  '&:not([hidden])': {
@@ -25,15 +25,14 @@ export function dialogStyle({theme}: ThemeProps): CSSObject {
25
25
  alignItems: 'center',
26
26
  justifyContent: 'center',
27
27
  outline: 'none',
28
- background: color.shadow.umbra,
28
+ background: color.backdrop,
29
29
  }
30
30
  }
31
31
 
32
32
  export function responsiveDialogPositionStyle(
33
33
  props: ResponsiveDialogPositionStyleProps & ThemeProps,
34
34
  ): CSSObject[] {
35
- const {theme} = props
36
- const {media} = theme.sanity
35
+ const {media} = getTheme_v2(props.theme)
37
36
 
38
37
  return _responsive(media, props.$position, (position) => ({'&&': {position}}))
39
38
  }
@@ -16,10 +16,12 @@ export interface HotkeysProps {
16
16
  }
17
17
 
18
18
  const Root = styled.kbd`
19
+ font: inherit;
20
+ padding: 1px;
21
+
19
22
  &:not([hidden]) {
20
23
  display: block;
21
24
  }
22
- font: inherit;
23
25
  `
24
26
 
25
27
  const Key = styled(KBD)`
@@ -37,7 +39,7 @@ export const Hotkeys = forwardRef(function Hotkeys(
37
39
  props: HotkeysProps & Omit<React.HTMLProps<HTMLElement>, 'as' | 'ref' | 'size'>,
38
40
  ref: React.Ref<HTMLElement>,
39
41
  ) {
40
- const {fontSize, keys, padding, radius, space: spaceProp = 1, ...restProps} = props
42
+ const {fontSize, keys, padding, radius, space: spaceProp = 0.5, ...restProps} = props
41
43
  const space = useArrayProp(spaceProp)
42
44
 
43
45
  if (!keys || keys.length === 0) {
@@ -0,0 +1,50 @@
1
+ import {UsersIcon} from '@sanity/icons'
2
+ import {Avatar, Badge, Box, Button, Flex, Text} from '../../../primitives'
3
+ import {Hotkeys} from '../../hotkeys'
4
+ import {Menu} from '../menu'
5
+ import {MenuButton} from '../menuButton'
6
+ import {MenuItem} from '../menuItem'
7
+
8
+ export default function AvatarMenuStory() {
9
+ return (
10
+ <Flex align="center" height="fill" justify="center">
11
+ <MenuButton
12
+ button={<Button icon={UsersIcon} />}
13
+ id="avatar-menu"
14
+ menu={
15
+ <Menu>
16
+ <MenuItem padding={0}>
17
+ <Flex align="center" padding={1}>
18
+ <Box flex="none">
19
+ <Avatar color="purple" initials="JS" />
20
+ </Box>
21
+ <Box flex={1} padding={2}>
22
+ <Text size={1}>Jane Smith</Text>
23
+ </Box>
24
+ <Box padding={1}>
25
+ <Badge>Me</Badge>
26
+ </Box>
27
+ <Box padding={1}>
28
+ <Hotkeys keys={['Cmd', '1']} />
29
+ </Box>
30
+ </Flex>
31
+ </MenuItem>
32
+ <MenuItem padding={0}>
33
+ <Flex align="center" padding={1}>
34
+ <Box flex="none">
35
+ <Avatar color="magenta" initials="JS" />
36
+ </Box>
37
+ <Box flex={1} padding={2}>
38
+ <Text size={1}>John Doe</Text>
39
+ </Box>
40
+ <Box padding={1}>
41
+ <Hotkeys keys={['Cmd', '2']} />
42
+ </Box>
43
+ </Flex>
44
+ </MenuItem>
45
+ </Menu>
46
+ }
47
+ />
48
+ </Flex>
49
+ )
50
+ }
@@ -75,5 +75,10 @@ export default defineScope({
75
75
  title: 'Menu with shouldFocus',
76
76
  component: lazy(() => import('./shouldFocus')),
77
77
  },
78
+ {
79
+ name: 'avatar',
80
+ title: 'Avatar menu',
81
+ component: lazy(() => import('./avatarMenu')),
82
+ },
78
83
  ],
79
84
  })
@@ -103,6 +103,8 @@ export const MenuItem = forwardRef(function MenuItem(
103
103
  [padding, paddingX, paddingY, paddingTop, paddingRight, paddingBottom, paddingLeft],
104
104
  )
105
105
 
106
+ const hotkeysFontSize = useArrayProp(fontSize).map((s) => s - 1)
107
+
106
108
  const setRef = useCallback(
107
109
  (el: HTMLDivElement | null) => {
108
110
  ref.current = el
@@ -151,7 +153,11 @@ export const MenuItem = forwardRef(function MenuItem(
151
153
  )}
152
154
 
153
155
  {hotkeys && (
154
- <Hotkeys fontSize={fontSize} keys={hotkeys} style={{marginTop: -4, marginBottom: -4}} />
156
+ <Hotkeys
157
+ fontSize={hotkeysFontSize}
158
+ keys={hotkeys}
159
+ style={{marginTop: -4, marginBottom: -4}}
160
+ />
155
161
  )}
156
162
 
157
163
  {iconRight && (
@@ -1,24 +1,22 @@
1
- import {Theme, ThemeFontKey} from '@sanity/ui/theme'
1
+ import {ThemeFontKey, getTheme_v2} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import styled from 'styled-components'
4
4
  import {useArrayProp} from '../../hooks'
5
- import {_responsive} from '../../styles'
5
+ import {ThemeProps, _responsive} from '../../styles'
6
6
  import {Skeleton, SkeletonProps} from './skeleton'
7
7
 
8
- const Root = styled(Skeleton)<{$size: number[]; $style: ThemeFontKey}>(({
9
- $size,
10
- $style,
11
- theme,
12
- }: {
13
- $size: number[]
14
- $style: ThemeFontKey
15
- theme: Theme
16
- }) => {
17
- const {media} = theme.sanity
18
- const font = theme.sanity.fonts[$style]
8
+ const Root = styled(Skeleton)<{$size: number[]; $style: ThemeFontKey}>((
9
+ props: {
10
+ $size: number[]
11
+ $style: ThemeFontKey
12
+ } & ThemeProps,
13
+ ) => {
14
+ const {$size, $style} = props
15
+ const {font, media} = getTheme_v2(props.theme)
16
+ const fontStyle = font[$style]
19
17
 
20
18
  const styles = _responsive(media, $size, (sizeIndex) => {
21
- const fontSize = font.sizes[sizeIndex]
19
+ const fontSize = fontStyle.sizes[sizeIndex]
22
20
  const capHeight = fontSize.lineHeight - fontSize.ascenderHeight - fontSize.descenderHeight
23
21
 
24
22
  return {height: capHeight}
@@ -1,6 +1,7 @@
1
+ import {getTheme_v2} from '@sanity/ui/theme'
1
2
  import {css} from 'styled-components'
2
3
  import {rem, ThemeProps} from '../../styles'
3
- import {_colorVarsStyle} from '../../styles/colorVars'
4
+ import {_cardColorStyle} from '../../styles/card'
4
5
 
5
6
  export function treeItemRootStyle(): ReturnType<typeof css> {
6
7
  return css`
@@ -36,51 +37,47 @@ export function treeItemRootStyle(): ReturnType<typeof css> {
36
37
  }
37
38
 
38
39
  export function treeItemRootColorStyle(props: ThemeProps): ReturnType<typeof css> {
39
- const {theme} = props
40
40
  const $tone = 'default'
41
- const {base, muted, selectable} = theme.sanity.color
42
- // @todo: remove use of `muted` here
43
- const tone = selectable ? selectable[$tone] || selectable.default : muted[$tone] || muted.default
41
+ const {color} = getTheme_v2(props.theme)
42
+ const tone = color.selectable[$tone]
44
43
 
45
44
  return css`
46
- /* <div role="none"><a data-ui="TreeItem__box" role="treeitem" tabIndex="0"></div> */
47
45
  &[role='none'] {
48
46
  & > [role='treeitem'] {
49
- ${_colorVarsStyle(base, tone.enabled)}
47
+ ${_cardColorStyle(color, tone.enabled)}
50
48
  }
51
49
 
52
50
  &[data-selected] > [role='treeitem'] {
53
- ${_colorVarsStyle(base, tone.pressed)}
51
+ ${_cardColorStyle(color, tone.pressed)}
54
52
  }
55
53
 
56
54
  @media (hover: hover) {
57
55
  &:not([data-selected]) > [role='treeitem']:not(:focus):hover {
58
- ${_colorVarsStyle(base, tone.hovered)}
56
+ ${_cardColorStyle(color, tone.hovered)}
59
57
  }
60
58
 
61
59
  & > [role='treeitem']:focus {
62
- ${_colorVarsStyle(base, tone.selected)}
60
+ ${_cardColorStyle(color, tone.selected)}
63
61
  }
64
62
  }
65
63
  }
66
64
 
67
- /* <div role="treeitem" tabIndex="0"><div data-ui="TreeItem__box"></div> */
68
65
  &[role='treeitem'] {
69
66
  & > [data-ui='TreeItem__box'] {
70
- ${_colorVarsStyle(base, tone.enabled)}
67
+ ${_cardColorStyle(color, tone.enabled)}
71
68
  }
72
69
 
73
70
  &[data-selected] > [data-ui='TreeItem__box'] {
74
- ${_colorVarsStyle(base, tone.pressed)}
71
+ ${_cardColorStyle(color, tone.pressed)}
75
72
  }
76
73
 
77
74
  @media (hover: hover) {
78
75
  &:not([data-selected]):not(:focus) > [data-ui='TreeItem__box']:hover {
79
- ${_colorVarsStyle(base, tone.hovered)}
76
+ ${_cardColorStyle(color, tone.hovered)}
80
77
  }
81
78
 
82
79
  &:focus > [data-ui='TreeItem__box'] {
83
- ${_colorVarsStyle(base, tone.selected)}
80
+ ${_cardColorStyle(color, tone.selected)}
84
81
  }
85
82
  }
86
83
  }
@@ -94,8 +91,8 @@ export interface TreeItemBoxStyleProps {
94
91
  export function treeItemBoxStyle(
95
92
  props: TreeItemBoxStyleProps & ThemeProps,
96
93
  ): ReturnType<typeof css> {
97
- const {$level, theme} = props
98
- const {space} = theme.sanity
94
+ const {$level} = props
95
+ const {space} = getTheme_v2(props.theme)
99
96
 
100
97
  return css`
101
98
  padding-left: ${rem(space[2] * $level)};
@@ -1,5 +1,5 @@
1
1
  /** @jest-environment node */
2
- import {studioTheme} from '@sanity/ui/theme'
2
+ import {defaultTheme} from '@sanity/ui/theme'
3
3
  import {renderToString, renderToStaticMarkup} from 'react-dom/server'
4
4
  import {ThemeProvider} from '../../theme'
5
5
  import {useMediaIndex} from './useMediaIndex'
@@ -14,7 +14,7 @@ describe('useMediaIndex', () => {
14
14
  it(`SSR to static markup returns 0`, () => {
15
15
  expect(
16
16
  renderToStaticMarkup(
17
- <ThemeProvider theme={studioTheme}>
17
+ <ThemeProvider theme={defaultTheme}>
18
18
  <Log />
19
19
  </ThemeProvider>,
20
20
  ),
@@ -23,7 +23,7 @@ describe('useMediaIndex', () => {
23
23
  it(`SSR to markup for hydration doesn't throw`, () => {
24
24
  expect(
25
25
  renderToString(
26
- <ThemeProvider theme={studioTheme}>
26
+ <ThemeProvider theme={defaultTheme}>
27
27
  <Log />
28
28
  </ThemeProvider>,
29
29
  ),
@@ -1,5 +1,5 @@
1
1
  import {useSyncExternalStore} from 'react'
2
- import {useTheme} from '../../theme'
2
+ import {useTheme_v2} from '../../theme'
3
3
 
4
4
  /**
5
5
  * @internal
@@ -96,8 +96,7 @@ function getServerSnapshot() {
96
96
  * @beta
97
97
  */
98
98
  export function useMediaIndex(): number {
99
- const theme = useTheme()
100
- const {media} = theme.sanity
99
+ const {media} = useTheme_v2()
101
100
 
102
101
  let store = MEDIA_STORE_CACHE.get(media)
103
102
 
@@ -1,7 +1,8 @@
1
+ import {getTheme_v2} from '@sanity/ui/theme'
1
2
  import {css} from 'styled-components'
2
3
  import {ThemeProps} from '../../styles'
3
- import {_colorVarsStyle} from '../../styles/colorVars'
4
- import {SelectableTone} from '../../types/selectable'
4
+ import {_cardColorStyle} from '../../styles/card'
5
+ import {SelectableTone} from '../../types'
5
6
 
6
7
  /**
7
8
  * @internal
@@ -37,13 +38,12 @@ export function selectableBaseStyle(): ReturnType<typeof css> {
37
38
  export function selectableColorStyle(
38
39
  props: SelectableStyleProps & ThemeProps,
39
40
  ): ReturnType<typeof css> {
40
- const {$tone, theme} = props
41
- const {base, muted, selectable} = theme.sanity.color
42
- // @todo: remove use of `muted` here
43
- const tone = selectable ? selectable[$tone] || selectable.default : muted[$tone] || muted.default
41
+ const {$tone} = props
42
+ const {color, style} = getTheme_v2(props.theme)
43
+ const tone = color.selectable[$tone]
44
44
 
45
45
  return css`
46
- ${_colorVarsStyle(base, tone.enabled)}
46
+ ${_cardColorStyle(color, tone.enabled)}
47
47
 
48
48
  background-color: var(--card-bg-color);
49
49
  color: var(--card-fg-color);
@@ -52,28 +52,28 @@ export function selectableColorStyle(
52
52
  /* &:is(button) */
53
53
  &[data-as='button'] {
54
54
  &:disabled {
55
- ${_colorVarsStyle(base, tone.disabled)}
55
+ ${_cardColorStyle(color, tone.disabled)}
56
56
  }
57
57
 
58
58
  &:not(:disabled) {
59
59
  &[aria-pressed='true'] {
60
- ${_colorVarsStyle(base, tone.pressed)}
60
+ ${_cardColorStyle(color, tone.pressed)}
61
61
  }
62
62
 
63
63
  &[data-selected],
64
64
  &[aria-selected='true'] > & {
65
- ${_colorVarsStyle(base, tone.selected)}
65
+ ${_cardColorStyle(color, tone.selected)}
66
66
  }
67
67
 
68
68
  @media (hover: hover) {
69
69
  &:not([data-selected]) {
70
70
  &[data-hovered],
71
71
  &:hover {
72
- ${_colorVarsStyle(base, tone.hovered)}
72
+ ${_cardColorStyle(color, tone.hovered)}
73
73
  }
74
74
 
75
75
  &:active {
76
- ${_colorVarsStyle(base, tone.pressed)}
76
+ ${_cardColorStyle(color, tone.pressed)}
77
77
  }
78
78
  }
79
79
  }
@@ -83,32 +83,32 @@ export function selectableColorStyle(
83
83
  /* &:is(a) */
84
84
  &[data-as='a'] {
85
85
  &[data-disabled] {
86
- ${_colorVarsStyle(base, tone.disabled)}
86
+ ${_cardColorStyle(color, tone.disabled)}
87
87
  }
88
88
 
89
89
  &:not([data-disabled]) {
90
90
  &[data-pressed] {
91
- ${_colorVarsStyle(base, tone.pressed)}
91
+ ${_cardColorStyle(color, tone.pressed)}
92
92
  }
93
93
 
94
94
  &[data-selected] {
95
- ${_colorVarsStyle(base, tone.selected)}
95
+ ${_cardColorStyle(color, tone.selected)}
96
96
  }
97
97
 
98
98
  @media (hover: hover) {
99
99
  &:not([data-selected]) {
100
100
  &[data-hovered],
101
101
  &:hover {
102
- ${_colorVarsStyle(base, tone.hovered)}
102
+ ${_cardColorStyle(color, tone.hovered)}
103
103
  }
104
104
  &:active {
105
- ${_colorVarsStyle(base, tone.pressed)}
105
+ ${_cardColorStyle(color, tone.pressed)}
106
106
  }
107
107
  }
108
108
  }
109
109
  }
110
110
  }
111
111
 
112
- ${theme.sanity.styles?.card?.root}
112
+ ${style?.card?.root}
113
113
  `
114
114
  }
@@ -3,7 +3,7 @@ import {forwardRef, useCallback, useEffect, useId, useMemo, useState} from 'reac
3
3
  import ReactIs from 'react-is'
4
4
  import styled from 'styled-components'
5
5
  import {useArrayProp} from '../../hooks'
6
- import {useTheme} from '../../theme'
6
+ import {useTheme_v2} from '../../theme'
7
7
  import {AvatarPosition, AvatarSize, AvatarStatus} from '../../types'
8
8
  import {Label} from '../label'
9
9
  import {avatarStyle, responsiveAvatarSizeStyle} from './styles'
@@ -74,10 +74,10 @@ export const Avatar = forwardRef(function Avatar(
74
74
  } = props
75
75
  const as = ReactIs.isValidElementType(asProp) ? asProp : 'div'
76
76
  const size = useArrayProp(sizeProp)
77
- const theme = useTheme()
77
+ const {avatar} = useTheme_v2()
78
78
 
79
79
  // @todo: remove this
80
- const avatarSize = theme.sanity.avatar.sizes[size[0]] || theme.sanity.avatar.sizes[0]
80
+ const avatarSize = avatar.sizes[size[0]] || avatar.sizes[0]
81
81
  const _sizeRem = avatarSize.size
82
82
  const _radius = _sizeRem / 2
83
83
 
@@ -1,3 +1,4 @@
1
+ import {getTheme_v2} from '@sanity/ui/theme'
1
2
  import {forwardRef, useMemo} from 'react'
2
3
  import styled, {css} from 'styled-components'
3
4
  import {EMPTY_RECORD} from '../../constants'
@@ -7,8 +8,7 @@ import {AvatarSize} from '../../types'
7
8
  import {Text} from '../text'
8
9
 
9
10
  function _responsiveAvatarCounterSizeStyle(props: {$size: AvatarSize[]} & ThemeProps) {
10
- const {theme} = props
11
- const {avatar, media} = theme.sanity
11
+ const {avatar, media} = getTheme_v2(props.theme)
12
12
 
13
13
  return _responsive(media, props.$size, (size) => {
14
14
  const avatarSize = avatar.sizes[size]
@@ -24,7 +24,7 @@ function _responsiveAvatarCounterSizeStyle(props: {$size: AvatarSize[]} & ThemeP
24
24
  }
25
25
 
26
26
  function _avatarCounterBaseStyle(props: ThemeProps) {
27
- const {theme} = props
27
+ const {space} = getTheme_v2(props.theme)
28
28
 
29
29
  return css`
30
30
  align-items: center;
@@ -37,7 +37,7 @@ function _avatarCounterBaseStyle(props: ThemeProps) {
37
37
  box-shadow:
38
38
  0 0 0 1px var(--card-bg-color),
39
39
  inset 0 0 0 1px var(--card-hairline-hard-color);
40
- padding: 0 ${rem(theme.sanity.space[2])};
40
+ padding: 0 ${rem(space[2])};
41
41
 
42
42
  &:not([hidden]) {
43
43
  display: flex;
@@ -1,3 +1,4 @@
1
+ import {getTheme_v2} from '@sanity/ui/theme'
1
2
  import {cloneElement, forwardRef} from 'react'
2
3
  import styled, {css} from 'styled-components'
3
4
  import {EMPTY_RECORD} from '../../constants'
@@ -24,8 +25,7 @@ function avatarStackStyle() {
24
25
  }
25
26
 
26
27
  function responsiveAvatarStackSizeStyle(props: {$size: AvatarSize[]} & ThemeProps) {
27
- const {theme} = props
28
- const {avatar, media} = theme.sanity
28
+ const {avatar, media} = getTheme_v2(props.theme)
29
29
 
30
30
  return _responsive(media, props.$size, (size) => {
31
31
  const avatarSize = avatar.sizes[size]
@@ -1,4 +1,4 @@
1
- import {CSSObject} from '@sanity/ui/theme'
1
+ import {CSSObject, getTheme_v2} from '@sanity/ui/theme'
2
2
  import {rem, _responsive, ThemeProps} from '../../styles'
3
3
  import {focusRingStyle} from '../../styles/internal'
4
4
  import {AvatarRootStyleProps, ResponsiveAvatarSizeStyleProps} from './types'
@@ -57,12 +57,12 @@ function avatarArrowStyle(): CSSObject {
57
57
  }
58
58
 
59
59
  export function avatarRootStyle(props: AvatarRootStyleProps & ThemeProps): CSSObject {
60
- const {$color, theme} = props
61
- const {focusRing} = theme.sanity.avatar
60
+ const {$color} = props
61
+ const {avatar} = getTheme_v2(props.theme)
62
62
 
63
63
  return {
64
- '--avatar-bg-color': theme.sanity.color.avatar?.[$color]?.bg || theme.sanity.color.spot[$color],
65
- '--avatar-fg-color': theme.sanity.color.avatar?.[$color]?.fg || 'var(--card-bg-color)',
64
+ '--avatar-bg-color': `var(--card-avatar-${$color}-bg-color)`,
65
+ '--avatar-fg-color': `var(--card-avatar-${$color}-fg-color)`,
66
66
 
67
67
  backgroundColor: 'var(--avatar-bg-color)',
68
68
  position: 'relative',
@@ -94,7 +94,7 @@ export function avatarRootStyle(props: AvatarRootStyleProps & ThemeProps): CSSOb
94
94
 
95
95
  // @ts-expect-error -- TODO wait for CSSObject types to be fixed in `styled-components` itself
96
96
  '&:focus': {
97
- boxShadow: focusRingStyle({focusRing}),
97
+ boxShadow: focusRingStyle({focusRing: avatar.focusRing}),
98
98
  },
99
99
 
100
100
  '&:focus:not(:focus-visible)': {
@@ -107,8 +107,7 @@ export function avatarRootStyle(props: AvatarRootStyleProps & ThemeProps): CSSOb
107
107
  export function responsiveAvatarSizeStyle(
108
108
  props: ResponsiveAvatarSizeStyleProps & ThemeProps,
109
109
  ): CSSObject[] {
110
- const {theme} = props
111
- const {avatar, media} = theme.sanity
110
+ const {avatar, media} = getTheme_v2(props.theme)
112
111
 
113
112
  return _responsive(media, props.$size, (size) => {
114
113
  const avatarSize = avatar.sizes[size] || avatar.sizes[0]
@@ -1,11 +1,11 @@
1
- import {ThemeColorSpotKey} from '@sanity/ui/theme'
1
+ import {ThemeColorAvatarColorKey} from '@sanity/ui/theme'
2
2
  import {AvatarSize} from '../../types'
3
3
 
4
4
  /**
5
5
  * @internal
6
6
  */
7
7
  export interface AvatarRootStyleProps {
8
- $color: ThemeColorSpotKey
8
+ $color: ThemeColorAvatarColorKey
9
9
  }
10
10
 
11
11
  /**
@@ -7,7 +7,7 @@ import {
7
7
  } from '../../../__workshop__/constants'
8
8
 
9
9
  export default function PropsStory() {
10
- const mode = useSelect('Mode', WORKSHOP_BADGE_MODE_OPTIONS, 'default', 'Props')
10
+ const mode = useSelect('Mode (deprecated)', WORKSHOP_BADGE_MODE_OPTIONS, 'default', 'Props')
11
11
  const paddingX = useSelect('Padding X', WORKSHOP_SPACE_OPTIONS, 1, 'Props')
12
12
  const paddingY = useSelect('Padding Y', WORKSHOP_SPACE_OPTIONS, 1, 'Props')
13
13
  const tone = useSelect('Tone', WORKSHOP_BADGE_TONE_OPTIONS, 'default', 'Props')
@@ -3,7 +3,7 @@ import {useSelect} from '@sanity/ui-workshop'
3
3
  import {WORKSHOP_BADGE_MODE_OPTIONS} from '../../../__workshop__/constants'
4
4
 
5
5
  export default function Tones() {
6
- const mode = useSelect('Mode', WORKSHOP_BADGE_MODE_OPTIONS, 'default', 'Props')
6
+ const mode = useSelect('Mode (deprecated)', WORKSHOP_BADGE_MODE_OPTIONS, 'default', 'Props')
7
7
 
8
8
  return (
9
9
  <Flex align="center" height="fill" justify="center" padding={4} sizing="border">