@sanity/ui 5.0.0-alpha.2 → 5.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 (140) hide show
  1. package/README.md +1 -1
  2. package/dist/LazyRefractor-CQ22IeXB.js +19 -0
  3. package/dist/LazyRefractor-CQ22IeXB.js.map +1 -0
  4. package/dist/cli/install.js +2 -1
  5. package/dist/index.d.ts +826 -855
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +2439 -1796
  8. package/dist/index.js.map +1 -1
  9. package/dist/polyfills.d.ts +1 -0
  10. package/dist/polyfills.js +5 -0
  11. package/dist/polyfills.js.map +1 -0
  12. package/dist/styles.css +1 -1
  13. package/package.json +16 -9
  14. package/src/cli/install.ts +2 -1
  15. package/src/components/avatar/Avatar.tsx +50 -0
  16. package/src/components/avatar/avatar.css +51 -0
  17. package/src/components/avatar/avatar.props.ts +57 -0
  18. package/src/components/avatar-counter/AvatarCounter.tsx +38 -0
  19. package/src/components/avatar-counter/avatar-counter.css +8 -0
  20. package/src/components/avatar-counter/avatarCounter.props.ts +44 -0
  21. package/src/components/avatar-stack/AvatarStack.tsx +60 -0
  22. package/src/components/avatar-stack/avatar-stack.css +16 -0
  23. package/src/components/avatar-stack/avatarStack.props.ts +20 -0
  24. package/src/components/badge/Badge.tsx +53 -0
  25. package/src/components/badge/badge.css +6 -0
  26. package/src/components/badge/badge.props.ts +31 -0
  27. package/src/components/box/box.css +5 -0
  28. package/src/components/box/box.props.ts +7 -2
  29. package/src/components/button/Button.tsx +7 -1
  30. package/src/components/button/button.css +51 -23
  31. package/src/components/button/button.props.ts +27 -9
  32. package/src/components/card/Card.tsx +1 -1
  33. package/src/components/card/card.props.ts +10 -5
  34. package/src/components/checkbox/Checkbox.tsx +15 -29
  35. package/src/components/checkbox/checkbox.css +19 -20
  36. package/src/components/checkbox/checkbox.props.ts +11 -12
  37. package/src/components/code/Code.tsx +18 -19
  38. package/src/components/code/code.props.ts +23 -14
  39. package/src/components/container/Container.tsx +5 -1
  40. package/src/components/container/container.css +4 -0
  41. package/src/components/container/container.props.ts +6 -2
  42. package/src/components/dialog/Dialog.tsx +139 -0
  43. package/src/components/dialog/dialog.css +49 -0
  44. package/src/components/dialog/dialog.props.ts +45 -0
  45. package/src/components/eyebrow/eyebrow.props.ts +6 -2
  46. package/src/components/flex/flex.css +5 -0
  47. package/src/components/flex/flex.props.ts +6 -2
  48. package/src/components/grid/grid.css +5 -0
  49. package/src/components/grid/grid.props.ts +14 -3
  50. package/src/components/h-stack/HStack.tsx +8 -14
  51. package/src/components/h-stack/hStack.props.ts +5 -13
  52. package/src/components/heading/Heading.tsx +8 -3
  53. package/src/components/heading/heading.css +0 -5
  54. package/src/components/heading/heading.props.ts +16 -5
  55. package/src/components/hotkeys/Hotkeys.tsx +29 -0
  56. package/src/components/hotkeys/hotkeys.css +3 -0
  57. package/src/components/hotkeys/hotkeys.props.ts +15 -0
  58. package/src/components/icon/Icon.tsx +22 -11
  59. package/src/components/icon/icon.props.ts +7 -3
  60. package/src/components/icon-button/iconButton.props.ts +7 -2
  61. package/src/components/index.css +12 -1
  62. package/src/components/indicator/indicator.css +1 -1
  63. package/src/components/indicator/indicator.props.ts +6 -2
  64. package/src/components/indicator-stack/indicatorStack.props.ts +3 -1
  65. package/src/components/inline/inline.props.ts +6 -2
  66. package/src/components/kbd/KBD.tsx +33 -0
  67. package/src/components/kbd/kbd.css +6 -0
  68. package/src/components/kbd/kbd.props.ts +20 -0
  69. package/src/components/link/link.props.ts +4 -4
  70. package/src/components/list/list.props.ts +27 -9
  71. package/src/components/popover/Popover.tsx +85 -0
  72. package/src/components/popover/popover.css +21 -0
  73. package/src/components/popover/popover.props.ts +38 -0
  74. package/src/components/press-area/pressArea.props.ts +3 -1
  75. package/src/components/radio/Radio.tsx +10 -28
  76. package/src/components/radio/radio.css +17 -32
  77. package/src/components/radio/radio.props.ts +1 -19
  78. package/src/components/select/Select.tsx +41 -0
  79. package/src/components/select/select.css +67 -0
  80. package/src/components/select/select.props.ts +18 -0
  81. package/src/components/skip-to-content/skipToContent.props.ts +9 -3
  82. package/src/components/spinner/Spinner.tsx +2 -1
  83. package/src/components/spinner/spinner.props.ts +3 -0
  84. package/src/components/switch/Switch.tsx +9 -21
  85. package/src/components/switch/switch.css +22 -23
  86. package/src/components/switch/switch.props.ts +7 -11
  87. package/src/components/tabs/Tabs.tsx +186 -0
  88. package/src/components/tabs/tabs.css +34 -0
  89. package/src/components/tabs/tabs.props.ts +66 -0
  90. package/src/components/text/text.props.ts +6 -2
  91. package/src/components/text-area/TextArea.tsx +32 -0
  92. package/src/components/text-area/text-area.css +56 -0
  93. package/src/components/text-area/textArea.props.ts +35 -0
  94. package/src/components/text-input/TextInput.tsx +32 -0
  95. package/src/components/text-input/text-input.css +55 -0
  96. package/src/components/text-input/textInput.props.ts +42 -0
  97. package/src/components/tooltip/Tooltip.tsx +59 -55
  98. package/src/components/tooltip/tooltip.css +21 -40
  99. package/src/components/tooltip/tooltip.props.ts +24 -8
  100. package/src/components/tooltip-group/TooltipGroup.tsx +2 -5
  101. package/src/components/tooltip-group/tooltipGroup.props.ts +3 -1
  102. package/src/components/v-stack/VStack.tsx +8 -14
  103. package/src/components/v-stack/vStack.props.ts +5 -13
  104. package/src/components/visually-hidden/visuallyHidden.props.ts +6 -2
  105. package/src/css/classes/dynamic/height.css +2 -0
  106. package/src/css/classes/generic/display.css +8 -8
  107. package/src/css/classes/generic/placement.css +105 -86
  108. package/src/css/classes/local/animation.css +4 -0
  109. package/src/css/classes/local/field-sizing.css +3 -0
  110. package/src/css/classes/local/index.css +3 -1
  111. package/src/css/classes/local/text-trim.css +11 -4
  112. package/src/css/classes/local/top-anchor.css +4 -0
  113. package/src/css/classes/system/shadow.css +6 -6
  114. package/src/css/classes/system/typography.css +0 -4
  115. package/src/css/global/reset.css +16 -1
  116. package/src/css/tokens/semantic.css +7 -6
  117. package/src/css/tokens/surface.css +80 -12
  118. package/src/hooks/useIsClient.ts +10 -0
  119. package/src/index.ts +17 -2
  120. package/src/polyfills.ts +17 -0
  121. package/src/props/formElement.ts +34 -0
  122. package/src/props/layout.ts +3 -3
  123. package/src/props/tone.ts +13 -2
  124. package/src/types/Avatar.ts +14 -0
  125. package/src/types/Code.ts +0 -3
  126. package/src/types/Eyebrow.ts +1 -1
  127. package/src/types/FormElement.ts +2 -0
  128. package/src/types/Heading.ts +1 -1
  129. package/src/types/TextAlign.ts +1 -1
  130. package/src/types/Tone.ts +2 -0
  131. package/src/utils/getProps.ts +1 -1
  132. package/src/utils/mergeTriggerProps.ts +66 -0
  133. package/src/utils/renderPortal.tsx +14 -0
  134. package/src/version.ts +2 -2
  135. package/dist/_chunks-es/LazyRefractor.js +0 -20
  136. package/dist/_chunks-es/LazyRefractor.js.map +0 -1
  137. package/src/components/label/Label.tsx +0 -34
  138. package/src/components/label/label.css +0 -3
  139. package/src/components/label/label.props.ts +0 -19
  140. package/src/css/classes/local/tone.css +0 -75
@@ -1,72 +1,100 @@
1
+ /**
2
+ * Button defaults
3
+ */
1
4
  .sui-Button {
5
+ --background-color: hsl(from var(--backdrop) h s l / var(--opacity-high));
6
+ --foreground-color: var(--foreground-high);
7
+ --hover-blend-color: var(--gray-500);
2
8
  background: var(--background-color);
3
9
  box-shadow: inset 0 0 0 1px var(--border-color, transparent);
4
10
  color: var(--foreground-color);
5
11
  text-decoration: none;
6
- transition: var(--hover-transition);
12
+ transition: var(--hover-transition), transform 100ms linear;
7
13
  appearance: none;
8
14
  }
9
15
 
10
16
  .sui-Button:hover {
11
17
  background: color-mix(
12
18
  in srgb,
13
- var(--tone-500) 25%,
19
+ var(--hover-blend-color) 12%,
14
20
  var(--background-color)
15
21
  );
16
- }
17
-
18
- .sui-Button.sui-button-level-primary:hover {
19
- background: color-mix(
22
+ color: color-mix(
20
23
  in srgb,
21
- var(--tone-950) 25%,
22
- var(--background-color)
24
+ var(--foreground-high) 25%,
25
+ var(--foreground-color)
23
26
  );
24
27
  }
25
28
 
26
- .sui-Button[class*='sui-tone']:disabled {
27
- --background-color: var(--inert-background);
28
- --foreground-color: var(--inert-foreground);
29
- --border-color: transparent;
30
- pointer-events: none;
31
- }
32
-
33
29
  .sui-Button:focus-visible {
34
30
  outline: var(--focus-outline);
35
31
  outline-offset: var(--focus-offset);
36
32
  }
37
33
 
34
+ .sui-Button:active {
35
+ transform: scale(0.975);
36
+ }
37
+
38
38
  .sui-Button :is([data-sanity-icon], .sui-Spinner, .sui-Text) {
39
39
  color: inherit;
40
40
  }
41
41
 
42
- .sui-Button > .sui-Flex + * {
42
+ .sui-Button > [data-ui="Button-Spinner"] + * {
43
43
  opacity: 0;
44
44
  }
45
45
 
46
+ /**
47
+ * Disabled
48
+ */
49
+ .sui-Button[class*='sui-tone']:disabled {
50
+ --background-color: var(--inert-background);
51
+ --foreground-color: var(--inert-foreground);
52
+ --border-color: transparent;
53
+ pointer-events: none;
54
+ }
55
+
56
+ /**
57
+ * Primary
58
+ */
46
59
  .sui-button-level-primary {
47
60
  --background-color: var(--background-high-emphasized);
48
61
  --foreground-color: var(--foreground-low-emphasized);
62
+ --hover-blend-color: light-dark(var(--gray-950), var(--gray-50));
63
+ }
64
+
65
+ .sui-Button.sui-button-level-primary:hover {
66
+ background: color-mix(
67
+ in srgb,
68
+ var(--hover-blend-color) 12%,
69
+ var(--background-color)
70
+ );
71
+ color: var(--foreground-low-emphasized);
49
72
  }
50
73
 
51
74
  .sui-button-level-primary.sui-tone-critical {
52
75
  --background-color: var(--background-low-emphasized);
76
+ --hover-blend-color: light-dark(var(--red-950), var(--red-50));
53
77
  }
54
78
 
79
+
80
+
81
+ /**
82
+ * Secondary
83
+ */
55
84
  .sui-button-level-secondary {
56
- --background-color: var(--background-high);
57
- --foreground-color: var(--foreground-high);
58
85
  --border-color: var(--separator-low)
59
86
  }
60
87
 
61
88
  .sui-button-level-secondary.sui-tone-critical {
89
+ --background-color: var(--background-low);
62
90
  --foreground-color: var(--foreground-low);
91
+ --hover-blend-color: var(--red-500);
63
92
  }
64
93
 
65
- .sui-button-level-tertiary {
66
- --background-color: transparent;
67
- --foreground-color: var(--foreground-high);
68
- }
69
-
94
+ /**
95
+ * Tertiary
96
+ */
70
97
  .sui-button-level-tertiary.sui-tone-critical {
71
98
  --foreground-color: var(--foreground-low);
99
+ --hover-blend-color: var(--red-500);
72
100
  }
@@ -16,23 +16,41 @@ import type {Responsive} from '../../types/Responsive'
16
16
 
17
17
  /** @public */
18
18
  export interface ButtonProps<T extends React.ElementType = 'button'> {
19
- /** Element to render */
19
+ /**
20
+ * HTML element to render.
21
+ */
20
22
  as?: InteractiveAs<T>
21
- /** Composite prop for setting padding and gap */
23
+ /**
24
+ * Sets padding and gap together to specify size.
25
+ */
22
26
  density?: ButtonDensity
23
- /** Set CSS **width** property to 100% */
27
+ /**
28
+ * Sets Button to fill the width of its container.
29
+ */
24
30
  fullWidth?: Responsive<boolean>
25
- /** Starting icon */
31
+ /**
32
+ * Shows an icon in the start position (left side in left-to-right languages).
33
+ */
26
34
  iconStart?: React.ElementType | React.ReactNode
27
- /** Ending icon */
35
+ /**
36
+ * Shows an icon in the end position (right side in left-to-right languages).
37
+ */
28
38
  iconEnd?: React.ElementType | React.ReactNode
29
- /** Button level */
39
+ /**
40
+ * Sets the importance of Button's action.
41
+ */
30
42
  level?: ButtonLevel
31
- /** Loading state */
43
+ /**
44
+ * Places Button into a loading state.
45
+ */
32
46
  loading?: boolean
33
- /** Button text */
47
+ /**
48
+ * Sets Button's text label.
49
+ */
34
50
  text?: string
35
- /** Button tone */
51
+ /**
52
+ * Sets Button's semantic meaning and related color.
53
+ */
36
54
  tone?: ButtonTone
37
55
  }
38
56
 
@@ -10,7 +10,7 @@ const cardClassName = suffixClassName('sui-Card')
10
10
  /** @public */
11
11
  export function Card<T extends ElementType = 'div'>({
12
12
  density = 'regular',
13
- tone = 'neutral',
13
+ tone = 'default',
14
14
  ...props
15
15
  }: CardProps<T> & Omit<ComponentPropsWithRef<T>, keyof CardProps<T>>) {
16
16
  const {as, children, className, style, ...rest} = getProps({density, tone, ...props}, cardProps)
@@ -2,16 +2,21 @@ import {borderProps} from '../../props/border'
2
2
  import {gapProps} from '../../props/gap'
3
3
  import {type MarginProps, marginProps} from '../../props/margin'
4
4
  import {paddingProps} from '../../props/padding'
5
- import {type ToneProps, toneProps} from '../../props/tone'
5
+ import {toneWithDefaultProps, type ToneWithDefaultProps} from '../../props/tone'
6
6
  import {DENSITY, type Density} from '../../types/Density'
7
7
  import {type PropDef} from '../../types/PropDef'
8
8
  import {type Responsive} from '../../types/Responsive'
9
9
 
10
10
  /** @public */
11
- export interface CardProps<T extends React.ElementType = 'div'> extends MarginProps, ToneProps {
12
- /** Element to render */
11
+ export interface CardProps<T extends React.ElementType = 'div'>
12
+ extends MarginProps, ToneWithDefaultProps {
13
+ /**
14
+ * HTML element or component to render.
15
+ */
13
16
  as?: T
14
- /** Composite prop for setting padding and border radius */
17
+ /**
18
+ * Sets padding, gap, and border-radius together to specify size. This prop is used in place of separate `padding`, `gap`, and `border-radius` props.
19
+ */
15
20
  density?: Responsive<Density>
16
21
  }
17
22
 
@@ -49,6 +54,6 @@ export const cardProps: Record<string, PropDef> = {
49
54
  },
50
55
  },
51
56
  } satisfies PropDef<Density>,
52
- ...toneProps,
57
+ ...toneWithDefaultProps,
53
58
  ...marginProps,
54
59
  }
@@ -1,62 +1,48 @@
1
- import {CheckmarkIcon, RemoveIcon} from '@sanity/icons'
1
+ import {CheckmarkIcon} from '@sanity/icons/Checkmark'
2
+ import {RemoveIcon} from '@sanity/icons/Remove'
2
3
  import clsx from 'clsx'
3
4
  import {useEffect, useRef} from 'react'
4
5
 
5
6
  import {getProps} from '../../utils/getProps'
6
7
  import {suffixClassName} from '../../utils/suffixClassName'
7
8
  import {Box} from '../box/Box'
8
- import {Label} from '../label/Label'
9
- import {VisuallyHidden} from '../visually-hidden/VisuallyHidden'
10
9
  import {type CheckboxProps, checkboxProps} from './checkbox.props'
11
10
 
12
11
  const checkboxClassName = suffixClassName('sui-Checkbox')
13
12
  const checkboxInputClassName = suffixClassName('sui-CheckboxInput')
14
- const checkboxMarkClassName = suffixClassName('sui-CheckboxMark')
15
13
 
16
14
  /** @beta */
17
15
  export function Checkbox(props: CheckboxProps) {
18
16
  const inputRef = useRef<HTMLInputElement>(null)
19
- const {className, style, disabled, error, indeterminate, label, ...rest} = getProps(
20
- props,
21
- checkboxProps,
22
- )
17
+ const {className, style, hasError, indeterminate, ...rest} = getProps(props, checkboxProps)
23
18
 
24
19
  useEffect(() => {
25
20
  if (inputRef.current) {
26
21
  inputRef.current.indeterminate = indeterminate
27
22
  }
28
- }, [indeterminate])
23
+ }, [indeterminate, inputRef])
29
24
 
30
25
  return (
31
- <Label
26
+ <Box
27
+ as="span"
32
28
  className={clsx(checkboxClassName, className)}
33
29
  style={style}
34
30
  data-ui="Checkbox"
35
- disabled={disabled}
36
- error={error}
31
+ position="relative"
32
+ radius={2}
33
+ width="17px"
34
+ height="17px"
37
35
  >
38
- <VisuallyHidden
39
- as="input"
36
+ {indeterminate ? <RemoveIcon aria-hidden="true" /> : <CheckmarkIcon aria-hidden="true" />}
37
+
38
+ <input
40
39
  type="checkbox"
41
40
  className={checkboxInputClassName}
42
41
  ref={inputRef}
43
- disabled={disabled}
42
+ aria-invalid={hasError || undefined}
44
43
  {...rest}
45
44
  />
46
-
47
- <Box
48
- as="span"
49
- className={clsx(checkboxMarkClassName, error && 'sui-error')}
50
- position="relative"
51
- radius={2}
52
- width="17px"
53
- height="17px"
54
- >
55
- {indeterminate ? <RemoveIcon /> : <CheckmarkIcon />}
56
- </Box>
57
-
58
- {label}
59
- </Label>
45
+ </Box>
60
46
  )
61
47
  }
62
48
 
@@ -1,9 +1,4 @@
1
- /*
2
- * Custom checkbox, base
3
- */
4
- .sui-CheckboxMark {
5
- /* Background and border colours are computed relatively in hover states;
6
- we use custom properties to make this easier */
1
+ .sui-Checkbox {
7
2
  --background-color: var(--backdrop);
8
3
  --border-color: var(--separator-high);
9
4
  background-color: var(--background-color);
@@ -13,19 +8,24 @@
13
8
  transition: var(--hover-transition);
14
9
  }
15
10
 
11
+ .sui-CheckboxInput {
12
+ opacity: 0;
13
+ position: absolute;
14
+ /* Use negative inset for 24x24 pixel hit area */
15
+ inset: var(--form-element-inset);
16
+ }
17
+
16
18
  /**
17
19
  * Hover - uses relative border/background colours to darken/lighten in both normal & error state
18
20
  */
19
- /** Checkbox border (unchecked) */
20
- .sui-Checkbox:hover .sui-CheckboxMark {
21
+ .sui-Checkbox:has(.sui-CheckboxInput:hover) {
21
22
  border-color: light-dark(
22
23
  oklch(from var(--border-color) calc(l - var(--hover-lightness-delta)) c h),
23
24
  oklch(from var(--border-color) calc(l + var(--hover-lightness-delta)) c h)
24
25
  );
25
26
  }
26
27
 
27
- /** Checkbox background (checked, indeterminate) */
28
- .sui-Checkbox:hover .sui-CheckboxInput:is(:checked, :indeterminate) + .sui-CheckboxMark {
28
+ .sui-Checkbox:has(.sui-CheckboxInput:hover:is(:checked, :indeterminate)) {
29
29
  background-color: light-dark(
30
30
  oklch(from var(--background-color) calc(l - var(--hover-lightness-delta)) c h),
31
31
  oklch(from var(--background-color) calc(l + var(--hover-lightness-delta)) c h)
@@ -35,7 +35,7 @@
35
35
  /**
36
36
  * Focus
37
37
  */
38
- .sui-CheckboxInput:focus-visible + .sui-CheckboxMark {
38
+ .sui-Checkbox:has(.sui-CheckboxInput:focus-visible) {
39
39
  outline: var(--focus-outline);
40
40
  outline-offset: var(--focus-offset);
41
41
  }
@@ -43,7 +43,7 @@
43
43
  /**
44
44
  * Checked/indeterminate
45
45
  */
46
- .sui-CheckboxInput:is(:checked, :indeterminate) + .sui-CheckboxMark {
46
+ .sui-Checkbox:has(.sui-CheckboxInput:is(:checked, :indeterminate)) {
47
47
  --background-color: var(--active-background-emphasized);
48
48
  --border-color: transparent;
49
49
  color: var(--active-foreground-emphasized);
@@ -52,20 +52,19 @@
52
52
  /**
53
53
  * Disabled
54
54
  */
55
- .sui-CheckboxInput:disabled + .sui-CheckboxMark {
55
+ .sui-Checkbox:has(.sui-CheckboxInput:disabled) {
56
56
  --background-color: var(--inert-background);
57
57
  --border-color: var(--separator-low);
58
58
  }
59
59
 
60
- /* Turn hover (and all pointer events) off for disabled checkboxes */
61
- .sui-Checkbox:has(:disabled) {
60
+ .sui-CheckboxInput:disabled {
62
61
  pointer-events: none;
63
62
  }
64
63
 
65
64
  /**
66
65
  * Disabled, but checked/indeterminate
67
66
  */
68
- .sui-CheckboxInput:is(:checked, :indeterminate):disabled + .sui-CheckboxMark {
67
+ .sui-Checkbox:has(.sui-CheckboxInput:is(:checked, :indeterminate):disabled) {
69
68
  --border-color: var(--separator-low);
70
69
  color: var(--inert-foreground);
71
70
  }
@@ -73,28 +72,28 @@
73
72
  /**
74
73
  * Error
75
74
  */
76
- .sui-CheckboxMark.sui-error {
75
+ .sui-Checkbox:has(.sui-CheckboxInput[aria-invalid="true"]) {
77
76
  --border-color: var(--error-separator);
78
77
  }
79
78
 
80
79
  /**
81
80
  * Error, checked/indeterminate
82
81
  */
83
- .sui-CheckboxInput:is(:checked, :indeterminate) + .sui-CheckboxMark.sui-error {
82
+ .sui-Checkbox:has(.sui-CheckboxInput:is(:checked, :indeterminate)[aria-invalid="true"]) {
84
83
  --background-color: var(--error-background-emphasized);
85
84
  }
86
85
 
87
86
  /**
88
87
  * Check/dash icons
89
88
  */
90
- .sui-CheckboxMark svg {
89
+ .sui-Checkbox svg {
91
90
  position: absolute;
92
91
  top: 50%;
93
92
  left: 50%;
94
93
  transform: translate(-50%, -50%);
95
94
  }
96
95
 
97
- .sui-CheckboxMark path {
96
+ .sui-Checkbox path {
98
97
  vector-effect: non-scaling-stroke;
99
98
  stroke-width: 1.5px;
100
99
  }
@@ -1,25 +1,24 @@
1
- import {type MarginProps, marginProps} from '../../props/margin'
2
1
  import {type PropDef} from '../../types/PropDef'
3
2
 
4
3
  /** @beta */
5
- export interface CheckboxProps extends React.ComponentProps<'input'>, MarginProps {
6
- /** Error state */
7
- error?: boolean
8
- /** Indeterminate state */
4
+ export interface CheckboxProps extends React.ComponentProps<'input'> {
5
+ /**
6
+ * Applies error styling to the checkbox mark for invalid states.
7
+ * @remarks Use when form validation fails. Pair with a visible error message.
8
+ */
9
+ hasError?: boolean
10
+ /**
11
+ * Renders the "mixed state" mark (a horizontal line).
12
+ * @remarks Use when the checkbox controls a group with some-but-not-all children checked.
13
+ */
9
14
  indeterminate?: boolean
10
- /** Input label */
11
- label: React.ReactNode
12
15
  }
13
16
 
14
17
  export const checkboxProps: Record<string, PropDef> = {
15
- error: {
18
+ hasError: {
16
19
  type: 'boolean',
17
20
  },
18
21
  indeterminate: {
19
22
  type: 'boolean',
20
23
  },
21
- label: {
22
- type: 'string',
23
- },
24
- ...marginProps,
25
24
  }
@@ -1,7 +1,6 @@
1
1
  import clsx from 'clsx'
2
- import {type ComponentPropsWithRef, lazy, Suspense} from 'react'
2
+ import {lazy, Suspense} from 'react'
3
3
 
4
- import {type CodeTag} from '../../types/Code'
5
4
  import {getProps} from '../../utils/getProps'
6
5
  import {suffixClassName} from '../../utils/suffixClassName'
7
6
  import {type CodeProps, codeProps} from './code.props'
@@ -11,26 +10,26 @@ const LazyRefractor = lazy(() => import('./LazyRefractor'))
11
10
  const codeClassName = suffixClassName('sui-Code')
12
11
 
13
12
  /** @public */
14
- export function Code<T extends CodeTag = 'pre'>({
15
- size = 2,
16
- ...props
17
- }: CodeProps<T> & Omit<ComponentPropsWithRef<T>, keyof CodeProps<T>>) {
18
- const {as, children, className, language, style, ...rest} = getProps({size, ...props}, codeProps)
19
- const Component = as || 'pre'
20
-
21
- if (!language) {
22
- return (
23
- <Component className={clsx(codeClassName, className)} style={style} data-ui="Code" {...rest}>
24
- <code>{children}</code>
25
- </Component>
26
- )
27
- }
13
+ export function Code({size = 2, ...props}: CodeProps) {
14
+ const {children, className, inline, language, style, ...rest} = getProps(
15
+ {size, ...props},
16
+ codeProps,
17
+ )
18
+ /*
19
+ * The span wrapper for inline code is necessary because react-refractor does not
20
+ * support any attributes other than className
21
+ */
22
+ const Component = inline ? 'span' : 'pre'
28
23
 
29
24
  return (
30
25
  <Component className={clsx(codeClassName, className)} style={style} data-ui="Code" {...rest}>
31
- <Suspense fallback={<code>{children}</code>}>
32
- <LazyRefractor language={language} value={children} />
33
- </Suspense>
26
+ {language ? (
27
+ <Suspense fallback={<code>{children}</code>}>
28
+ <LazyRefractor language={language} value={children} />
29
+ </Suspense>
30
+ ) : (
31
+ <code>{children}</code>
32
+ )}
34
33
  </Component>
35
34
  )
36
35
  }
@@ -1,26 +1,36 @@
1
1
  import {marginProps} from '../../props/margin'
2
2
  import {type TypographyProps, typographyProps} from '../../props/typography'
3
- import {CODE_SIZE, CODE_TAG, type CodeSize, type CodeTag} from '../../types/Code'
3
+ import {CODE_SIZE, type CodeSize} from '../../types/Code'
4
4
  import {type PropDef} from '../../types/PropDef'
5
5
  import type {Responsive} from '../../types/Responsive'
6
6
 
7
- /** @public */
8
- export interface CodeProps<T extends CodeTag = 'pre'> extends Omit<
9
- TypographyProps,
10
- 'align' | 'truncate' | 'tone'
11
- > {
12
- /** Element to render */
13
- as?: T
14
- /** Refractor language for syntax highlighting */
7
+ interface CodeBaseProps extends Omit<TypographyProps, 'align' | 'truncate' | 'tone' | 'weight'> {
8
+ /**
9
+ * Refractor language for syntax highlighting.
10
+ */
15
11
  language?: string
16
- /** CSS **font-size** property */
12
+ /**
13
+ * Sets font size.
14
+ */
17
15
  size?: Responsive<CodeSize>
18
16
  }
19
17
 
18
+ /** @public */
19
+ export type CodeProps =
20
+ | (CodeBaseProps & {
21
+ /**
22
+ * Render code inline or as a block.
23
+ * @remarks Block code is wrapped in a `<pre>` tag.
24
+ */
25
+ inline?: false
26
+ } & Omit<React.ComponentPropsWithRef<'pre'>, keyof CodeBaseProps>)
27
+ | (CodeBaseProps & {
28
+ inline: true
29
+ } & Omit<React.ComponentPropsWithRef<'span'>, keyof CodeBaseProps>)
30
+
20
31
  export const codeProps: Record<string, PropDef> = {
21
- as: {
22
- type: 'union',
23
- values: CODE_TAG,
32
+ inline: {
33
+ type: 'boolean',
24
34
  },
25
35
  language: {
26
36
  type: 'string',
@@ -32,6 +42,5 @@ export const codeProps: Record<string, PropDef> = {
32
42
  },
33
43
  muted: typographyProps['muted'] as PropDef,
34
44
  trim: typographyProps['trim'] as PropDef,
35
- weight: typographyProps['weight'] as PropDef,
36
45
  ...marginProps,
37
46
  }
@@ -10,9 +10,13 @@ const containerClassName = suffixClassName('sui-Container')
10
10
  /** @public */
11
11
  export function Container<T extends ElementType = 'div'>({
12
12
  marginX = 'auto',
13
+ size = 2,
13
14
  ...props
14
15
  }: ContainerProps<T> & Omit<ComponentPropsWithRef<T>, keyof ContainerProps<T>>) {
15
- const {as, children, className, style, ...rest} = getProps({marginX, ...props}, containerProps)
16
+ const {as, children, className, style, ...rest} = getProps(
17
+ {marginX, size, ...props},
18
+ containerProps,
19
+ )
16
20
  const Component = as || 'div'
17
21
 
18
22
  return (
@@ -1,3 +1,7 @@
1
+ .sui-Container {
2
+ width: 100%;
3
+ }
4
+
1
5
  .sui-Container[class*='sui-tone'] {
2
6
  --container-background: var(--background-low);
3
7
  background-color: var(--container-background);
@@ -5,9 +5,13 @@ import type {Responsive} from '../../types/Responsive'
5
5
 
6
6
  /** @public */
7
7
  export interface ContainerProps<T extends React.ElementType = 'div'> extends LayoutProps {
8
- /** Element to render */
8
+ /**
9
+ * HTML element or component to render.
10
+ */
9
11
  as?: T
10
- /** CSS **max-width** property */
12
+ /**
13
+ * Maximum width of the container.
14
+ */
11
15
  size?: Responsive<ContainerSize>
12
16
  }
13
17