@sanity/ui 2.0.0-beta.10 → 2.0.0-beta.11

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.0.0-beta.10",
3
+ "version": "2.0.0-beta.11",
4
4
  "sideEffects": false,
5
5
  "types": "./dist/index.d.ts",
6
6
  "source": "./exports/index.ts",
@@ -62,7 +62,7 @@ function TextInputTest(props: {inputRef: React.Ref<HTMLInputElement>}) {
62
62
  ) as IconSymbol
63
63
  const padding = useSelect('Padding', WORKSHOP_SPACE_OPTIONS, 3, 'Props')
64
64
  const placeholder = useText('Placeholder', '', 'Props') || undefined
65
- const radius = useSelect('Radius', WORKSHOP_RADIUS_OPTIONS, 0, 'Props')
65
+ const radius = useSelect('Radius', WORKSHOP_RADIUS_OPTIONS, 2, 'Props')
66
66
  const readOnly = useBoolean('Read only', false, 'Props')
67
67
  const space = useSelect('Space', WORKSHOP_SPACE_OPTIONS, 3, 'Props')
68
68
  const weight = useSelect('Weight', WORKSHOP_FONT_WEIGHT_OPTIONS, '', 'Props') || undefined
@@ -1,7 +1,8 @@
1
1
  import {Container, Flex, Stack, Text, TextInput} from '@sanity/ui'
2
- import {useAction} from '@sanity/ui-workshop'
2
+ import {useAction, useBoolean} from '@sanity/ui-workshop'
3
3
 
4
4
  export default function StatesStory() {
5
+ const invalid = useBoolean('Invalid', false, 'Props')
5
6
  const onChange = useAction('onChange')
6
7
 
7
8
  return (
@@ -12,7 +13,12 @@ export default function StatesStory() {
12
13
  <Text size={1} weight="medium">
13
14
  <label htmlFor="enabled-example">Enabled (default)</label>
14
15
  </Text>
15
- <TextInput id="enabled-example" onChange={onChange} value="This is some text" />
16
+ <TextInput
17
+ customValidity={invalid ? 'invalid' : undefined}
18
+ id="enabled-example"
19
+ onChange={onChange}
20
+ value="This is some text"
21
+ />
16
22
  </Stack>
17
23
 
18
24
  <Stack space={3}>
@@ -20,6 +26,7 @@ export default function StatesStory() {
20
26
  <label htmlFor="disabled-example">Disabled</label>
21
27
  </Text>
22
28
  <TextInput
29
+ customValidity={invalid ? 'invalid' : undefined}
23
30
  disabled
24
31
  id="disabled-example"
25
32
  onChange={onChange}
@@ -32,6 +39,7 @@ export default function StatesStory() {
32
39
  <label htmlFor="read-only-example">Read-only</label>
33
40
  </Text>
34
41
  <TextInput
42
+ customValidity={invalid ? 'invalid' : undefined}
35
43
  id="read-only-example"
36
44
  readOnly
37
45
  onChange={onChange}
@@ -195,9 +195,10 @@ export function textInputRepresentationStyle(
195
195
  }
196
196
 
197
197
  /* disabled */
198
- *:disabled + & {
198
+ *:not(:invalid):disabled + & {
199
199
  --card-bg-color: ${color.input.default.disabled.bg} !important;
200
200
  --card-fg-color: ${color.input.default.disabled.fg} !important;
201
+ --card-icon-color: ${color.input.default.disabled.fg} !important;
201
202
 
202
203
  &[data-border] {
203
204
  --input-box-shadow: ${focusRingBorderStyle({
@@ -207,12 +208,30 @@ export function textInputRepresentationStyle(
207
208
  }
208
209
  }
209
210
 
211
+ *:invalid:disabled + & {
212
+ --card-bg-color: ${color.input.invalid.disabled.bg} !important;
213
+ --card-fg-color: ${color.input.invalid.disabled.fg} !important;
214
+ --card-icon-color: ${color.input.invalid.disabled.fg} !important;
215
+
216
+ &[data-border] {
217
+ --input-box-shadow: ${focusRingBorderStyle({
218
+ color: color.input.invalid.disabled.border,
219
+ width: input.border.width,
220
+ })};
221
+ }
222
+ }
223
+
210
224
  /* readOnly */
211
- *:read-only + & {
225
+ *:not(:invalid):read-only + & {
212
226
  --card-bg-color: ${color.input.default.readOnly.bg} !important;
213
227
  --card-fg-color: ${color.input.default.readOnly.fg} !important;
214
228
  }
215
229
 
230
+ *:invalid:read-only + & {
231
+ --card-bg-color: ${color.input.invalid.readOnly.bg} !important;
232
+ --card-fg-color: ${color.input.invalid.readOnly.fg} !important;
233
+ }
234
+
216
235
  /* hovered */
217
236
  @media (hover: hover) {
218
237
  *:not(:disabled):not(:read-only):not(:invalid):hover + & {
@@ -220,12 +239,24 @@ export function textInputRepresentationStyle(
220
239
  --card-fg-color: ${color.input.default.hovered.fg};
221
240
  }
222
241
 
242
+ *:invalid:not(:disabled):not(:read-only):hover + & {
243
+ --card-bg-color: ${color.input.invalid.hovered.bg};
244
+ --card-fg-color: ${color.input.invalid.hovered.fg};
245
+ }
246
+
223
247
  *:not(:disabled):not(:read-only):not(:invalid):not(:focus):hover + &[data-border] {
224
248
  --input-box-shadow: ${focusRingBorderStyle({
225
249
  color: color.input.default.hovered.border,
226
250
  width: input.border.width,
227
251
  })};
228
252
  }
253
+
254
+ *:invalid:not(:disabled):not(:read-only):not(:focus):hover + &[data-border] {
255
+ --input-box-shadow: ${focusRingBorderStyle({
256
+ color: color.input.invalid.hovered.border,
257
+ width: input.border.width,
258
+ })};
259
+ }
229
260
  }
230
261
  }
231
262
  `
@@ -1,3 +1,4 @@
1
+ import {CropIcon} from '@sanity/icons'
1
2
  import {
2
3
  THEME_COLOR_BUTTON_MODES,
3
4
  THEME_COLOR_CARD_TONES,
@@ -8,6 +9,7 @@ import {
8
9
  ThemeColorScheme_v2,
9
10
  ThemeColorState_v2,
10
11
  } from '@sanity/ui/theme'
12
+ import {useBoolean} from '@sanity/ui-workshop'
11
13
  import {CSSProperties} from 'react'
12
14
  import {Badge, Box, Flex, KBD, Stack, Text} from '../../../primitives'
13
15
  import {useRootTheme} from '../../useRootTheme'
@@ -27,17 +29,23 @@ export default function DebugStory() {
27
29
  function DebugScheme(props: {scheme: ThemeColorScheme_v2}) {
28
30
  const {scheme} = props
29
31
 
32
+ const button = useBoolean('Button', false, 'Props') || false
33
+ const selectable = useBoolean('Selectable', false, 'Props') || false
34
+
30
35
  return (
31
36
  <Box flex={1} style={{backgroundColor: scheme.default.bg}}>
32
37
  {THEME_COLOR_CARD_TONES.map((tone) => (
33
- <DebugCard card={scheme[tone]} key={tone} />
38
+ <DebugCard card={scheme[tone]} features={{button, selectable}} key={tone} />
34
39
  ))}
35
40
  </Box>
36
41
  )
37
42
  }
38
43
 
39
- function DebugCard(props: {card: ThemeColorCard_v2}) {
40
- const {card} = props
44
+ function DebugCard(props: {
45
+ card: ThemeColorCard_v2
46
+ features: {button: boolean; selectable: boolean}
47
+ }) {
48
+ const {card, features} = props
41
49
 
42
50
  // card.avatar
43
51
  // card.backdrop
@@ -56,27 +64,44 @@ function DebugCard(props: {card: ThemeColorCard_v2}) {
56
64
  return (
57
65
  <Box style={getStateVars(card)}>
58
66
  <DebugState />
59
- <Stack padding={2} space={1}>
60
- {THEME_COLOR_BUTTON_MODES.map((mode) => (
61
- <Stack key={mode} space={1}>
62
- {THEME_COLOR_STATE_TONES.map((stateTone) => (
63
- <Flex key={stateTone} gap={1}>
64
- {/* {mode} */}
65
- {THEME_COLOR_STATES.map((state) => (
66
- <Box
67
- flex={1}
68
- key={state}
69
- style={getStateVars(card.button[mode][stateTone][state])}
70
- >
71
- <DebugState />
72
- {/* {state} */}
73
- </Box>
74
- ))}
75
- </Flex>
76
- ))}
77
- </Stack>
78
- ))}
79
- </Stack>
67
+
68
+ {features.button && (
69
+ <Stack padding={2} space={1}>
70
+ {THEME_COLOR_BUTTON_MODES.map((mode) => (
71
+ <Stack key={mode} space={1}>
72
+ {THEME_COLOR_STATE_TONES.map((stateTone) => (
73
+ <Flex key={stateTone} gap={1}>
74
+ {/* {mode} */}
75
+ {THEME_COLOR_STATES.map((state) => (
76
+ <Box
77
+ flex={1}
78
+ key={state}
79
+ style={getStateVars(card.button[mode][stateTone][state])}
80
+ >
81
+ <DebugState />
82
+ </Box>
83
+ ))}
84
+ </Flex>
85
+ ))}
86
+ </Stack>
87
+ ))}
88
+ </Stack>
89
+ )}
90
+
91
+ {features.selectable && (
92
+ <Stack padding={2} space={1}>
93
+ {THEME_COLOR_STATE_TONES.map((stateTone) => (
94
+ <Flex key={stateTone} gap={1}>
95
+ {/* {mode} */}
96
+ {THEME_COLOR_STATES.map((state) => (
97
+ <Box flex={1} key={state} style={getStateVars(card.selectable[stateTone][state])}>
98
+ <DebugState />
99
+ </Box>
100
+ ))}
101
+ </Flex>
102
+ ))}
103
+ </Stack>
104
+ )}
80
105
  </Box>
81
106
  )
82
107
  }
@@ -89,7 +114,12 @@ function DebugState() {
89
114
  space={3}
90
115
  style={{border: '1px solid var(--card-border-color)'}}
91
116
  >
92
- <Text size={1}>Text</Text>
117
+ <Flex gap={3}>
118
+ <Text size={1}>Text</Text>
119
+ <Text size={1}>
120
+ <CropIcon />
121
+ </Text>
122
+ </Flex>
93
123
  <Text muted size={1}>
94
124
  Muted
95
125
  </Text>
@@ -116,13 +146,20 @@ function DebugState() {
116
146
 
117
147
  function getStateVars(state: ThemeColorState_v2) {
118
148
  return {
149
+ '--card-accent-fg-color': state.accent.fg,
150
+
151
+ '--card-code-bg-color': state.code.bg,
152
+ '--card-code-fg-color': state.code.fg,
153
+
119
154
  '--card-bg-color': state.bg,
155
+
120
156
  '--card-border-color': state.border,
157
+
121
158
  '--card-fg-color': state.fg,
122
- '--card-accent-fg-color': state.accent.fg,
159
+
160
+ '--card-icon-color': state.icon,
161
+
123
162
  '--card-muted-fg-color': state.muted.fg,
124
- '--card-code-bg-color': state.code.bg,
125
- '--card-code-fg-color': state.code.fg,
126
163
 
127
164
  '--card-kbd-bg-color': state.kbd.bg,
128
165
  '--card-kbd-border-color': state.kbd.border,
@@ -65,7 +65,7 @@ test('buildColorTheme: base', () => {
65
65
  light: {
66
66
  transparent: {
67
67
  bg: 'gray/50',
68
- fg: 'gray/600',
68
+ fg: 'gray/800',
69
69
  },
70
70
  default: {
71
71
  bg: 'white',
@@ -79,7 +79,7 @@ test('buildColorTheme: base', () => {
79
79
  dark: {
80
80
  transparent: {
81
81
  bg: 'black',
82
- fg: 'gray/400',
82
+ fg: 'gray/200',
83
83
  },
84
84
  default: {
85
85
  bg: 'gray/950',
@@ -35,10 +35,11 @@ export const defaultColorTokens: ThemeColorTokens = {
35
35
  border: ['200', '800'],
36
36
  code: {
37
37
  bg: ['50', '950'],
38
- fg: ['600', '300'],
38
+ fg: ['600', '400'],
39
39
  },
40
40
  fg: ['800', '200'],
41
41
  focusRing: ['blue/500', 'blue/500'],
42
+ icon: ['600', '400'],
42
43
  kbd: {
43
44
  bg: ['white', 'black'],
44
45
  fg: ['600', '400'],
@@ -49,7 +50,7 @@ export const defaultColorTokens: ThemeColorTokens = {
49
50
  },
50
51
  muted: {
51
52
  bg: ['50', '950'],
52
- fg: ['700 70%', '300 70%'],
53
+ fg: ['700 75%', '300 75%'],
53
54
  },
54
55
  shadow: {
55
56
  outline: ['500/0.3', '500/0.4'],
@@ -64,14 +65,10 @@ export const defaultColorTokens: ThemeColorTokens = {
64
65
  },
65
66
  transparent: {
66
67
  bg: ['50', 'black'],
67
- fg: ['600', '400'],
68
- muted: {
69
- fg: ['600', '400'],
70
- },
71
68
  },
72
69
  default: {
73
70
  bg: ['white', '950'],
74
- fg: ['black', '200'],
71
+ fg: ['800', '200'],
75
72
  muted: {
76
73
  fg: ['600', '400'],
77
74
  },
@@ -95,6 +92,13 @@ export const defaultColorTokens: ThemeColorTokens = {
95
92
  accent: {
96
93
  fg: ['purple/300', 'purple/700'],
97
94
  },
95
+ avatar: {
96
+ '*': {
97
+ _blend: ['multiply', 'screen'],
98
+ bg: ['white', 'black'],
99
+ fg: ['black', 'white'],
100
+ },
101
+ },
98
102
  badge: {
99
103
  '*': {
100
104
  bg: ['900', '100'],
@@ -110,18 +114,18 @@ export const defaultColorTokens: ThemeColorTokens = {
110
114
  fg: ['200', '600'],
111
115
  },
112
116
  fg: ['white', 'black'],
113
- icon: ['200', '800'],
117
+ icon: ['100 70%', '900 70%'],
114
118
  kbd: {
115
119
  bg: ['black', 'white'],
116
- fg: ['200', '800'],
120
+ fg: ['200', '600'],
117
121
  border: ['800', '200'],
118
122
  },
119
123
  link: {
120
- fg: ['blue/200', 'blue/700'],
124
+ fg: ['blue/200', 'blue/600'],
121
125
  },
122
126
  muted: {
123
127
  bg: ['950', '50'],
124
- fg: ['100 70%', '600'],
128
+ fg: ['100 70%', '900 70%'],
125
129
  },
126
130
  skeleton: {
127
131
  from: ['900', '100'],
@@ -140,6 +144,9 @@ export const defaultColorTokens: ThemeColorTokens = {
140
144
  },
141
145
  disabled: {
142
146
  _hue: 'gray',
147
+ accent: {
148
+ fg: ['100 70%', '900 70%'],
149
+ },
143
150
  badge: {
144
151
  '*': {
145
152
  bg: ['gray/700', 'gray/300'],
@@ -149,12 +156,14 @@ export const defaultColorTokens: ThemeColorTokens = {
149
156
  },
150
157
  },
151
158
  bg: ['200', '800'],
152
- icon: ['white', 'black'],
153
159
  kbd: {
154
160
  bg: ['black', 'white'],
155
161
  fg: ['white', 'black'],
156
162
  border: ['700', '300'],
157
163
  },
164
+ link: {
165
+ fg: ['100 70%', '900 70%'],
166
+ },
158
167
  },
159
168
  },
160
169
  default: {
@@ -198,7 +207,7 @@ export const defaultColorTokens: ThemeColorTokens = {
198
207
  fg: ['700 60%', '400 60%'],
199
208
  },
200
209
  fg: ['600', '400'],
201
- icon: ['600', '500'],
210
+ icon: ['700 60%', '300 60%'],
202
211
  kbd: {
203
212
  bg: ['white', 'black'],
204
213
  fg: ['600', '400'],
@@ -291,14 +300,14 @@ export const defaultColorTokens: ThemeColorTokens = {
291
300
  bg: ['white', 'black'],
292
301
  border: ['white/0', 'black/0'],
293
302
  code: {
294
- bg: ['100', '950'],
295
- fg: ['600', '300'],
303
+ bg: ['50', '950'],
304
+ fg: ['700 75%', '300 75%'],
296
305
  },
297
306
  fg: ['700', '300'],
298
- icon: ['700 70%', '300 70%'],
307
+ icon: ['700 75%', '300 75%'],
299
308
  kbd: {
300
309
  bg: ['white', 'black'],
301
- fg: ['600', '400'],
310
+ fg: ['700', '300'],
302
311
  border: ['200', '800'],
303
312
  },
304
313
  link: {
@@ -306,7 +315,7 @@ export const defaultColorTokens: ThemeColorTokens = {
306
315
  },
307
316
  muted: {
308
317
  bg: ['100', '950'],
309
- fg: ['700 70%', '300 70%'],
318
+ fg: ['700 75%', '300 75%'],
310
319
  },
311
320
  skeleton: {
312
321
  from: ['100', '900'],
@@ -315,7 +324,6 @@ export const defaultColorTokens: ThemeColorTokens = {
315
324
  },
316
325
  hovered: {
317
326
  bg: ['50', '950'],
318
- fg: ['700', '300'],
319
327
  icon: ['700 70%', '400 70%'],
320
328
  },
321
329
  pressed: {
@@ -330,6 +338,9 @@ export const defaultColorTokens: ThemeColorTokens = {
330
338
  },
331
339
  disabled: {
332
340
  _hue: 'gray',
341
+ accent: {
342
+ fg: ['200', '800'],
343
+ },
333
344
  badge: {
334
345
  '*': {
335
346
  _hue: 'gray',
@@ -339,13 +350,12 @@ export const defaultColorTokens: ThemeColorTokens = {
339
350
  icon: ['gray/200', 'gray/800'],
340
351
  },
341
352
  },
342
- fg: ['200', '800'],
343
- muted: {
344
- fg: ['200', '800'],
345
- },
346
- accent: {
353
+ code: {
354
+ bg: ['50', '950'],
347
355
  fg: ['200', '800'],
348
356
  },
357
+ fg: ['200', '800'],
358
+ icon: ['200', '800'],
349
359
  kbd: {
350
360
  bg: ['white', 'black'],
351
361
  fg: ['200', '800'],
@@ -354,8 +364,7 @@ export const defaultColorTokens: ThemeColorTokens = {
354
364
  link: {
355
365
  fg: ['200', '800'],
356
366
  },
357
- code: {
358
- bg: ['50', '950'],
367
+ muted: {
359
368
  fg: ['200', '800'],
360
369
  },
361
370
  },
@@ -398,15 +407,8 @@ export const defaultColorTokens: ThemeColorTokens = {
398
407
  '*': {
399
408
  '*': {
400
409
  _blend: ['multiply', 'screen'],
401
- bg: ['white', 'black'],
402
- fg: ['800', '200'],
403
- icon: ['700 70%', '300 70%'],
404
- avatar: {
405
- '*': {
406
- _blend: ['screen', 'multiply'],
407
- bg: ['500', '400'],
408
- fg: ['white', 'black'],
409
- },
410
+ accent: {
411
+ fg: ['purple/700 70%', 'purple/300 70%'],
410
412
  },
411
413
  badge: {
412
414
  '*': {
@@ -416,25 +418,25 @@ export const defaultColorTokens: ThemeColorTokens = {
416
418
  icon: ['500', '500'],
417
419
  },
418
420
  },
421
+ bg: ['white', 'black'],
419
422
  border: ['200', '800'],
420
- muted: {
423
+ code: {
421
424
  bg: ['50', '950'],
422
- fg: ['700', '300'],
423
- },
424
- accent: {
425
- fg: ['purple/600', 'purple/400'],
425
+ fg: ['600', '400'],
426
426
  },
427
+ fg: ['700', '300'],
428
+ icon: ['700 75%', '300 75%'],
427
429
  kbd: {
428
430
  bg: ['white', 'black'],
429
431
  fg: ['600', '400'],
430
432
  border: ['200', '800'],
431
433
  },
432
434
  link: {
433
- fg: ['blue/700', 'blue/300'],
435
+ fg: ['blue/700 70%', 'blue/300 70%'],
434
436
  },
435
- code: {
436
- bg: ['50', '950'],
437
- fg: ['700', '300'],
437
+ muted: {
438
+ bg: ['100', '950'],
439
+ fg: ['700 75%', '300 75%'],
438
440
  },
439
441
  skeleton: {
440
442
  from: ['100', '900'],
@@ -449,9 +451,9 @@ export const defaultColorTokens: ThemeColorTokens = {
449
451
  },
450
452
  selected: {
451
453
  _blend: ['screen', 'multiply'],
452
- bg: ['500', '400'],
453
- fg: ['white', 'black'],
454
- icon: ['200', '800'],
454
+ accent: {
455
+ fg: ['purple/300', 'purple/700'],
456
+ },
455
457
  avatar: {
456
458
  '*': {
457
459
  _blend: ['multiply', 'screen'],
@@ -461,31 +463,31 @@ export const defaultColorTokens: ThemeColorTokens = {
461
463
  },
462
464
  badge: {
463
465
  '*': {
464
- bg: ['700', '300'],
465
- fg: ['white', 'black'],
466
- dot: ['300', '700'],
467
- icon: ['300', '700'],
466
+ bg: ['900', '100'],
467
+ fg: ['400', '600'],
468
+ dot: ['500', '500'],
469
+ icon: ['500', '500'],
468
470
  },
469
471
  },
472
+ bg: ['500', '400'],
470
473
  border: ['500 20%', '400 20%'],
471
- muted: {
472
- bg: ['950', '50'],
473
- fg: ['200', '800'],
474
- },
475
- accent: {
476
- fg: ['purple/200', 'purple/800'],
474
+ code: {
475
+ bg: ['500 20%', '400 20%'],
476
+ fg: ['200', '600'],
477
477
  },
478
+ fg: ['white', 'black'],
479
+ icon: ['100 70%', '900 70%'],
478
480
  kbd: {
479
- bg: ['black/0', 'white/0'],
480
- fg: ['white', 'black'],
481
- border: ['gray/700', 'gray/300'],
481
+ bg: ['black', 'white'],
482
+ fg: ['200', '600'],
483
+ border: ['800', '200'],
482
484
  },
483
485
  link: {
484
- fg: ['blue/200', 'blue/800'],
486
+ fg: ['blue/200', 'blue/600'],
485
487
  },
486
- code: {
487
- bg: ['500 20%', '400 20%'],
488
- fg: ['300', '700'],
488
+ muted: {
489
+ bg: ['950', '50'],
490
+ fg: ['100 70%', '900 70%'],
489
491
  },
490
492
  skeleton: {
491
493
  from: ['900', '100'],
@@ -493,19 +495,35 @@ export const defaultColorTokens: ThemeColorTokens = {
493
495
  },
494
496
  },
495
497
  disabled: {
498
+ _hue: 'gray',
499
+ accent: {
500
+ fg: ['200', '800'],
501
+ },
502
+ badge: {
503
+ '*': {
504
+ _hue: 'gray',
505
+ bg: ['50', '950'],
506
+ fg: ['gray/200', 'gray/800'],
507
+ dot: ['gray/200', 'gray/800'],
508
+ icon: ['gray/200', 'gray/800'],
509
+ },
510
+ },
511
+ border: ['100', '900'],
512
+ code: {
513
+ bg: ['50', '950'],
514
+ fg: ['200', '800'],
515
+ },
496
516
  fg: ['200', '800'],
497
517
  icon: ['200', '800'],
498
- muted: {
518
+ kbd: {
519
+ bg: ['white', 'black'],
499
520
  fg: ['200', '800'],
500
- },
501
- accent: {
502
- fg: ['purple/200', 'purple/800'],
521
+ border: ['100', '900'],
503
522
  },
504
523
  link: {
505
- fg: ['blue/200', 'blue/800'],
524
+ fg: ['200', '800'],
506
525
  },
507
- code: {
508
- bg: ['50', '950'],
526
+ muted: {
509
527
  fg: ['200', '800'],
510
528
  },
511
529
  },