@sanity/ui 1.8.2 → 2.0.0-alpha.2

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 (49) hide show
  1. package/dist/index.d.ts +42 -11
  2. package/dist/index.esm.js +335 -116
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +334 -115
  5. package/dist/index.js.map +1 -1
  6. package/package.json +34 -16
  7. package/src/components/autocomplete/autocomplete.tsx +2 -1
  8. package/src/components/dialog/dialog.tsx +3 -3
  9. package/src/components/hotkeys/hotkeys.tsx +2 -1
  10. package/src/components/menu/menuButton.tsx +2 -2
  11. package/src/components/menu/menuGroup.tsx +2 -2
  12. package/src/components/tab/tab.tsx +2 -1
  13. package/src/primitives/avatar/styles.ts +1 -1
  14. package/src/primitives/button/button.tsx +6 -7
  15. package/src/primitives/button/styles.ts +20 -3
  16. package/src/primitives/card/styles.ts +1 -1
  17. package/src/primitives/checkbox/checkbox.tsx +1 -0
  18. package/src/primitives/checkbox/styles.ts +47 -17
  19. package/src/primitives/kbd/kbd.tsx +6 -6
  20. package/src/primitives/popover/popoverCard.tsx +2 -2
  21. package/src/primitives/radio/radio.tsx +1 -0
  22. package/src/primitives/radio/styles.ts +17 -4
  23. package/src/primitives/select/select.tsx +3 -2
  24. package/src/primitives/select/styles.ts +2 -1
  25. package/src/primitives/switch/__workshop__/props.tsx +4 -4
  26. package/src/primitives/switch/styles.ts +19 -12
  27. package/src/primitives/text/styles.ts +1 -0
  28. package/src/primitives/textInput/textInput.tsx +2 -1
  29. package/src/primitives/tooltip/tooltip.tsx +2 -2
  30. package/src/primitives/types.ts +3 -2
  31. package/src/styles/colorVars/colorVarsStyle.ts +2 -0
  32. package/src/styles/focusRing/index.ts +3 -1
  33. package/src/styles/input/textInputStyle.ts +2 -1
  34. package/src/styles/radius/radiusStyle.ts +14 -4
  35. package/src/styles/radius/types.ts +3 -1
  36. package/src/theme/lib/theme/avatar.ts +3 -0
  37. package/src/theme/lib/theme/color/_generic/types.ts +1 -0
  38. package/src/theme/lib/theme/color/color.test.ts +1 -0
  39. package/src/theme/lib/theme/color/defaults.ts +8 -0
  40. package/src/theme/lib/theme/color/input/types.ts +1 -0
  41. package/src/theme/lib/theme/input.ts +11 -0
  42. package/src/theme/lib/theme/theme.ts +7 -1
  43. package/src/theme/studioTheme/color.ts +82 -70
  44. package/src/theme/studioTheme/fonts.ts +3 -3
  45. package/src/theme/studioTheme/theme.ts +17 -3
  46. package/src/theme/studioTheme/tints.ts +152 -0
  47. package/src/theme/types.ts +8 -0
  48. package/src/types/index.ts +1 -0
  49. package/src/types/radius.ts +4 -0
@@ -36,12 +36,13 @@ export function switchInputStyles(): ReturnType<typeof css> {
36
36
  /* Representation */
37
37
  export function switchRepresentationStyles(props: ThemeProps): ReturnType<typeof css> {
38
38
  const {theme} = props
39
- const {focusRing, input} = theme.sanity
40
- const color = theme.sanity.color.button.default
39
+ const {input} = theme.sanity
40
+ const {focusRing} = input.switch
41
+ const color = theme.sanity.color.input
41
42
 
42
43
  return css`
43
- --switch-bg-color: ${color.default.enabled.bg};
44
- --switch-fg-color: ${color.default.enabled.fg};
44
+ --switch-bg-color: ${color.default.enabled.border};
45
+ --switch-fg-color: ${color.default.enabled.bg};
45
46
  --switch-box-shadow: none;
46
47
 
47
48
  &:not([hidden]) {
@@ -78,25 +79,30 @@ export function switchRepresentationStyles(props: ThemeProps): ReturnType<typeof
78
79
  }
79
80
 
80
81
  input:checked + && {
81
- --switch-bg-color: ${color.positive.enabled.bg};
82
- --switch-fg-color: ${color.positive.enabled.fg};
82
+ --switch-bg-color: var(--card-focus-ring-color);
83
+ --switch-fg-color: ${color.default.enabled.bg};
83
84
  }
84
85
 
85
86
  @media (hover: hover) {
86
87
  input:not(:disabled):hover + && {
87
- --switch-bg-color: ${color.default.hovered.bg};
88
- --switch-fg-color: ${color.default.hovered.fg};
88
+ --switch-bg-color: ${color.default.hovered.border};
89
+ --switch-fg-color: ${color.default.hovered.bg};
89
90
  }
90
91
 
91
92
  input:not(:disabled):checked:hover + && {
92
- --switch-bg-color: ${color.positive.hovered.bg};
93
- --switch-fg-color: ${color.positive.hovered.fg};
93
+ --switch-bg-color: var(--card-focus-ring-color);
94
+ --switch-fg-color: ${color.default.enabled.bg};
94
95
  }
95
96
  }
96
97
 
97
98
  input:not([data-read-only]):disabled + && {
98
- --switch-bg-color: ${color.default.disabled.bg};
99
- --switch-fg-color: ${color.default.disabled.fg};
99
+ --switch-bg-color: ${color.default.disabled.border};
100
+ --switch-fg-color: ${color.default.disabled.bg};
101
+ }
102
+
103
+ input[data-read-only]:disabled + && {
104
+ --switch-bg-color: ${color.default.readOnly.border};
105
+ --switch-fg-color: ${color.default.readOnly.bg};
100
106
  }
101
107
  `
102
108
  }
@@ -149,6 +155,7 @@ export function switchThumbStyles(
149
155
  transition-timing-function: ${input.switch.transitionTimingFunction};
150
156
  background: var(--switch-fg-color);
151
157
  transform: translate3d(0, 0, 0);
158
+ box-shadow: 0px 1px 0px 0px rgba(0, 0, 0, 0.1);
152
159
 
153
160
  ${checked &&
154
161
  css`
@@ -62,6 +62,7 @@ export function textBaseStyle(
62
62
 
63
63
  & [data-sanity-icon] {
64
64
  vertical-align: baseline;
65
+ color: var(--card-icon-color);
65
66
  }
66
67
  `
67
68
  }
@@ -17,6 +17,7 @@ import {
17
17
  textInputRootStyle,
18
18
  } from '../../styles/internal'
19
19
  import {ThemeFontWeightKey, useRootTheme} from '../../theme'
20
+ import {Radius} from '../../types'
20
21
  import {Box} from '../box'
21
22
  import {Button, ButtonProps} from '../button'
22
23
  import {Card} from '../card'
@@ -64,7 +65,7 @@ export interface TextInputProps {
64
65
  onClear?: () => void
65
66
  padding?: number | number[]
66
67
  prefix?: React.ReactNode
67
- radius?: number | number[]
68
+ radius?: Radius | Radius[]
68
69
  space?: number | number[]
69
70
  suffix?: React.ReactNode
70
71
  type?: TextInputType
@@ -81,7 +81,7 @@ export const Tooltip = forwardRef(function Tooltip(
81
81
  disabled,
82
82
  fallbackPlacements: fallbackPlacementsProp = props.fallbackPlacements ??
83
83
  DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
84
- padding,
84
+ padding = 3,
85
85
  placement: placementProp = 'bottom',
86
86
  portal,
87
87
  scheme,
@@ -303,7 +303,7 @@ export const Tooltip = forwardRef(function Tooltip(
303
303
  data-ui="Tooltip__card"
304
304
  data-placement={placement}
305
305
  padding={padding}
306
- radius={2}
306
+ radius={3}
307
307
  scheme={scheme}
308
308
  shadow={shadow}
309
309
  >
@@ -17,6 +17,7 @@ import {
17
17
  GridItemRow,
18
18
  GridItemRowEnd,
19
19
  GridItemRowStart,
20
+ Radius,
20
21
  } from '../types'
21
22
 
22
23
  /**
@@ -113,7 +114,7 @@ export interface ResponsivePaddingProps {
113
114
  * @public
114
115
  */
115
116
  export interface ResponsiveRadiusProps {
116
- radius?: number | number[]
117
+ radius?: Radius | Radius[]
117
118
  }
118
119
 
119
120
  /**
@@ -131,7 +132,7 @@ export interface ResponsiveWidthProps {
131
132
  }
132
133
 
133
134
  /**
134
- * @beta
135
+ * @public
135
136
  */
136
137
  export type Delay =
137
138
  | number
@@ -17,9 +17,11 @@ export function _colorVarsStyle(
17
17
  '--card-shadow-penumbra-color': base.shadow.penumbra,
18
18
  '--card-shadow-ambient-color': base.shadow.ambient,
19
19
  '--card-focus-ring-color': base.focusRing,
20
+ '--card-icon-color': color.iconColor,
20
21
 
21
22
  // Card
22
23
  '--card-bg-color': color.bg,
24
+ '--card-bg2-color': color.bg2,
23
25
  '--card-bg-image': checkered
24
26
  ? `repeating-conic-gradient(${color.bg} 0% 25%, ${color.bg2 || color.bg} 0% 50%)`
25
27
  : undefined,
@@ -1,3 +1,5 @@
1
+ import {FocusRing} from '../../theme'
2
+
1
3
  export function focusRingBorderStyle(border: {color: string; width: number}): string {
2
4
  return `inset 0 0 0 ${border.width}px ${border.color}`
3
5
  }
@@ -5,7 +7,7 @@ export function focusRingBorderStyle(border: {color: string; width: number}): st
5
7
  export function focusRingStyle(opts: {
6
8
  base?: {bg: string}
7
9
  border?: {color: string; width: number}
8
- focusRing: {offset: number; width: number}
10
+ focusRing: FocusRing
9
11
  }): string {
10
12
  const {base, border, focusRing} = opts
11
13
  const focusRingOutsetWidth = focusRing.offset + focusRing.width
@@ -130,7 +130,8 @@ export function textInputRepresentationStyle(
130
130
  props: TextInputRepresentationStyleProps & ThemeProps,
131
131
  ): ReturnType<typeof css> {
132
132
  const {$hasPrefix, $hasSuffix, $scheme, $tone, theme} = props
133
- const {focusRing, input} = theme.sanity
133
+ const {input} = theme.sanity
134
+ const {focusRing} = input.text
134
135
  const color = theme.sanity.color.input
135
136
 
136
137
  return css`
@@ -1,5 +1,5 @@
1
1
  import {CSSObject} from '../../types/styled'
2
- import {rem, _responsive} from '../helpers'
2
+ import {_responsive, rem} from '../helpers'
3
3
  import {ThemeProps} from '../types'
4
4
  import {ResponsiveRadiusStyleProps} from './types'
5
5
 
@@ -7,7 +7,17 @@ export function responsiveRadiusStyle(props: ResponsiveRadiusStyleProps & ThemeP
7
7
  const {theme} = props
8
8
  const {media, radius} = theme.sanity
9
9
 
10
- return _responsive(media, props.$radius, (radiusIndex) => ({
11
- borderRadius: rem(radius[radiusIndex]),
12
- }))
10
+ return _responsive(media, props.$radius, (value) => {
11
+ let borderRadius: string | 0 = 0
12
+
13
+ if (typeof value === 'number') {
14
+ borderRadius = rem(radius[value])
15
+ }
16
+
17
+ if (value === 'full') {
18
+ borderRadius = '9999px'
19
+ }
20
+
21
+ return {borderRadius}
22
+ })
13
23
  }
@@ -1,6 +1,8 @@
1
+ import {Radius} from '../../types'
2
+
1
3
  /**
2
4
  * @internal
3
5
  */
4
6
  export interface ResponsiveRadiusStyleProps {
5
- $radius: number[]
7
+ $radius: Radius[]
6
8
  }
@@ -1,3 +1,5 @@
1
+ import {FocusRing} from '../../types'
2
+
1
3
  /**
2
4
  * @public
3
5
  */
@@ -6,4 +8,5 @@ export interface ThemeAvatar {
6
8
  distance: number
7
9
  size: number
8
10
  }[]
11
+ focusRing: FocusRing
9
12
  }
@@ -9,6 +9,7 @@ export interface ThemeColorGenericState {
9
9
  bg2?: string
10
10
  border: string
11
11
  fg: string
12
+ iconColor: string
12
13
  muted: {
13
14
  fg: string
14
15
  }
@@ -39,6 +39,7 @@ describe('color', () => {
39
39
  bg2: 'hsl(0, 0%, 95%)',
40
40
  border: 'hsl(0, 0%, 70%)',
41
41
  fg: 'hsl(0, 0%, 20%)',
42
+ iconColor: 'hsl(0, 0%, 20%)',
42
43
  muted: {
43
44
  fg: 'hsl(0, 0%, 0%)',
44
45
  },
@@ -158,6 +158,7 @@ export const defaultOpts: ThemeColorBuilderOpts = {
158
158
  bg2: dark ? color.light : color.dark,
159
159
  border: dark ? color.lighter : color.darker,
160
160
  fg: dark ? color.darkest : color.lightest,
161
+ iconColor: dark ? color.darkest : color.lightest,
161
162
  muted: {
162
163
  fg: black,
163
164
  },
@@ -180,6 +181,7 @@ export const defaultOpts: ThemeColorBuilderOpts = {
180
181
  bg2: color.base,
181
182
  border: dark ? color.light : color.dark,
182
183
  fg: dark ? color.darkest : color.lightest,
184
+ iconColor: dark ? color.darkest : color.lightest,
183
185
  muted: {
184
186
  fg: black,
185
187
  },
@@ -206,6 +208,7 @@ export const defaultOpts: ThemeColorBuilderOpts = {
206
208
  bg2: dark ? color.darker : color.lighter,
207
209
  border: dark ? color.lighter : color.darker,
208
210
  fg: dark ? color.lightest : color.darkest,
211
+ iconColor: dark ? color.lightest : color.darkest,
209
212
  muted: {
210
213
  fg: black,
211
214
  },
@@ -228,6 +231,7 @@ export const defaultOpts: ThemeColorBuilderOpts = {
228
231
  bg2: dark ? color.darkest : color.lightest,
229
232
  border: dark ? color.darker : color.lighter,
230
233
  fg: dark ? color.lighter : color.darker,
234
+ iconColor: dark ? color.lighter : color.darker,
231
235
  muted: {
232
236
  fg: black,
233
237
  },
@@ -253,6 +257,7 @@ export const defaultOpts: ThemeColorBuilderOpts = {
253
257
  bg: 'transparent',
254
258
  bg2: 'transparent',
255
259
  fg: muted.enabled.fg,
260
+ iconColor: muted.enabled.fg,
256
261
  border: 'transparent',
257
262
  muted: {
258
263
  fg: black,
@@ -273,6 +278,7 @@ export const defaultOpts: ThemeColorBuilderOpts = {
273
278
  bg: muted.enabled.bg,
274
279
  bg2: muted.enabled.bg,
275
280
  fg: muted.hovered.fg,
281
+ iconColor: muted.hovered.fg,
276
282
  border: 'transparent',
277
283
  muted: {
278
284
  fg: black,
@@ -306,6 +312,7 @@ export const defaultOpts: ThemeColorBuilderOpts = {
306
312
  bg: black,
307
313
  bg2: black,
308
314
  fg: black,
315
+ iconColor: black,
309
316
  border: black,
310
317
  muted: {
311
318
  fg: black,
@@ -327,6 +334,7 @@ export const defaultOpts: ThemeColorBuilderOpts = {
327
334
  input: () => {
328
335
  return {
329
336
  bg: black,
337
+ bg2: black,
330
338
  fg: black,
331
339
  border: black,
332
340
  placeholder: black,
@@ -3,6 +3,7 @@
3
3
  */
4
4
  export interface ThemeColorInputState {
5
5
  bg: string
6
+ bg2: string
6
7
  fg: string
7
8
  border: string
8
9
  placeholder: string
@@ -1,13 +1,17 @@
1
+ import {FocusRing} from '../../types'
2
+
1
3
  /**
2
4
  * @public
3
5
  */
4
6
  export interface ThemeInput {
5
7
  checkbox: {
6
8
  size: number
9
+ focusRing: FocusRing
7
10
  }
8
11
  radio: {
9
12
  size: number
10
13
  markSize: number
14
+ focusRing: FocusRing
11
15
  }
12
16
  switch: {
13
17
  width: number
@@ -15,8 +19,15 @@ export interface ThemeInput {
15
19
  padding: number
16
20
  transitionDurationMs: number
17
21
  transitionTimingFunction: string
22
+ focusRing: FocusRing
18
23
  }
19
24
  border: {
20
25
  width: number
21
26
  }
27
+ select: {
28
+ focusRing: FocusRing
29
+ }
30
+ text: {
31
+ focusRing: FocusRing
32
+ }
22
33
  }
@@ -1,3 +1,4 @@
1
+ import {FocusRing} from '../../types'
1
2
  import {ThemeAvatar} from './avatar'
2
3
  import {ThemeColorSchemes} from './color'
3
4
  import {ThemeFonts, ThemeFontWeightKey} from './fonts'
@@ -15,14 +16,20 @@ export interface BaseTheme<
15
16
  avatar: ThemeAvatar
16
17
  button: {
17
18
  textWeight: ThemeFontWeightKey
19
+ focusRing: FocusRing
20
+ }
21
+ card: {
22
+ focusRing: FocusRing
18
23
  }
19
24
  color: ThemeColorSchemes
20
25
  container: number[]
26
+ /** @deprecated Use component-specific `focusRing` values instead */
21
27
  focusRing: {
22
28
  offset: number
23
29
  width: number
24
30
  }
25
31
  fonts: ThemeFonts
32
+ input: ThemeInput
26
33
  /**
27
34
  * THIS API MAY BE UNSTABLE. DO NOT USE IN PRODUCTION.
28
35
  * @beta
@@ -32,6 +39,5 @@ export interface BaseTheme<
32
39
  radius: number[]
33
40
  shadows: Array<ThemeShadow | null>
34
41
  space: number[]
35
- input: ThemeInput
36
42
  styles?: Styles
37
43
  }