@sanity/ui 2.0.0-alpha.33 → 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 -515
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +413 -531
  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 +8 -3
  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
@@ -22,7 +22,7 @@ import {
22
22
  useRef,
23
23
  } from 'react'
24
24
  import {useForwardedRef, useArrayProp, useElementSize, useMediaIndex} from '../../hooks'
25
- import {useTheme} from '../../theme'
25
+ import {useTheme_v2} from '../../theme'
26
26
  import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
27
27
  import {LayerProps, LayerProvider, Portal, useBoundaryElement} from '../../utils'
28
28
  import {ResponsiveRadiusProps, ResponsiveShadowProps} from '../types'
@@ -85,7 +85,7 @@ export const Popover = memo(
85
85
  Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'children' | 'content' | 'width'>,
86
86
  ref: React.ForwardedRef<HTMLDivElement>,
87
87
  ): React.ReactElement {
88
- const theme = useTheme()
88
+ const {container, layer} = useTheme_v2()
89
89
  const boundaryElementContext = useBoundaryElement()
90
90
 
91
91
  const {
@@ -115,7 +115,7 @@ export const Popover = memo(
115
115
  shadow: shadowProp = 3,
116
116
  tone = 'inherit',
117
117
  width: widthProp = 'auto',
118
- zOffset: zOffsetProp = theme.sanity.layer?.popover.zOffset,
118
+ zOffset: zOffsetProp = layer.popover.zOffset,
119
119
  updateRef,
120
120
  ...restProps
121
121
  } = props
@@ -135,7 +135,11 @@ export const Popover = memo(
135
135
  // Update width when
136
136
  // - media index changes
137
137
  // - `width` property changes
138
- const width = calcCurrentWidth({mediaIndex, theme, width: widthArrayProp})
138
+ const width = calcCurrentWidth({
139
+ container,
140
+ mediaIndex,
141
+ width: widthArrayProp,
142
+ })
139
143
  const widthRef = useRef(width)
140
144
 
141
145
  useEffect(() => {
@@ -2,5 +2,5 @@
2
2
  export type PopoverUpdateCallback = () => void
3
3
 
4
4
  /** @public */
5
- // TODO: remove `auto` from PopoverWidth
5
+ // todo: remove `auto` from PopoverWidth
6
6
  export type PopoverWidth = number | 'auto'
@@ -1,3 +1,4 @@
1
+ import {getTheme_v2} from '@sanity/ui/theme'
1
2
  import {css} from 'styled-components'
2
3
  import {rem, ThemeProps} from '../../styles'
3
4
  import {focusRingBorderStyle, focusRingStyle} from '../../styles/internal'
@@ -17,10 +18,7 @@ export function radioBaseStyle(): ReturnType<typeof css> {
17
18
  }
18
19
 
19
20
  export function inputElementStyle(props: ThemeProps): ReturnType<typeof css> {
20
- const {theme} = props
21
- const {input} = theme.sanity
22
- const {focusRing} = input.radio
23
- const color = theme.sanity.color.input
21
+ const {color, input} = getTheme_v2(props.theme)
24
22
  const dist = (input.radio.size - input.radio.markSize) / 2
25
23
 
26
24
  return css`
@@ -45,9 +43,9 @@ export function inputElementStyle(props: ThemeProps): ReturnType<typeof css> {
45
43
  height: ${rem(input.radio.size)};
46
44
  width: ${rem(input.radio.size)};
47
45
  border-radius: ${rem(input.radio.size / 2)};
48
- background: ${color.default.enabled.bg};
46
+ background: ${color.input.default.enabled.bg};
49
47
  box-shadow: ${focusRingBorderStyle({
50
- color: color.default.enabled.border,
48
+ color: color.input.default.enabled.border,
51
49
  width: input.border.width,
52
50
  })};
53
51
 
@@ -59,7 +57,7 @@ export function inputElementStyle(props: ThemeProps): ReturnType<typeof css> {
59
57
  height: ${rem(input.radio.markSize)};
60
58
  width: ${rem(input.radio.markSize)};
61
59
  border-radius: ${rem(input.radio.markSize / 2)};
62
- background: ${color.default.enabled.fg};
60
+ background: ${color.input.default.enabled.fg};
63
61
  opacity: 0;
64
62
  }
65
63
  }
@@ -67,14 +65,14 @@ export function inputElementStyle(props: ThemeProps): ReturnType<typeof css> {
67
65
  /* focused */
68
66
  &:not(:disabled):focus + span {
69
67
  box-shadow: ${focusRingStyle({
70
- border: {width: input.border.width, color: color.default.enabled.border},
71
- focusRing,
68
+ border: {width: input.border.width, color: color.input.default.enabled.border},
69
+ focusRing: input.radio.focusRing,
72
70
  })};
73
71
  }
74
72
 
75
73
  &:not(:disabled):focus:not(:focus-visible) + span {
76
74
  box-shadow: ${focusRingBorderStyle({
77
- color: color.default.enabled.border,
75
+ color: color.input.default.enabled.border,
78
76
  width: input.border.width,
79
77
  })};
80
78
  }
@@ -85,33 +83,33 @@ export function inputElementStyle(props: ThemeProps): ReturnType<typeof css> {
85
83
 
86
84
  /* customValidity */
87
85
  &[data-error] + span {
88
- background-color: ${color.invalid.enabled.border};
86
+ background-color: ${color.input.invalid.enabled.border};
89
87
  box-shadow: ${focusRingBorderStyle({
90
88
  width: input.border.width,
91
- color: color.invalid.enabled.bg2,
89
+ color: color.input.invalid.enabled.muted.bg,
92
90
  })};
93
91
  &::after {
94
- background: ${color.invalid.enabled.bg2};
92
+ background: ${color.input.invalid.enabled.muted.bg};
95
93
  }
96
94
  }
97
95
 
98
96
  /* read only */
99
97
  &[data-read-only] + span {
100
- box-shadow: 0 0 0 1px ${color.default.readOnly.border};
101
- background: ${color.default.readOnly.bg};
98
+ box-shadow: 0 0 0 1px ${color.input.default.readOnly.border};
99
+ background: ${color.input.default.readOnly.bg};
102
100
 
103
101
  &::after {
104
- background: ${color.default.readOnly.border};
102
+ background: ${color.input.default.readOnly.border};
105
103
  }
106
104
  }
107
105
 
108
106
  /* disabled */
109
107
  &:not([data-read-only]):disabled + span {
110
- box-shadow: 0 0 0 1px ${color.default.disabled.border};
111
- background: ${color.default.disabled.bg};
108
+ box-shadow: 0 0 0 1px ${color.input.default.disabled.border};
109
+ background: ${color.input.default.disabled.bg};
112
110
 
113
111
  &::after {
114
- background: ${color.default.disabled.border};
112
+ background: ${color.input.default.disabled.border};
115
113
  }
116
114
  }
117
115
  `
@@ -1,4 +1,4 @@
1
- import {ThemeFontSize} from '@sanity/ui/theme'
1
+ import {ThemeFontSize, getTheme_v2} from '@sanity/ui/theme'
2
2
  import {CSSObject} from '@sanity/ui/theme'
3
3
  import {css} from 'styled-components'
4
4
  import {rem, _responsive, ThemeProps} from '../../styles'
@@ -24,14 +24,13 @@ function rootStyle(): ReturnType<typeof css> {
24
24
  }
25
25
 
26
26
  function inputBaseStyle(props: ThemeProps): ReturnType<typeof css> {
27
- const {theme} = props
28
- const font = theme.sanity.fonts.text
27
+ const {font} = getTheme_v2(props.theme)
29
28
 
30
29
  return css`
31
30
  -webkit-font-smoothing: antialiased;
32
31
  appearance: none;
33
32
  border: 0;
34
- font-family: ${font.family};
33
+ font-family: ${font.text.family};
35
34
  color: inherit;
36
35
  width: 100%;
37
36
  outline: none;
@@ -44,27 +43,24 @@ function inputBaseStyle(props: ThemeProps): ReturnType<typeof css> {
44
43
  }
45
44
 
46
45
  function inputColorStyle(props: ThemeProps) {
47
- const {theme} = props
48
- const {input} = theme.sanity
49
- const {focusRing} = input.select
50
- const color = theme.sanity.color.input
46
+ const {color, input} = getTheme_v2(props.theme)
51
47
 
52
48
  return css`
53
49
  /* enabled */
54
- background-color: ${color.default.enabled.bg};
55
- color: ${color.default.enabled.fg};
50
+ background-color: ${color.input.default.enabled.bg};
51
+ color: ${color.input.default.enabled.fg};
56
52
  box-shadow: ${focusRingBorderStyle({
57
- color: color.default.enabled.border,
53
+ color: color.input.default.enabled.border,
58
54
  width: input.border.width,
59
55
  })};
60
56
 
61
57
  /* hovered */
62
58
  @media (hover: hover) {
63
59
  &:not(:disabled):hover {
64
- background-color: ${color.default.hovered.bg};
65
- color: ${color.default.hovered.fg};
60
+ background-color: ${color.input.default.hovered.bg};
61
+ color: ${color.input.default.hovered.fg};
66
62
  box-shadow: ${focusRingBorderStyle({
67
- color: color.default.hovered.border,
63
+ color: color.input.default.hovered.border,
68
64
  width: input.border.width,
69
65
  })};
70
66
  }
@@ -73,27 +69,27 @@ function inputColorStyle(props: ThemeProps) {
73
69
  /* focused */
74
70
  &:not(:disabled):focus {
75
71
  box-shadow: ${focusRingStyle({
76
- border: {width: input.border.width, color: color.default.enabled.border},
77
- focusRing,
72
+ border: {width: input.border.width, color: color.input.default.enabled.border},
73
+ focusRing: input.select.focusRing,
78
74
  })};
79
75
  }
80
76
 
81
77
  /* read-only */
82
78
  &[data-read-only] {
83
- background-color: ${color.default.readOnly.bg};
84
- color: ${color.default.readOnly.fg};
79
+ background-color: ${color.input.default.readOnly.bg};
80
+ color: ${color.input.default.readOnly.fg};
85
81
  box-shadow: ${focusRingBorderStyle({
86
- color: color.default.readOnly.border,
82
+ color: color.input.default.readOnly.border,
87
83
  width: input.border.width,
88
84
  })};
89
85
  }
90
86
 
91
87
  /* disabled */
92
88
  &:not([data-read-only]):disabled {
93
- background-color: ${color.default.disabled.bg};
94
- color: ${color.default.disabled.fg};
89
+ background-color: ${color.input.default.disabled.bg};
90
+ color: ${color.input.default.disabled.fg};
95
91
  box-shadow: ${focusRingBorderStyle({
96
- color: color.default.disabled.border,
92
+ color: color.input.default.disabled.border,
97
93
  width: input.border.width,
98
94
  })};
99
95
  }
@@ -105,11 +101,11 @@ function textSize(size: ThemeFontSize) {
105
101
  }
106
102
 
107
103
  function inputTextSizeStyle(props: {$fontSize: number[]} & ThemeProps) {
108
- const {theme, $fontSize} = props
109
- const {sizes} = theme.sanity.fonts.text
104
+ const {$fontSize} = props
105
+ const {font, media} = getTheme_v2(props.theme)
110
106
 
111
- return _responsive(theme.sanity.media, $fontSize, (sizeIndex) =>
112
- textSize(sizes[sizeIndex] || sizes[2]),
107
+ return _responsive(media, $fontSize, (sizeIndex) =>
108
+ textSize(font.text.sizes[sizeIndex] || font.text.sizes[2]),
113
109
  )
114
110
  }
115
111
 
@@ -133,8 +129,7 @@ function inputStyle(): Array<
133
129
  }
134
130
 
135
131
  function iconBoxStyle(props: ThemeProps): ReturnType<typeof css> {
136
- const {theme} = props
137
- const color = theme.sanity.color.input
132
+ const {color} = getTheme_v2(props.theme)
138
133
 
139
134
  return css`
140
135
  pointer-events: none;
@@ -143,23 +138,23 @@ function iconBoxStyle(props: ThemeProps): ReturnType<typeof css> {
143
138
  right: 0;
144
139
 
145
140
  /* enabled */
146
- --card-fg-color: ${color.default.enabled.fg};
141
+ --card-fg-color: ${color.input.default.enabled.fg};
147
142
 
148
143
  /* hover */
149
144
  @media (hover: hover) {
150
145
  select:not(disabled):not(:read-only):hover + && {
151
- --card-fg-color: ${color.default.hovered.fg};
146
+ --card-fg-color: ${color.input.default.hovered.fg};
152
147
  }
153
148
  }
154
149
 
155
150
  /* disabled */
156
151
  select:disabled + && {
157
- --card-fg-color: ${color.default.disabled.fg};
152
+ --card-fg-color: ${color.input.default.disabled.fg};
158
153
  }
159
154
 
160
155
  /* read-only */
161
156
  select[data-read-only] + && {
162
- --card-fg-color: ${color.default.readOnly.fg};
157
+ --card-fg-color: ${color.input.default.readOnly.fg};
163
158
  }
164
159
  `
165
160
  }
@@ -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
 
4
4
  export interface ResponsiveStackSpaceStyleProps {
@@ -23,8 +23,7 @@ export function stackBaseStyle(): CSSObject {
23
23
  export function responsiveStackSpaceStyle(
24
24
  props: ResponsiveStackSpaceStyleProps & ThemeProps,
25
25
  ): CSSObject[] {
26
- const {theme} = props
27
- const {media, space} = theme.sanity
26
+ const {media, space} = getTheme_v2(props.theme)
28
27
 
29
28
  return _responsive(media, props.$space, (spaceIndex) => ({
30
29
  gridGap: rem(space[spaceIndex]),
@@ -1,41 +1,21 @@
1
- import {Flex, Switch, useTheme} from '@sanity/ui'
2
- import {useBoolean, useNumber} from '@sanity/ui-workshop'
3
- import {useCallback, useMemo} from 'react'
4
- import {ThemeProvider} from 'styled-components'
1
+ import {Flex, Switch} from '@sanity/ui'
2
+ import {useBoolean} from '@sanity/ui-workshop'
3
+ import {useCallback} from 'react'
5
4
 
6
5
  export default function PropsStory() {
7
6
  const checked = useBoolean('Checked', false)
8
7
  const indeterminate = useBoolean('Indeterminate', false)
9
8
  const readOnly = useBoolean('Read only', false)
10
- const theme = useTheme()
11
- const focusRingOffset = useNumber('Focus ring offset', theme.sanity.input.switch.focusRing.offset)
12
- const focusRingWidth = useNumber('Focus ring width', theme.sanity.input.switch.focusRing.width)
13
9
  const handleChange = useCallback(() => undefined, [])
14
10
 
15
- const customTheme = useMemo(
16
- () => ({
17
- ...theme,
18
- sanity: {
19
- ...theme.sanity,
20
- focusRing: {
21
- offset: focusRingOffset || theme.sanity.input.switch.focusRing.offset,
22
- width: focusRingWidth || theme.sanity.input.switch.focusRing.width,
23
- },
24
- },
25
- }),
26
- [focusRingOffset, focusRingWidth, theme],
27
- )
28
-
29
11
  return (
30
- <ThemeProvider theme={customTheme}>
31
- <Flex align="center" height="fill" justify="center" padding={[4, 5, 6]} sizing="border">
32
- <Switch
33
- checked={checked}
34
- indeterminate={indeterminate}
35
- onChange={handleChange}
36
- readOnly={readOnly}
37
- />
38
- </Flex>
39
- </ThemeProvider>
12
+ <Flex align="center" height="fill" justify="center" padding={[4, 5, 6]} sizing="border">
13
+ <Switch
14
+ checked={checked}
15
+ indeterminate={indeterminate}
16
+ onChange={handleChange}
17
+ readOnly={readOnly}
18
+ />
19
+ </Flex>
40
20
  )
41
21
  }
@@ -1,3 +1,4 @@
1
+ import {getTheme_v2} from '@sanity/ui/theme'
1
2
  import {css} from 'styled-components'
2
3
  import {rem, ThemeProps} from '../../styles'
3
4
  import {focusRingStyle} from '../../styles/internal'
@@ -35,14 +36,11 @@ export function switchInputStyles(): ReturnType<typeof css> {
35
36
 
36
37
  /* Representation */
37
38
  export function switchRepresentationStyles(props: ThemeProps): ReturnType<typeof css> {
38
- const {theme} = props
39
- const {input} = theme.sanity
40
- const {focusRing} = input.switch
41
- const color = theme.sanity.color.input
39
+ const {color, input} = getTheme_v2(props.theme)
42
40
 
43
41
  return css`
44
- --switch-bg-color: ${color.default.enabled.border};
45
- --switch-fg-color: ${color.default.enabled.bg};
42
+ --switch-bg-color: ${color.input.default.enabled.border};
43
+ --switch-fg-color: ${color.input.default.enabled.bg};
46
44
  --switch-box-shadow: none;
47
45
 
48
46
  &:not([hidden]) {
@@ -71,7 +69,7 @@ export function switchRepresentationStyles(props: ThemeProps): ReturnType<typeof
71
69
 
72
70
  /* Focus styles */
73
71
  input:focus + && {
74
- --switch-box-shadow: ${focusRingStyle({focusRing})};
72
+ --switch-box-shadow: ${focusRingStyle({focusRing: input.switch.focusRing})};
75
73
  }
76
74
 
77
75
  input:focus:not(:focus-visible) + && {
@@ -79,38 +77,37 @@ export function switchRepresentationStyles(props: ThemeProps): ReturnType<typeof
79
77
  }
80
78
 
81
79
  input:checked + && {
82
- --switch-bg-color: ${color.default.enabled.fg};
83
- --switch-fg-color: ${color.default.enabled.bg};
80
+ --switch-bg-color: ${color.input.default.enabled.fg};
81
+ --switch-fg-color: ${color.input.default.enabled.bg};
84
82
  }
85
83
 
86
84
  @media (hover: hover) {
87
85
  input:not(:disabled):hover + && {
88
- --switch-bg-color: ${color.default.hovered.border};
89
- --switch-fg-color: ${color.default.hovered.bg};
86
+ --switch-bg-color: ${color.input.default.hovered.border};
87
+ --switch-fg-color: ${color.input.default.hovered.bg};
90
88
  }
91
89
 
92
90
  input:not(:disabled):checked:hover + && {
93
- --switch-bg-color: ${color.default.enabled.fg};
94
- --switch-fg-color: ${color.default.enabled.bg};
91
+ --switch-bg-color: ${color.input.default.enabled.fg};
92
+ --switch-fg-color: ${color.input.default.enabled.bg};
95
93
  }
96
94
  }
97
95
 
98
96
  input:not([data-read-only]):disabled + && {
99
- --switch-bg-color: ${color.default.disabled.border};
100
- --switch-fg-color: ${color.default.disabled.bg};
97
+ --switch-bg-color: ${color.input.default.disabled.border};
98
+ --switch-fg-color: ${color.input.default.disabled.bg};
101
99
  }
102
100
 
103
101
  input[data-read-only]:disabled + && {
104
- --switch-bg-color: ${color.default.readOnly.border};
105
- --switch-fg-color: ${color.default.readOnly.bg};
102
+ --switch-bg-color: ${color.input.default.readOnly.border};
103
+ --switch-fg-color: ${color.input.default.readOnly.bg};
106
104
  }
107
105
  `
108
106
  }
109
107
 
110
108
  /* Track */
111
109
  export function switchTrackStyles(props: ThemeProps): ReturnType<typeof css> {
112
- const {theme} = props
113
- const {input} = theme.sanity
110
+ const {input} = getTheme_v2(props.theme)
114
111
 
115
112
  return css`
116
113
  &:not([hidden]) {
@@ -130,8 +127,8 @@ export function switchTrackStyles(props: ThemeProps): ReturnType<typeof css> {
130
127
  export function switchThumbStyles(
131
128
  props: {$checked?: boolean; $indeterminate?: boolean} & ThemeProps,
132
129
  ): ReturnType<typeof css> {
133
- const {$indeterminate, theme} = props
134
- const {input} = theme.sanity
130
+ const {$indeterminate} = props
131
+ const {input} = getTheme_v2(props.theme)
135
132
  const trackWidth = input.switch.width
136
133
  const trackHeight = input.switch.height
137
134
  const trackPadding = input.switch.padding
@@ -1,27 +1,27 @@
1
- import {Flex, Text, useTheme} from '@sanity/ui'
2
- import {Theme, ThemeColorSpotKey} from '@sanity/ui/theme'
1
+ import {Flex, Text, ThemeProps} from '@sanity/ui'
2
+ import {ThemeColorAvatarColorKey, ThemeColorSpotKey, getTheme_v2} from '@sanity/ui/theme'
3
3
  import {useSelect} from '@sanity/ui-workshop'
4
4
  import styled, {css} from 'styled-components'
5
5
  import {WORKSHOP_SPOT_COLOR_OPTIONS} from '../../../__workshop__/constants'
6
6
 
7
- const ColoredText = styled(Text)<{color?: ThemeColorSpotKey}>((props: {
8
- color?: ThemeColorSpotKey
9
- theme: Theme
10
- }) => {
11
- const {spot} = props.theme.sanity.color
7
+ const ColoredText = styled(Text)<{$color?: ThemeColorSpotKey}>((
8
+ props: {
9
+ $color?: ThemeColorAvatarColorKey
10
+ } & ThemeProps,
11
+ ) => {
12
+ const {color} = getTheme_v2(props.theme)
12
13
 
13
14
  return css`
14
- color: ${spot[props.color || 'gray']};
15
+ color: ${color.avatar[props.$color || 'gray'].bg};
15
16
  `
16
17
  })
17
18
 
18
19
  export default function ColoredTextStory() {
19
- const theme = useTheme()
20
20
  const color = useSelect('Color', WORKSHOP_SPOT_COLOR_OPTIONS, 'gray')
21
21
 
22
22
  return (
23
23
  <Flex align="center" height="fill" justify="center" padding={[4, 5, 6]} sizing="border">
24
- <ColoredText align="center" color={color} size={4} theme={theme} weight="bold">
24
+ <ColoredText align="center" $color={color} size={4} weight="bold">
25
25
  {color}
26
26
  </ColoredText>
27
27
  </Flex>
@@ -1,11 +1,12 @@
1
+ import {getTheme_v2} from '@sanity/ui/theme'
1
2
  import {css} from 'styled-components'
2
3
  import {ThemeProps} from '../../styles'
3
4
 
4
5
  export function textBaseStyle(
5
6
  props: {$accent?: boolean; $muted?: boolean} & ThemeProps,
6
7
  ): ReturnType<typeof css> {
7
- const {$accent, $muted, theme} = props
8
- const {weights} = theme.sanity.fonts.text
8
+ const {$accent, $muted} = props
9
+ const {font} = getTheme_v2(props.theme)
9
10
 
10
11
  return css`
11
12
  color: var(--card-fg-color);
@@ -21,7 +22,7 @@ export function textBaseStyle(
21
22
  `}
22
23
 
23
24
  & code {
24
- font-family: ${theme.sanity.fonts.code.family};
25
+ font-family: ${font.code.family};
25
26
  border-radius: 1px;
26
27
  background-color: var(--card-code-bg-color);
27
28
  color: var(--card-code-fg-color);
@@ -51,7 +52,7 @@ export function textBaseStyle(
51
52
  }
52
53
 
53
54
  & strong {
54
- font-weight: ${weights.bold};
55
+ font-weight: ${font.text.weights.bold};
55
56
  }
56
57
 
57
58
  & svg {
@@ -63,6 +64,10 @@ export function textBaseStyle(
63
64
  & [data-sanity-icon] {
64
65
  vertical-align: baseline;
65
66
  color: var(--card-icon-color);
67
+
68
+ & path {
69
+ vector-effect: non-scaling-stroke !important;
70
+ }
66
71
  }
67
72
  `
68
73
  }
@@ -26,7 +26,7 @@ import {
26
26
  import styled from 'styled-components'
27
27
  import {useArrayProp, useForwardedRef} from '../../hooks'
28
28
  import {useDelayedState} from '../../hooks/useDelayedState'
29
- import {useTheme} from '../../theme'
29
+ import {useTheme_v2} from '../../theme'
30
30
  import {Placement} from '../../types'
31
31
  import {Arrow, Layer, LayerProps, Portal, useBoundaryElement, usePortal} from '../../utils'
32
32
  import {Card} from '../card'
@@ -96,7 +96,7 @@ export const Tooltip = forwardRef(function Tooltip(
96
96
  ref: React.ForwardedRef<HTMLDivElement>,
97
97
  ) {
98
98
  const boundaryElementContext = useBoundaryElement()
99
- const theme = useTheme()
99
+ const {layer} = useTheme_v2()
100
100
  const {
101
101
  arrow: arrowProp = false,
102
102
  boundaryElement = boundaryElementContext?.element,
@@ -111,7 +111,7 @@ export const Tooltip = forwardRef(function Tooltip(
111
111
  radius = 2,
112
112
  scheme,
113
113
  shadow = 2,
114
- zOffset = theme.sanity.layer?.tooltip.zOffset,
114
+ zOffset = layer.tooltip.zOffset,
115
115
  delay,
116
116
  animate = false,
117
117
  ...restProps
@@ -1,4 +1,4 @@
1
- import {CSSObject} from '@sanity/ui/theme'
1
+ import {CSSObject, getTheme_v2} from '@sanity/ui/theme'
2
2
  import {_responsive} from '../helpers'
3
3
  import {ThemeProps} from '../types'
4
4
  import {ResponsiveBorderStyleProps} from './types'
@@ -10,8 +10,7 @@ export function responsiveBorderStyle(): Array<
10
10
  }
11
11
 
12
12
  function border(props: ResponsiveBorderStyleProps & ThemeProps) {
13
- const {theme} = props
14
- const {card, media} = theme.sanity
13
+ const {card, media} = getTheme_v2(props.theme)
15
14
  const borderStyle = `${card.border?.width ?? 1}px solid var(--card-border-color)`
16
15
 
17
16
  return _responsive(media, props.$border, (value) =>
@@ -20,8 +19,7 @@ function border(props: ResponsiveBorderStyleProps & ThemeProps) {
20
19
  }
21
20
 
22
21
  function borderTop(props: ResponsiveBorderStyleProps & ThemeProps) {
23
- const {theme} = props
24
- const {card, media} = theme.sanity
22
+ const {card, media} = getTheme_v2(props.theme)
25
23
  const borderStyle = `${card.border?.width ?? 1}px solid var(--card-border-color)`
26
24
 
27
25
  return _responsive(media, props.$borderTop, (value) =>
@@ -30,8 +28,7 @@ function borderTop(props: ResponsiveBorderStyleProps & ThemeProps) {
30
28
  }
31
29
 
32
30
  function borderRight(props: ResponsiveBorderStyleProps & ThemeProps) {
33
- const {theme} = props
34
- const {card, media} = theme.sanity
31
+ const {card, media} = getTheme_v2(props.theme)
35
32
  const borderStyle = `${card.border?.width ?? 1}px solid var(--card-border-color)`
36
33
 
37
34
  return _responsive(media, props.$borderRight, (value) =>
@@ -40,8 +37,7 @@ function borderRight(props: ResponsiveBorderStyleProps & ThemeProps) {
40
37
  }
41
38
 
42
39
  function borderBottom(props: ResponsiveBorderStyleProps & ThemeProps) {
43
- const {theme} = props
44
- const {card, media} = theme.sanity
40
+ const {card, media} = getTheme_v2(props.theme)
45
41
  const borderStyle = `${card.border?.width ?? 1}px solid var(--card-border-color)`
46
42
 
47
43
  return _responsive(media, props.$borderBottom, (value) =>
@@ -50,8 +46,7 @@ function borderBottom(props: ResponsiveBorderStyleProps & ThemeProps) {
50
46
  }
51
47
 
52
48
  function borderLeft(props: ResponsiveBorderStyleProps & ThemeProps) {
53
- const {theme} = props
54
- const {card, media} = theme.sanity
49
+ const {card, media} = getTheme_v2(props.theme)
55
50
  const borderStyle = `${card.border?.width ?? 1}px solid var(--card-border-color)`
56
51
 
57
52
  return _responsive(media, props.$borderLeft, (value) =>
@@ -1,4 +1,4 @@
1
- import {CSSObject} from '@sanity/ui/theme'
1
+ import {CSSObject, getTheme_v2} from '@sanity/ui/theme'
2
2
  import {Property} from 'csstype'
3
3
  import {_responsive} from '../helpers'
4
4
  import {ThemeProps} from '../types'
@@ -36,8 +36,7 @@ export function responsiveBoxStyle(): Array<
36
36
  }
37
37
 
38
38
  function responsiveBoxDisplayStyle(props: ResponsiveBoxStyleProps & ThemeProps) {
39
- const {theme} = props
40
- const {media} = theme.sanity
39
+ const {media} = getTheme_v2(props.theme)
41
40
 
42
41
  return _responsive(media, props.$display, (display) => ({
43
42
  '&:not([hidden])': {display},
@@ -45,8 +44,7 @@ function responsiveBoxDisplayStyle(props: ResponsiveBoxStyleProps & ThemeProps)
45
44
  }
46
45
 
47
46
  function responsiveBoxSizingStyle(props: ResponsiveBoxStyleProps & ThemeProps) {
48
- const {theme} = props
49
- const {media} = theme.sanity
47
+ const {media} = getTheme_v2(props.theme)
50
48
 
51
49
  return _responsive(media, props.$sizing, (sizing) => ({
52
50
  boxSizing: BOX_SIZING[sizing],
@@ -54,8 +52,7 @@ function responsiveBoxSizingStyle(props: ResponsiveBoxStyleProps & ThemeProps) {
54
52
  }
55
53
 
56
54
  function responsiveBoxHeightStyle(props: ResponsiveBoxStyleProps & ThemeProps) {
57
- const {theme} = props
58
- const {media} = theme.sanity
55
+ const {media} = getTheme_v2(props.theme)
59
56
 
60
57
  return _responsive(media, props.$height, (height) => ({
61
58
  height: BOX_HEIGHT[height],
@@ -63,8 +60,7 @@ function responsiveBoxHeightStyle(props: ResponsiveBoxStyleProps & ThemeProps) {
63
60
  }
64
61
 
65
62
  function responsiveBoxOverflowStyle(props: ResponsiveBoxStyleProps & ThemeProps) {
66
- const {theme} = props
67
- const {media} = theme.sanity
63
+ const {media} = getTheme_v2(props.theme)
68
64
 
69
65
  return _responsive(media, props.$overflow, (overflow) => ({
70
66
  overflow,