@sanity/ui 2.0.0-alpha.2 → 2.0.0-alpha.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 (96) hide show
  1. package/dist/index.cjs.mjs +28 -0
  2. package/dist/index.d.ts +476 -12
  3. package/dist/index.esm.js +1326 -524
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +1353 -523
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -8
  8. package/src/components/autocomplete/autocomplete.tsx +6 -0
  9. package/src/components/dialog/constants.ts +4 -0
  10. package/src/components/dialog/dialog.tsx +79 -15
  11. package/src/components/hotkeys/hotkeys.tsx +2 -0
  12. package/src/components/menu/menu.tsx +2 -0
  13. package/src/components/menu/menuButton.tsx +2 -0
  14. package/src/components/menu/menuGroup.tsx +22 -23
  15. package/src/components/menu/menuItem.tsx +29 -35
  16. package/src/components/tab/tab.tsx +4 -1
  17. package/src/components/toast/toast.tsx +4 -0
  18. package/src/primitives/_selectable/style.ts +2 -1
  19. package/src/primitives/avatar/avatar.tsx +16 -9
  20. package/src/primitives/avatar/avatarCounter.tsx +3 -3
  21. package/src/primitives/avatar/styles.ts +1 -1
  22. package/src/primitives/badge/badge.tsx +7 -3
  23. package/src/primitives/box/box.tsx +3 -0
  24. package/src/primitives/button/__workshop__/sanityUploadButton.tsx +2 -1
  25. package/src/primitives/button/button.tsx +7 -3
  26. package/src/primitives/button/styles.ts +9 -2
  27. package/src/primitives/card/card.tsx +4 -0
  28. package/src/primitives/card/styles.ts +2 -0
  29. package/src/primitives/checkbox/checkbox.tsx +2 -0
  30. package/src/primitives/code/code.tsx +1 -0
  31. package/src/primitives/container/container.tsx +2 -0
  32. package/src/primitives/flex/flex.tsx +2 -0
  33. package/src/primitives/grid/grid.tsx +2 -0
  34. package/src/primitives/heading/heading.tsx +2 -0
  35. package/src/primitives/inline/inline.tsx +3 -0
  36. package/src/primitives/kbd/kbd.tsx +2 -0
  37. package/src/primitives/label/label.tsx +2 -0
  38. package/src/primitives/popover/popover.tsx +6 -1
  39. package/src/primitives/radio/radio.tsx +2 -0
  40. package/src/primitives/select/select.tsx +2 -0
  41. package/src/primitives/select/styles.ts +2 -0
  42. package/src/primitives/spinner/spinner.tsx +2 -0
  43. package/src/primitives/stack/stack.tsx +2 -0
  44. package/src/primitives/switch/switch.tsx +4 -0
  45. package/src/primitives/text/text.tsx +3 -0
  46. package/src/primitives/textArea/textArea.tsx +4 -1
  47. package/src/primitives/textInput/textInput.tsx +10 -1
  48. package/src/primitives/tooltip/__workshop__/customPortal.tsx +99 -0
  49. package/src/primitives/tooltip/__workshop__/index.ts +15 -0
  50. package/src/primitives/tooltip/__workshop__/overflowingBoundary.tsx +73 -0
  51. package/src/primitives/tooltip/__workshop__/resizableBoundary.tsx +85 -0
  52. package/src/primitives/tooltip/constants.ts +1 -0
  53. package/src/primitives/tooltip/tooltip.test.tsx +192 -0
  54. package/src/primitives/tooltip/tooltip.tsx +109 -33
  55. package/src/primitives/types.ts +4 -0
  56. package/src/styles/input/textInputStyle.ts +11 -6
  57. package/src/theme/_internal/__workshop__/build/story.tsx +288 -0
  58. package/src/theme/_internal/__workshop__/build/theme.ts +3 -0
  59. package/src/theme/_internal/__workshop__/index.ts +14 -0
  60. package/src/theme/_internal/build/buildTheme.test.ts +78 -0
  61. package/src/theme/_internal/build/buildTheme.ts +16 -0
  62. package/src/theme/_internal/build/colorTheme/buildColorTheme.test.ts +185 -0
  63. package/src/theme/_internal/build/colorTheme/buildColorTheme.ts +164 -0
  64. package/src/theme/_internal/build/colorTheme/renderColorTheme.ts +242 -0
  65. package/src/theme/_internal/build/colorTheme/resolveColorTokens.ts +121 -0
  66. package/src/theme/_internal/build/defaults/colorPalette.ts +8 -0
  67. package/src/theme/_internal/build/defaults/colorTokens.ts +147 -0
  68. package/src/theme/_internal/build/helpers.ts +65 -0
  69. package/src/theme/_internal/build/index.ts +1 -0
  70. package/src/theme/_internal/config/helpers.ts +47 -0
  71. package/src/theme/_internal/config/index.ts +3 -0
  72. package/src/theme/_internal/config/token/index.ts +2 -0
  73. package/src/theme/_internal/config/token/parseTokenKey.test.ts +72 -0
  74. package/src/theme/_internal/config/token/parseTokenKey.ts +88 -0
  75. package/src/theme/_internal/config/token/parseTokenValue.test.ts +45 -0
  76. package/src/theme/_internal/config/token/parseTokenValue.ts +123 -0
  77. package/src/theme/_internal/config/types.ts +137 -0
  78. package/src/theme/_internal/constants.ts +48 -0
  79. package/src/theme/_internal/helpers.ts +19 -0
  80. package/src/theme/_internal/index.ts +5 -0
  81. package/src/theme/_internal/types.ts +91 -0
  82. package/src/theme/index.ts +1 -0
  83. package/src/theme/lib/color-fns/blend/multiply.ts +2 -2
  84. package/src/theme/lib/color-fns/blend/screen.ts +2 -2
  85. package/src/theme/lib/color-fns/convert.ts +15 -1
  86. package/src/theme/lib/color-fns/parse.ts +7 -3
  87. package/src/theme/lib/color-fns/types.ts +11 -0
  88. package/src/theme/lib/theme/avatar.ts +2 -0
  89. package/src/theme/lib/theme/color/_legacy/createColorTheme.ts +7 -0
  90. package/src/theme/lib/theme/color/_legacy/index.ts +1 -0
  91. package/src/theme/lib/theme/color/_legacy/legacyColor.ts +3997 -0
  92. package/src/theme/studioTheme/color.ts +98 -82
  93. package/src/theme/studioTheme/helpers.ts +15 -1
  94. package/src/theme/studioTheme/theme.ts +5 -5
  95. package/src/theme/studioTheme/tints.ts +244 -84
  96. package/src/types/button.ts +5 -0
@@ -1,67 +1,201 @@
1
1
  /**
2
2
  * This file creates a translation between the tints and the studio colors
3
3
  * Providing readable names, and allowing to mix colors and tints in the same ThemeColor.
4
- * e.g. for positive theme: `{"bg_base": "white", "bg_base_hover": "gray/50", "bg_base_active": "cyan/50"}
4
+ * e.g. for positive theme: `{"bg_base": "white", ""bg-base-hover"": "gray/50", ""bg-base-active"": "cyan/50"}
5
5
  * This is not possible in the previous configuration, as each ThemeColor uses only one tint.
6
6
  */
7
- import {ColorTintKey, ColorTints, ColorValue, black, hues, white} from '@sanity/color'
7
+ import {ColorTintKey, ColorTints, ColorTint, black, hues, white} from '@sanity/color'
8
+ import {rgba} from '../lib/color-fns'
8
9
  import {ThemeColorName, ThemeColorSchemeKey} from '../lib/theme'
9
10
 
10
11
  export const colorKeys = [
11
- 'text_primary',
12
- 'text_secondary',
13
- 'text_inactive',
14
- 'bg_base',
15
- 'bg_base_hover',
16
- 'bg_base_active',
17
- 'bg_accent',
18
- 'bg_accent_hover',
19
- 'bg_accent_active',
20
- 'bg_tint',
21
- 'icon_default',
22
- 'icon_inverted',
23
- 'border_base',
24
- 'border_accent',
25
- 'border_accent_inverted',
12
+ 'text-primary',
13
+ 'text-secondary',
14
+ 'text-inactive',
15
+ // TODO: Can this be replaced by other of the text colors? It's used by the code html element if it's inside a text
16
+ 'text-code',
17
+ 'text-muted',
18
+ 'text-link',
19
+ 'text-accent',
20
+ 'bg-base',
21
+ 'bg-base-hover',
22
+ 'bg-base-active',
23
+ 'bg-accent',
24
+ 'bg-accent-hover',
25
+ 'bg-accent-active',
26
+ 'bg-tint',
27
+ // TODO: Can we replace this with bg_tint? It's used by the code html element if it's inside a text
28
+ 'bg-tint-code',
29
+
30
+ 'icon-default',
31
+ 'icon-inverted',
32
+ 'border-base',
33
+ 'border-base-hover',
34
+ 'border-accent',
35
+ 'border-accent-inverted',
36
+
37
+ // Colors starting with -base won't be affected by the mix function
38
+ 'base-bg-card', // This is used by the card when a tone is defined, it will also override the bg-base in the rest of the components.
39
+ 'base-bg-raw', // This is the same color as bg-base, but it won't be overridden by the card bg color, used in selectable items.
40
+
41
+ 'base-shadow-outline-color',
42
+ 'base-shadow-umbra-color',
43
+ 'base-shadow-penumbra-color',
44
+ 'base-shadow-ambient-color',
45
+ 'base-text-color', // Color used by the buttons for default mode text
46
+
47
+ 'skeleton-from',
48
+ 'skeleton-to',
26
49
  ] as const
27
50
 
28
51
  export type ColorKey = (typeof colorKeys)[number]
29
52
 
30
- type ColorTintsDictionary = Record<ColorKey, ColorTintKey | ColorValue>
53
+ type ColorWithOpacity = {
54
+ type: 'colorWithOpacity'
55
+ tint: ColorTintKey
56
+ /**
57
+ * Number between 0 and 1
58
+ */
59
+ opacity: number
60
+ }
61
+
62
+ type DefaultColor = {
63
+ type: 'colorTint'
64
+ value: ColorTint
65
+ }
66
+
67
+ type ColorTintsDictionary = Record<ColorKey, ColorTintKey | DefaultColor | ColorWithOpacity>
31
68
  const defaultTints: Record<ThemeColorSchemeKey, ColorTintsDictionary> = {
32
69
  light: {
33
- text_primary: '900',
34
- text_secondary: '600',
35
- text_inactive: '500',
36
- bg_base: white,
37
- bg_base_hover: '50',
38
- bg_base_active: '100',
39
- bg_accent: '500',
40
- bg_accent_hover: '600',
41
- bg_accent_active: '700',
42
- bg_tint: '50',
43
- icon_default: '500',
44
- icon_inverted: white,
45
- border_base: '100',
46
- border_accent: '500',
47
- border_accent_inverted: white,
70
+ 'text-primary': '900',
71
+ 'text-secondary': '600',
72
+ 'text-inactive': '500',
73
+ 'text-code': '600',
74
+ 'text-muted': '600',
75
+ 'text-link': {
76
+ type: 'colorTint',
77
+ value: hues.blue['600'],
78
+ },
79
+ 'text-accent': {
80
+ type: 'colorTint',
81
+ value: hues.red['500'],
82
+ },
83
+ 'bg-base': {
84
+ type: 'colorTint',
85
+ value: white,
86
+ },
87
+ 'bg-base-hover': '50',
88
+ 'bg-base-active': '100',
89
+ 'bg-accent': '500',
90
+ 'bg-accent-hover': '600',
91
+ 'bg-accent-active': '700',
92
+ 'bg-tint': '50',
93
+ 'bg-tint-code': '50',
94
+ 'icon-default': '500',
95
+ 'icon-inverted': {
96
+ type: 'colorTint',
97
+ value: white,
98
+ },
99
+ 'border-base': '100',
100
+ 'border-base-hover': '200',
101
+ 'border-accent': '500',
102
+ 'border-accent-inverted': {
103
+ type: 'colorTint',
104
+ value: white,
105
+ },
106
+ 'base-bg-card': '50',
107
+ 'base-bg-raw': {
108
+ type: 'colorTint',
109
+ value: white,
110
+ },
111
+ 'base-text-color': {type: 'colorTint', value: white},
112
+ 'base-shadow-outline-color': {
113
+ type: 'colorWithOpacity',
114
+ tint: '500',
115
+ opacity: 0.2,
116
+ },
117
+ 'base-shadow-umbra-color': {
118
+ type: 'colorWithOpacity',
119
+ tint: '500',
120
+ opacity: 0.1,
121
+ },
122
+ 'base-shadow-penumbra-color': {
123
+ type: 'colorWithOpacity',
124
+ tint: '500',
125
+ opacity: 0.07,
126
+ },
127
+ 'base-shadow-ambient-color': {
128
+ type: 'colorWithOpacity',
129
+ tint: '500',
130
+ opacity: 0.06,
131
+ },
132
+ 'skeleton-from': '100',
133
+ 'skeleton-to': {
134
+ type: 'colorWithOpacity',
135
+ tint: '50',
136
+ opacity: 0.5,
137
+ },
48
138
  },
49
139
  dark: {
50
- text_primary: '50',
51
- text_secondary: '300',
52
- text_inactive: '400',
53
- bg_base: black,
54
- bg_base_hover: '900',
55
- bg_base_active: '800',
56
- bg_accent: '500',
57
- bg_accent_hover: '400',
58
- bg_accent_active: '300',
59
- bg_tint: '900',
60
- icon_default: '300',
61
- icon_inverted: hues.gray[900],
62
- border_base: '800',
63
- border_accent: '300',
64
- border_accent_inverted: hues.gray[900],
140
+ 'text-primary': '50',
141
+ 'text-secondary': '300',
142
+ 'text-inactive': '400',
143
+ 'text-code': '400',
144
+ 'text-muted': '400',
145
+ 'text-link': {
146
+ type: 'colorTint',
147
+ value: hues.blue['400'],
148
+ },
149
+ 'text-accent': {
150
+ type: 'colorTint',
151
+ value: hues.red['400'],
152
+ },
153
+ 'bg-base': {type: 'colorTint', value: black},
154
+ 'bg-base-hover': '900',
155
+ 'bg-base-active': '800',
156
+ 'bg-accent': '500',
157
+ 'bg-accent-hover': '400',
158
+ 'bg-accent-active': '300',
159
+ 'bg-tint': '900',
160
+ 'bg-tint-code': '950',
161
+ 'icon-default': '300',
162
+ 'icon-inverted': {type: 'colorTint', value: hues.gray[900]},
163
+ 'border-base': '800',
164
+ 'border-base-hover': '700',
165
+ 'border-accent': '300',
166
+ 'border-accent-inverted': {type: 'colorTint', value: hues.gray[900]},
167
+ 'base-bg-card': '950',
168
+ 'base-text-color': {type: 'colorTint', value: black},
169
+ 'base-shadow-outline-color': {
170
+ type: 'colorWithOpacity',
171
+ tint: '500',
172
+ opacity: 0.4,
173
+ },
174
+ 'base-shadow-umbra-color': {
175
+ type: 'colorWithOpacity',
176
+ tint: '900',
177
+ opacity: 0.4,
178
+ },
179
+ 'base-shadow-penumbra-color': {
180
+ type: 'colorWithOpacity',
181
+ tint: '900',
182
+ opacity: 0.28,
183
+ },
184
+ 'base-shadow-ambient-color': {
185
+ type: 'colorWithOpacity',
186
+ tint: '900',
187
+ opacity: 0.24,
188
+ },
189
+ 'base-bg-raw': {
190
+ type: 'colorTint',
191
+ value: black,
192
+ },
193
+ 'skeleton-from': '900',
194
+ 'skeleton-to': {
195
+ type: 'colorWithOpacity',
196
+ tint: '50',
197
+ opacity: 0.5,
198
+ },
65
199
  },
66
200
  }
67
201
 
@@ -72,81 +206,107 @@ export const colorTints: Record<
72
206
  light: {
73
207
  default: {
74
208
  ...defaultTints.light,
75
- bg_accent: '900',
76
- bg_accent_hover: '950',
77
- bg_accent_active: black,
78
- border_accent: '600',
209
+ 'base-bg-card': {type: 'colorTint', value: white},
210
+ 'bg-accent': '900',
211
+ 'bg-accent-hover': '950',
212
+ 'bg-accent-active': {type: 'colorTint', value: black},
213
+ 'border-accent': '600',
79
214
  },
80
215
  primary: {
81
216
  ...defaultTints.light,
82
- bg_accent: '900',
83
- bg_accent_hover: '950',
84
- bg_accent_active: black,
85
- border_accent: '600',
217
+ 'bg-accent': '900',
218
+ 'bg-accent-hover': '950',
219
+ 'bg-accent-active': {type: 'colorTint', value: black},
220
+ 'border-accent': '600',
86
221
  },
87
222
  positive: {
88
223
  ...defaultTints.light,
89
- bg_base_hover: hues.gray[50],
90
- bg_base_active: '50',
91
- bg_accent: '400',
92
- bg_accent_hover: '500',
93
- bg_accent_active: '600',
94
- border_accent: '400',
224
+ 'bg-base-hover': {type: 'colorTint', value: hues.gray[50]},
225
+ 'bg-base-active': '50',
226
+ 'bg-accent': '400',
227
+ 'bg-accent-hover': '500',
228
+ 'bg-accent-active': '600',
229
+ 'border-accent': '400',
95
230
  },
96
231
  transparent: defaultTints.light,
97
232
  caution: defaultTints.light,
98
- critical: defaultTints.light,
233
+ critical: {...defaultTints.light, 'text-inactive': '300'},
99
234
  },
100
235
  dark: {
101
236
  default: {
102
237
  ...defaultTints.dark,
103
- text_primary: white,
104
- bg_accent: white,
105
- bg_accent_hover: '50',
106
- bg_accent_active: '100',
238
+ 'base-bg-card': {type: 'colorTint', value: black},
239
+ 'text-primary': {type: 'colorTint', value: white},
240
+ 'bg-accent': {type: 'colorTint', value: white},
241
+ 'bg-accent-hover': '50',
242
+ 'bg-accent-active': '100',
243
+ 'base-shadow-umbra-color': {
244
+ type: 'colorWithOpacity',
245
+ tint: '950',
246
+ opacity: 0.4,
247
+ },
248
+ 'base-shadow-penumbra-color': {
249
+ type: 'colorWithOpacity',
250
+ tint: '950',
251
+ opacity: 0.28,
252
+ },
253
+ 'base-shadow-ambient-color': {
254
+ type: 'colorWithOpacity',
255
+ tint: '950',
256
+ opacity: 0.24,
257
+ },
107
258
  },
108
259
  primary: {
109
260
  ...defaultTints.dark,
110
- text_primary: white,
111
- bg_accent: white,
112
- bg_accent_hover: '50',
113
- bg_accent_active: '100',
261
+ 'text-primary': {type: 'colorTint', value: white},
262
+ 'bg-accent': {type: 'colorTint', value: white},
263
+ 'bg-accent-hover': '50',
264
+ 'bg-accent-active': '100',
114
265
  },
115
266
  positive: {
116
267
  ...defaultTints.dark,
117
- bg_base_hover: hues.gray[900],
118
- bg_base_active: '900',
119
- bg_accent: '400',
120
- bg_accent_hover: '300',
121
- bg_accent_active: '200',
122
- border_accent: '400',
268
+ 'bg-base-hover': {type: 'colorTint', value: hues.gray[900]},
269
+ 'bg-base-active': '900',
270
+ 'bg-accent': '400',
271
+ 'bg-accent-hover': '300',
272
+ 'bg-accent-active': '200',
273
+ 'border-accent': '400',
123
274
  },
124
275
  transparent: defaultTints.dark,
125
276
  caution: defaultTints.dark,
126
- critical: defaultTints.dark,
277
+ critical: {...defaultTints.dark, 'text-inactive': '700'},
127
278
  },
128
279
  }
129
280
 
130
281
  export const getColorValue = (
131
282
  tints: ColorTints,
132
- dark: boolean,
283
+ scheme: ThemeColorSchemeKey,
133
284
  tone: ThemeColorName,
134
285
  key: ColorKey,
135
- ): ColorValue => {
136
- const value = colorTints[dark ? 'dark' : 'light'][tone][key]
286
+ ): ColorTint => {
287
+ const value = colorTints[scheme][tone][key]
137
288
 
138
289
  if (typeof value === 'string') {
139
290
  return tints[value]
140
291
  }
141
292
 
142
- return value
293
+ if (value.type === 'colorWithOpacity') {
294
+ const base = tints[value.tint]
295
+
296
+ return {
297
+ hex: rgba(base.hex, value.opacity),
298
+ title: `${base.title} ${Math.round(value.opacity * 100)}%`,
299
+ }
300
+ }
301
+
302
+ return value.value
143
303
  }
144
304
 
145
305
  export const getColorHex = (
146
306
  tints: ColorTints,
147
- dark: boolean,
307
+ scheme: ThemeColorSchemeKey,
148
308
  tone: ThemeColorName,
149
309
  key: ColorKey,
150
310
  ): string => {
151
- return getColorValue(tints, dark, tone, key).hex
311
+ return getColorValue(tints, scheme, tone, key).hex
152
312
  }
@@ -12,3 +12,8 @@ export type ButtonTextAlign = 'left' | 'right' | 'center'
12
12
  * @public
13
13
  */
14
14
  export type ButtonTone = 'default' | 'primary' | 'positive' | 'caution' | 'critical'
15
+
16
+ /**
17
+ * @public
18
+ */
19
+ export type ButtonWidth = 'fill'