@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
@@ -1,8 +1,8 @@
1
+ import {defaultColorPalette} from '../defaults/colorPalette'
1
2
  import {buildTheme} from './buildTheme'
2
- import {defaultColorPalette} from './defaults/colorPalette'
3
3
 
4
4
  test('build theme', () => {
5
- const {color} = buildTheme({
5
+ const rootTheme = buildTheme({
6
6
  palette: {
7
7
  ...defaultColorPalette,
8
8
  black: '#000000',
@@ -27,10 +27,12 @@ test('build theme', () => {
27
27
  },
28
28
  })
29
29
 
30
+ const {color} = rootTheme.v2!
31
+
30
32
  expect({
31
33
  light: {
32
- bg: color.light.default.base.bg,
33
- fg: color.light.default.base.fg,
34
+ bg: color.light.default.bg,
35
+ fg: color.light.default.fg,
34
36
  default: {
35
37
  button: {
36
38
  ghost: {
@@ -42,8 +44,8 @@ test('build theme', () => {
42
44
  },
43
45
  },
44
46
  dark: {
45
- bg: color.dark.default.base.bg,
46
- fg: color.dark.default.base.fg,
47
+ bg: color.dark.default.bg,
48
+ fg: color.dark.default.fg,
47
49
  default: {
48
50
  button: {
49
51
  ghost: {
@@ -75,7 +77,7 @@ test('build theme', () => {
75
77
  button: {
76
78
  ghost: {
77
79
  enabled: {
78
- border: 'rgba(19,19,27,0)',
80
+ border: 'rgba(19,20,27,0)',
79
81
  },
80
82
  },
81
83
  },
@@ -1,28 +1,31 @@
1
1
  import {ThemeConfig} from '../config'
2
- import {RootTheme} from '../system'
2
+ import {defaultThemeConfig} from '../defaults/config'
3
+ import {defaultThemeFonts} from '../defaults/fonts'
4
+ import {RootTheme, RootTheme_v2} from '../system'
5
+ import {v2_v0} from '../versioning'
3
6
  import {buildColorTheme} from './buildColorTheme'
4
- import {defaultThemeConfig} from './defaults/config'
5
- import {defaultThemeFonts} from './defaults/fonts'
6
7
  import {renderThemeColorSchemes} from './renderColorTheme'
7
8
 
8
9
  /** @internal */
9
10
  export function buildTheme(config?: ThemeConfig): RootTheme {
10
11
  const colorTheme = buildColorTheme(config)
11
12
 
12
- return {
13
+ const v2: RootTheme_v2 = {
14
+ _version: 2,
13
15
  avatar: config?.avatar ?? defaultThemeConfig.avatar,
14
16
  button: config?.button ?? defaultThemeConfig.button,
15
17
  card: config?.card ?? defaultThemeConfig.card,
16
18
  color: renderThemeColorSchemes(colorTheme, config),
17
19
  container: config?.container ?? defaultThemeConfig.container,
18
- focusRing: config?.focusRing ?? defaultThemeConfig.focusRing,
19
- fonts: config?.fonts ?? defaultThemeFonts,
20
+ font: config?.fonts ?? defaultThemeFonts,
20
21
  input: config?.input ?? defaultThemeConfig.input,
22
+ layer: config?.layer ?? defaultThemeConfig.layer,
21
23
  media: config?.media ?? defaultThemeConfig.media,
22
24
  radius: config?.radius ?? defaultThemeConfig.radius,
23
- shadows: config?.shadows ?? defaultThemeConfig.shadows,
25
+ shadow: config?.shadow ?? defaultThemeConfig.shadow,
24
26
  space: config?.space ?? defaultThemeConfig.space,
25
-
26
- styles: config?.styles ?? defaultThemeConfig.styles,
27
+ style: config?.style ?? defaultThemeConfig.style,
27
28
  }
29
+
30
+ return v2_v0(v2)
28
31
  }
@@ -6,9 +6,11 @@ export interface ColorTokenContext {
6
6
  scheme: 'light' | 'dark'
7
7
  }
8
8
 
9
+ const DEFAULT_COLOR_TOKEN_VALUE: ThemeColorTokenValue = ['500', '500']
10
+
9
11
  export function resolveColorTokenValue(
10
12
  context: ColorTokenContext,
11
- value: ThemeColorTokenValue,
13
+ value: ThemeColorTokenValue = DEFAULT_COLOR_TOKEN_VALUE,
12
14
  ): string {
13
15
  const {hue, scheme} = context
14
16
  const node = parseTokenValue(value[scheme === 'light' ? 0 : 1])
@@ -1,6 +1,7 @@
1
1
  import {parseColor} from './parse'
2
2
  import {RGB, RGBA} from './types'
3
3
 
4
+ /** @internal */
4
5
  export function getContrastRatio(bg: string, fg: string): number {
5
6
  const rgb1 = parseColor(bg) // bg: RGB | RGBA, fg: RGB | RGBA
6
7
  const rgb2 = parseColor(fg)
@@ -0,0 +1,3 @@
1
+ export function isRecord(value: unknown): value is Record<string, unknown> {
2
+ return Boolean(value && typeof value === 'object' && !Array.isArray(value))
3
+ }
@@ -1,23 +1,28 @@
1
- export function merge(
2
- target: Record<string, unknown>,
3
- source: Record<string, unknown>,
4
- ): Record<string, unknown> {
5
- const ret = {...target}
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
6
2
 
3
+ import {isRecord} from './lib/isRecord'
4
+
5
+ export function merge<T extends Record<string, any>>(...records: (T | undefined)[]): T {
6
+ const _records = records.filter(Boolean) as T[]
7
+
8
+ if (_records.length === 0) {
9
+ return {} as T
10
+ }
11
+
12
+ return _records.reduce(_merge, {} as T)
13
+ }
14
+
15
+ function _merge<T extends Record<string, any>>(acc: T, source: T): T {
7
16
  for (const key of Object.keys(source)) {
8
- const prevValue = target[key]
17
+ const prevValue = acc[key]
9
18
  const nextValue = source[key]
10
19
 
11
20
  if (isRecord(prevValue) && isRecord(nextValue)) {
12
- ret[key] = merge(prevValue, nextValue)
21
+ ;(acc as any)[key] = merge(prevValue, nextValue)
13
22
  } else {
14
- ret[key] = nextValue
23
+ ;(acc as any)[key] = nextValue
15
24
  }
16
25
  }
17
26
 
18
- return ret
19
- }
20
-
21
- function isRecord(value: unknown): value is Record<string, unknown> {
22
- return Boolean(value && typeof value === 'object' && !Array.isArray(value))
27
+ return acc
23
28
  }