@sanity/ui 2.0.0-beta.2 → 2.0.0-beta.21

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 (91) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +6 -3
  3. package/dist/index.cjs.mjs +11 -36
  4. package/dist/index.d.ts +247 -267
  5. package/dist/index.esm.js +477 -326
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.js +486 -539
  8. package/dist/index.js.map +1 -1
  9. package/dist/theme.cjs.mjs +1 -1
  10. package/dist/theme.d.ts +87 -115
  11. package/dist/theme.esm.js +348 -290
  12. package/dist/theme.esm.js.map +1 -1
  13. package/dist/theme.js +348 -290
  14. package/dist/theme.js.map +1 -1
  15. package/package.json +6 -3
  16. package/src/core/__workshop__/fontsPlugin.tsx +48 -8
  17. package/src/core/_compat.ts +236 -87
  18. package/src/core/components/dialog/dialog.tsx +1 -1
  19. package/src/core/components/dialog/styles.ts +2 -2
  20. package/src/core/components/menu/__workshop__/selectedItem.tsx +7 -2
  21. package/src/core/components/menu/menuButton.tsx +12 -1
  22. package/src/core/components/toast/toast.tsx +17 -2
  23. package/src/core/components/toast/toastProvider.tsx +20 -3
  24. package/src/core/constants.ts +37 -0
  25. package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +6 -3
  26. package/src/core/middleware/origin.ts +47 -0
  27. package/src/core/primitives/badge/badge.tsx +1 -3
  28. package/src/core/primitives/button/button.tsx +9 -11
  29. package/src/core/primitives/heading/styles.ts +4 -0
  30. package/src/core/primitives/kbd/kbd.tsx +2 -0
  31. package/src/core/primitives/popover/popover.tsx +67 -13
  32. package/src/core/primitives/popover/popoverCard.tsx +31 -15
  33. package/src/core/primitives/select/select.tsx +1 -1
  34. package/src/core/primitives/switch/styles.ts +6 -1
  35. package/src/core/primitives/textInput/__workshop__/plain.tsx +1 -1
  36. package/src/core/primitives/textInput/__workshop__/states.tsx +10 -2
  37. package/src/core/primitives/tooltip/tooltip.tsx +46 -56
  38. package/src/core/primitives/tooltip/tooltipCard.tsx +110 -0
  39. package/src/core/styles/card/_cardColorStyle.ts +2 -0
  40. package/src/core/styles/input/textInputStyle.ts +33 -2
  41. package/src/core/styles/margin/marginsStyle.test.ts +2 -2
  42. package/src/core/styles/padding/paddingStyle.test.ts +2 -2
  43. package/src/core/theme/__workshop__/build/Root.tsx +20 -3
  44. package/src/core/theme/__workshop__/build/story.tsx +16 -10
  45. package/src/core/theme/__workshop__/canvas.tsx +7 -7
  46. package/src/core/theme/__workshop__/debug/story.tsx +196 -0
  47. package/src/core/theme/__workshop__/index.ts +5 -0
  48. package/src/core/theme/theme.test.tsx +2 -2
  49. package/src/core/types/button.ts +1 -2
  50. package/src/core/{primitives/tooltip → utils/conditionalWrapper}/conditionalWrapper.tsx +3 -0
  51. package/src/core/utils/conditionalWrapper/index.ts +1 -0
  52. package/src/core/utils/index.ts +1 -0
  53. package/src/theme/build/_deprecated/color/factory.ts +3 -3
  54. package/src/theme/build/buildColorTheme.test.ts +2 -2
  55. package/src/theme/build/buildColorTheme.ts +16 -16
  56. package/src/theme/build/colorToken/colorToken.ts +19 -0
  57. package/src/theme/build/colorToken/compileColorToken.ts +21 -0
  58. package/src/theme/build/colorToken/index.ts +2 -0
  59. package/src/theme/build/colorToken/types.ts +6 -0
  60. package/src/theme/build/renderColorTheme.ts +14 -15
  61. package/src/theme/build/renderColorValue.ts +9 -2
  62. package/src/theme/config/system.ts +12 -10
  63. package/src/theme/config/tokens/color/types.ts +12 -1
  64. package/src/theme/config/tokens/parseTokenKey.ts +1 -0
  65. package/src/theme/config/tokens/parseTokenValue.test.ts +13 -16
  66. package/src/theme/config/tokens/parseTokenValue.ts +45 -14
  67. package/src/theme/config/tokens/types.ts +3 -2
  68. package/src/theme/defaults/colorTokens.ts +279 -253
  69. package/src/theme/defaults/config.ts +2 -2
  70. package/src/theme/getScopedTheme.ts +1 -0
  71. package/src/theme/index.ts +0 -7
  72. package/src/theme/system/color/_constants.ts +5 -2
  73. package/src/theme/system/color/_system.ts +2 -1
  74. package/src/theme/system/color/avatar.ts +2 -12
  75. package/src/theme/system/color/button.ts +4 -20
  76. package/src/theme/system/color/input.ts +3 -11
  77. package/src/theme/system/color/selectable.ts +3 -14
  78. package/src/theme/system/shadow.ts +0 -6
  79. package/src/theme/system/styles.ts +0 -6
  80. package/src/theme/system/theme.ts +11 -1
  81. package/src/theme/system/v0/avatar.ts +1 -1
  82. package/src/theme/system/v0/color/button.ts +4 -4
  83. package/src/theme/system/v0/color/card.ts +2 -2
  84. package/src/theme/system/v0/color/color.ts +0 -1
  85. package/src/theme/system/v0/color/input.ts +3 -3
  86. package/src/theme/system/v0/color/muted.ts +2 -2
  87. package/src/theme/system/v0/color/solid.ts +2 -2
  88. package/src/theme/versioning/getTheme_v2.ts +2 -1
  89. package/src/theme/versioning/themeColor_v0_v2.ts +2 -2
  90. package/src/theme/versioning/v2_v0.ts +3 -2
  91. package/src/theme/build/colorToken.ts +0 -39
@@ -10,6 +10,7 @@ import {
10
10
  ThemeColorTokenValue,
11
11
  } from '../../system'
12
12
 
13
+ /** @public */
13
14
  export interface ThemeColorAvatarHueTokens {
14
15
  _blend?: ColorBlendModeTokenValue
15
16
  _hue?: ColorHueKey
@@ -17,6 +18,7 @@ export interface ThemeColorAvatarHueTokens {
17
18
  fg?: ThemeColorTokenValue
18
19
  }
19
20
 
21
+ /** @public */
20
22
  export interface ThemeColorAvatarTokens {
21
23
  '*'?: ThemeColorAvatarHueTokens
22
24
  gray?: ThemeColorAvatarHueTokens
@@ -30,8 +32,8 @@ export interface ThemeColorAvatarTokens {
30
32
  cyan?: ThemeColorAvatarHueTokens
31
33
  }
32
34
 
35
+ /** @public */
33
36
  export interface ThemeColorBadgeTokens {
34
- // _blend?: ColorBlendModeTokenValue
35
37
  _hue?: ColorHueKey
36
38
  bg?: ThemeColorTokenValue
37
39
  fg?: ThemeColorTokenValue
@@ -39,6 +41,7 @@ export interface ThemeColorBadgeTokens {
39
41
  icon?: ThemeColorTokenValue
40
42
  }
41
43
 
44
+ /** @public */
42
45
  export interface ThemeColorBaseTokens extends ThemeColorStateTokens {
43
46
  focusRing?: ThemeColorTokenValue
44
47
  backdrop?: ThemeColorTokenValue
@@ -50,6 +53,7 @@ export interface ThemeColorBaseTokens extends ThemeColorStateTokens {
50
53
  }
51
54
  }
52
55
 
56
+ /** @public */
53
57
  export interface ThemeColorBadgeToneTokens {
54
58
  _blend?: ColorBlendModeTokenValue
55
59
  _hue?: ColorHueKey
@@ -59,6 +63,7 @@ export interface ThemeColorBadgeToneTokens {
59
63
  icon?: ThemeColorTokenValue
60
64
  }
61
65
 
66
+ /** @public */
62
67
  export interface ThemeColorBadgeTokens {
63
68
  '*'?: ThemeColorBadgeToneTokens
64
69
  default?: ThemeColorBadgeToneTokens
@@ -68,6 +73,7 @@ export interface ThemeColorBadgeTokens {
68
73
  critical?: ThemeColorBadgeToneTokens
69
74
  }
70
75
 
76
+ /** @public */
71
77
  export interface ThemeColorStateTokens {
72
78
  _blend?: ColorBlendModeTokenValue
73
79
  _hue?: ColorHueKey
@@ -102,13 +108,16 @@ export interface ThemeColorStateTokens {
102
108
  }
103
109
  }
104
110
 
111
+ /** @public */
105
112
  export type ThemeColorStatesTokens = Partial<Record<ColorConfigState, ThemeColorStateTokens>>
106
113
 
114
+ /** @public */
107
115
  export interface ThemeColorButtonTokens
108
116
  extends Partial<Record<ColorConfigStateTone, ThemeColorStatesTokens>> {
109
117
  _hue?: ColorHueKey
110
118
  }
111
119
 
120
+ /** @public */
112
121
  export interface ThemeColorInputStateTokens {
113
122
  _blend?: ColorBlendModeTokenValue
114
123
  _hue?: ColorHueKey
@@ -121,11 +130,13 @@ export interface ThemeColorInputStateTokens {
121
130
  placeholder?: ThemeColorTokenValue
122
131
  }
123
132
 
133
+ /** @public */
124
134
  export interface ThemeColorInputTokens
125
135
  extends Partial<Record<ColorConfigInputState, ThemeColorInputStateTokens>> {
126
136
  _hue?: ColorHueKey
127
137
  }
128
138
 
139
+ /** @public */
129
140
  export interface ThemeColorTokens {
130
141
  base?: Partial<Record<ColorConfigCardTone, ThemeColorBaseTokens>>
131
142
  button?: Partial<Record<ThemeColorButtonModeKey, ThemeColorButtonTokens>>
@@ -8,6 +8,7 @@ import {
8
8
  } from '../helpers'
9
9
  import {TokenKeyNode} from './types'
10
10
 
11
+ /** @internal */
11
12
  export function parseTokenKey(str: string): TokenKeyNode | undefined {
12
13
  const segments = str.split('/')
13
14
  const segment0 = segments.shift() || ''
@@ -11,13 +11,25 @@ test('parse color value', () => {
11
11
  tint: '50',
12
12
  })
13
13
 
14
+ expect(parseTokenValue('50 50%')).toEqual({
15
+ type: 'color',
16
+ tint: '50',
17
+ mix: 0.5,
18
+ })
19
+
14
20
  expect(parseTokenValue('cyan/500')).toEqual({
15
21
  type: 'color',
16
- key: 'cyan/500',
17
22
  hue: 'cyan',
18
23
  tint: '500',
19
24
  })
20
25
 
26
+ expect(parseTokenValue('cyan/500 50%')).toEqual({
27
+ type: 'color',
28
+ hue: 'cyan',
29
+ mix: 0.5,
30
+ tint: '500',
31
+ })
32
+
21
33
  expect(parseTokenValue('screen')).toEqual({
22
34
  type: 'blendMode',
23
35
  value: 'screen',
@@ -27,19 +39,4 @@ test('parse color value', () => {
27
39
  type: 'blendMode',
28
40
  value: 'multiply',
29
41
  })
30
-
31
- expect(parseTokenValue('0')).toEqual({
32
- type: 'color',
33
- opacity: 0,
34
- })
35
-
36
- expect(parseTokenValue('0.1')).toEqual({
37
- type: 'color',
38
- opacity: 0.1,
39
- })
40
-
41
- expect(parseTokenValue('1')).toEqual({
42
- type: 'color',
43
- opacity: 1,
44
- })
45
42
  })
@@ -2,14 +2,32 @@ import {isColorBlendModeValue, isColorHueKey, isColorTintKey} from '../../system
2
2
  import {isColorOpacityValue, isColorValue} from '../helpers'
3
3
  import {TokenValueNode} from './types'
4
4
 
5
+ function isColorMixPercentValue(str: string): str is `${number}%` {
6
+ return /^\d+%$/.test(str)
7
+ }
8
+
9
+ /** @internal */
5
10
  export function parseTokenValue(str: string): TokenValueNode | undefined {
6
11
  const segments = str.split('/')
7
- const segment0 = segments.shift() || ''
12
+
13
+ let nextSegment = segments.shift() || ''
14
+
15
+ const [segment0, segment0mix] = nextSegment.split(' ')
8
16
 
9
17
  if (isColorTintKey(segment0)) {
10
18
  const tint = segment0
11
19
  const segment1 = segments.shift() || ''
12
20
 
21
+ if (isColorMixPercentValue(segment0mix)) {
22
+ const mix = Number(segment0mix.slice(0, -1)) / 100
23
+
24
+ return {
25
+ type: 'color',
26
+ tint,
27
+ mix,
28
+ }
29
+ }
30
+
13
31
  if (isColorOpacityValue(segment1)) {
14
32
  const opacity = Number(segment1)
15
33
 
@@ -30,6 +48,16 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
30
48
  const key = segment0 as 'black' | 'white'
31
49
  const segment1 = segments.shift() || ''
32
50
 
51
+ if (isColorMixPercentValue(segment0mix)) {
52
+ const mix = Number(segment0mix.slice(0, -1)) / 100
53
+
54
+ return {
55
+ type: 'color',
56
+ key,
57
+ mix,
58
+ }
59
+ }
60
+
33
61
  if (isColorOpacityValue(segment1)) {
34
62
  const opacity = Number(segment1)
35
63
 
@@ -48,18 +76,31 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
48
76
 
49
77
  if (isColorHueKey(segment0)) {
50
78
  const hue = segment0
51
- const segment1 = segments.shift() || ''
79
+
80
+ nextSegment = segments.shift() || ''
81
+
82
+ const [segment1, segment1mix] = nextSegment.split(' ')
52
83
 
53
84
  if (isColorTintKey(segment1)) {
54
85
  const tint = segment1
55
86
  const segment2 = segments.shift() || ''
56
87
 
88
+ if (isColorMixPercentValue(segment1mix)) {
89
+ const mix = Number(segment1mix.slice(0, -1)) / 100
90
+
91
+ return {
92
+ type: 'color',
93
+ hue,
94
+ tint,
95
+ mix,
96
+ }
97
+ }
98
+
57
99
  if (isColorOpacityValue(segment2)) {
58
100
  const opacity = Number(segment2)
59
101
 
60
102
  return {
61
103
  type: 'color',
62
- key: `${hue}/${tint}`,
63
104
  hue,
64
105
  tint,
65
106
  opacity,
@@ -68,7 +109,6 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
68
109
 
69
110
  return {
70
111
  type: 'color',
71
- key: `${hue}/${tint}`,
72
112
  hue,
73
113
  tint,
74
114
  }
@@ -76,16 +116,7 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
76
116
 
77
117
  return {
78
118
  type: 'hue',
79
- value: `${hue}`,
80
- }
81
- }
82
-
83
- if (isColorOpacityValue(segment0)) {
84
- const opacity = Number(segment0)
85
-
86
- return {
87
- type: 'color',
88
- opacity,
119
+ value: hue,
89
120
  }
90
121
  }
91
122
 
@@ -29,10 +29,11 @@ export type TokenKeyNode = TokenBaseKeyNode | TokenButtonKeyNode
29
29
  /** @internal */
30
30
  export interface TokenColorValueNode {
31
31
  type: 'color'
32
- key?: 'black' | 'white' | `${ColorHueKey}/${ColorTintKey}` | ColorTintKey
32
+ key?: 'black' | 'white'
33
33
  hue?: ColorHueKey
34
- tint?: ColorTintKey
34
+ mix?: number
35
35
  opacity?: number
36
+ tint?: ColorTintKey
36
37
  }
37
38
 
38
39
  /** @internal */