@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
@@ -0,0 +1,139 @@
1
+ import {CloseIcon} from '@sanity/icons/Close'
2
+ import clsx from 'clsx'
3
+ import {type ComponentProps, useEffect, useId, useRef} from 'react'
4
+
5
+ import {getProps} from '../../utils/getProps'
6
+ import {suffixClassName} from '../../utils/suffixClassName'
7
+ import {Box} from '../box/Box'
8
+ import {Flex} from '../flex/Flex'
9
+ import {Heading} from '../heading/Heading'
10
+ import {IconButton} from '../icon-button/IconButton'
11
+ import {type DialogProps, dialogProps} from './dialog.props'
12
+
13
+ const dialogClassName = suffixClassName('sui-Dialog')
14
+ const dialogContentClassName = suffixClassName('sui-DialogContent')
15
+ const dialogFooterClassName = suffixClassName('sui-DialogFooter')
16
+
17
+ function DialogRoot({open = false, size = 0, ...props}: DialogProps) {
18
+ const {children, className, style, header, onClose, ...rest} = getProps(
19
+ {size, ...props},
20
+ dialogProps,
21
+ )
22
+
23
+ const dialogRef = useRef<HTMLDialogElement>(null)
24
+ const headerId = useId()
25
+
26
+ const dialogClasses = clsx(
27
+ dialogClassName,
28
+ `${props.topAnchor ? 'sui-mx-auto' : 'sui-m-auto'} sui-radius5 sui-shadow3 sui-p4 sui-flex-direction-column sui-gap4 sui-overflow-y-auto`,
29
+ )
30
+
31
+ useEffect(() => {
32
+ const dialogElement = dialogRef.current
33
+ if (!dialogElement) return
34
+
35
+ // `open` = `open` prop
36
+ // dialogElement.open = the `open` attribute on the HTML dialog element
37
+ // The prop and the attribute are manipulated independently, thus they
38
+ // can get out of sync if not handled within this effect.
39
+ if (open) {
40
+ if (!dialogElement.open) {
41
+ dialogElement.showModal()
42
+ }
43
+ } else {
44
+ if (dialogElement.open) {
45
+ dialogElement.close()
46
+ }
47
+ }
48
+
49
+ // Ensure the dialog is closed (and thus its `open` attribute updated)
50
+ // when the component is unmounted.
51
+ return () => {
52
+ dialogElement.close()
53
+ }
54
+ }, [open])
55
+
56
+ return (
57
+ <dialog
58
+ {...rest}
59
+ ref={dialogRef}
60
+ closedby="any"
61
+ aria-labelledby={header ? headerId : undefined}
62
+ onClose={onClose}
63
+ className={clsx(dialogClasses, className)}
64
+ style={style}
65
+ data-ui="Dialog"
66
+ >
67
+ <Flex flexShrink={0} justifyContent="space-between" alignItems="center">
68
+ {header ? (
69
+ <Heading as="h2" trim size={1} id={headerId}>
70
+ {header}
71
+ </Heading>
72
+ ) : (
73
+ <div />
74
+ )}
75
+ <IconButton
76
+ aria-label="Close"
77
+ level="tertiary"
78
+ icon={CloseIcon}
79
+ onClick={() => dialogRef.current?.close()}
80
+ />
81
+ </Flex>
82
+ {children}
83
+ </dialog>
84
+ )
85
+ }
86
+
87
+ function DialogContent(props: ComponentProps<'div'>) {
88
+ const {children, className, style, ...rest} = getProps(props, {})
89
+
90
+ return (
91
+ <Box
92
+ {...rest}
93
+ className={clsx(dialogContentClassName, className)}
94
+ style={style}
95
+ data-ui="DialogContent"
96
+ flexGrow={1}
97
+ overflowY="auto"
98
+ >
99
+ {children}
100
+ </Box>
101
+ )
102
+ }
103
+
104
+ function DialogFooter(props: ComponentProps<'div'>) {
105
+ const {children, className, style, ...rest} = getProps(props, {})
106
+
107
+ return (
108
+ <Box
109
+ {...rest}
110
+ className={clsx(dialogFooterClassName, className)}
111
+ style={style}
112
+ data-ui="DialogFooter"
113
+ flexShrink={0}
114
+ >
115
+ {children}
116
+ </Box>
117
+ )
118
+ }
119
+
120
+ DialogRoot.displayName = 'Dialog'
121
+
122
+ /**
123
+ * @beta
124
+ *
125
+ * Renders a modal dialog element — should not be used for nonmodal dialogs.
126
+ * Modal dialogs make their containing documents inert, and render on the topmost
127
+ * layer within that containing document; they must be dimissed before the containing
128
+ * document and its contents become unblocked. They also trap focus within the bounds
129
+ * of the dialog element and its descendants.
130
+ *
131
+ * For more on dialogs and modality, refer to the HTML specification for the dialog element:
132
+ * https://html.spec.whatwg.org/dev/interactive-elements.html#the-dialog-element
133
+ */
134
+ export const Dialog = DialogRoot
135
+
136
+ DialogRoot.Content = DialogContent
137
+ DialogRoot.Footer = DialogFooter
138
+
139
+ export type {DialogProps}
@@ -0,0 +1,49 @@
1
+ .sui-Dialog {
2
+ /* Computed width is moderated by Dialog's size prop, which controls max-width */
3
+ width: calc(100dvw - 2rem);
4
+ max-height: calc(100dvh - 2rem);
5
+ transition:
6
+ display 150ms allow-discrete,
7
+ overlay 150ms allow-discrete,
8
+ opacity 150ms var(--timing-linear),
9
+ scale 150ms var(--timing-curve);
10
+ }
11
+
12
+ .sui-Dialog:not([open]) {
13
+ opacity: 0;
14
+ scale: 0.9;
15
+ }
16
+
17
+ .sui-Dialog[open] {
18
+ display: flex;
19
+ opacity: 1;
20
+ scale: 1;
21
+ }
22
+
23
+ .sui-Dialog::backdrop {
24
+ --dialog-backdrop: hsl(from var(--separator-high) h s l / var(--overlay-opacity));
25
+ background-color: var(--dialog-backdrop);
26
+ transition:
27
+ display 150ms allow-discrete,
28
+ overlay 150ms allow-discrete,
29
+ opacity 150ms var(--timing-linear);
30
+ }
31
+
32
+ .sui-Dialog:not([open])::backdrop {
33
+ opacity: 0;
34
+ }
35
+
36
+ .sui-Dialog[open]::backdrop {
37
+ opacity: 1;
38
+ }
39
+
40
+ @starting-style {
41
+ .sui-Dialog[open] {
42
+ opacity: 0;
43
+ scale: 0.9;
44
+ }
45
+
46
+ .sui-Dialog[open]::backdrop {
47
+ opacity: 0;
48
+ }
49
+ }
@@ -0,0 +1,45 @@
1
+ import {CONTAINER_SIZE, type ContainerSize} from '../../types/Container'
2
+ import {type PropDef} from '../../types/PropDef'
3
+ import type {Responsive} from '../../types/Responsive'
4
+
5
+ /** @beta */
6
+ export interface DialogProps extends Omit<React.ComponentProps<'dialog'>, 'open'> {
7
+ /**
8
+ * Text for the dialog heading.
9
+ * @remarks Recommended for accessibility. The component sets `aria-labelledby` to the heading when you give this prop.
10
+ */
11
+ header?: string
12
+ /**
13
+ * A function to call alongside the native `close` event.
14
+ * @remarks Use it to set `open` back to `false`. It runs for every close cause: the Escape key, a backdrop click, the close button, or a programmatic close.
15
+ */
16
+ onClose: React.ReactEventHandler<HTMLDialogElement>
17
+ /**
18
+ * Toggles the dialog's open state.
19
+ * @remarks `true` calls `showModal()` on the element. `false` calls `close()`.
20
+ */
21
+ open?: boolean
22
+ /** Sets the max width of the dialog */
23
+ size?: Responsive<ContainerSize>
24
+ /** CSS length value used to set the Dialog’s distance from the top of the viewport; Dialog is centered if not provided */
25
+ topAnchor?: string
26
+ }
27
+
28
+ export const dialogProps: Record<string, PropDef> = {
29
+ header: {
30
+ type: 'string',
31
+ },
32
+ open: {
33
+ type: 'boolean',
34
+ },
35
+ size: {
36
+ type: 'union',
37
+ className: 'container',
38
+ values: CONTAINER_SIZE,
39
+ },
40
+ topAnchor: {
41
+ type: 'string',
42
+ className: 'top-anchor',
43
+ variable: '--top-anchor',
44
+ },
45
+ }
@@ -5,9 +5,13 @@ import type {Responsive} from '../../types/Responsive'
5
5
 
6
6
  /** @public */
7
7
  export interface EyebrowProps<T extends React.ElementType = 'span'> extends TypographyProps {
8
- /** Element to render */
8
+ /**
9
+ * HTML element to render.
10
+ */
9
11
  as?: T
10
- /** CSS **font-size** property */
12
+ /**
13
+ * Sets font size. Uses the same scale as Label.
14
+ */
11
15
  size?: Responsive<EyebrowSize>
12
16
  }
13
17
 
@@ -1,3 +1,8 @@
1
+ .sui-Flex {
2
+ min-width: 0;
3
+ min-height: 0;
4
+ }
5
+
1
6
  .sui-Flex[class*='sui-tone'] {
2
7
  --flex-background: var(--background-low);
3
8
  background-color: var(--flex-background);
@@ -8,9 +8,13 @@ import type {Responsive} from '../../types/Responsive'
8
8
  /** @public */
9
9
  export interface FlexProps<T extends React.ElementType = 'div'>
10
10
  extends FlexParentProps, GapProps, LayoutProps {
11
- /** Element to render */
11
+ /**
12
+ * HTML element or component to render.
13
+ */
12
14
  as?: T
13
- /** CSS **display** property */
15
+ /**
16
+ * CSS `display` property.
17
+ */
14
18
  display?: Responsive<DisplayFlex>
15
19
  }
16
20
 
@@ -1,3 +1,8 @@
1
+ .sui-Grid {
2
+ min-width: 0;
3
+ min-height: 0;
4
+ }
5
+
1
6
  .sui-Grid[class*='sui-tone'] {
2
7
  --grid-background: var(--background-low);
3
8
  background-color: var(--grid-background);
@@ -1,3 +1,4 @@
1
+ import {flexParentProps, type FlexParentProps} from '../../props/flexParent'
1
2
  import {type GapProps, gapProps} from '../../props/gap'
2
3
  import {type GridParentProps, gridParentProps} from '../../props/gridParent'
3
4
  import {type LayoutProps, layoutProps} from '../../props/layout'
@@ -7,10 +8,18 @@ import type {Responsive} from '../../types/Responsive'
7
8
 
8
9
  /** @public */
9
10
  export interface GridProps<T extends React.ElementType = 'div'>
10
- extends GridParentProps, GapProps, LayoutProps {
11
- /** Element to render */
11
+ extends
12
+ Pick<FlexParentProps, 'alignItems' | 'justifyContent'>,
13
+ GridParentProps,
14
+ GapProps,
15
+ LayoutProps {
16
+ /**
17
+ * HTML element or component to render.
18
+ */
12
19
  as?: T
13
- /** CSS **display** property */
20
+ /**
21
+ * CSS `display` property.
22
+ */
14
23
  display?: Responsive<DisplayGrid>
15
24
  }
16
25
 
@@ -23,6 +32,8 @@ export const gridProps: Record<string, PropDef> = {
23
32
  className: 'display',
24
33
  values: DISPLAY_GRID,
25
34
  },
35
+ alignItems: flexParentProps['alignItems'] as PropDef,
36
+ justifyContent: flexParentProps['justifyContent'] as PropDef,
26
37
  ...gridParentProps,
27
38
  ...gapProps,
28
39
  ...layoutProps,
@@ -1,33 +1,27 @@
1
1
  import clsx from 'clsx'
2
2
  import type {ComponentPropsWithRef, ElementType} from 'react'
3
3
 
4
- import {getProps} from '../../utils/getProps'
4
+ import {type ComponentProps} from '../../utils/getProps'
5
5
  import {suffixClassName} from '../../utils/suffixClassName'
6
6
  import {Flex} from '../flex/Flex'
7
- import {type HStackProps, hStackProps} from './hStack.props'
7
+ import {type HStackProps} from './hStack.props'
8
8
 
9
9
  const hStackClassName = suffixClassName('sui-HStack')
10
10
 
11
11
  /** @public */
12
- export function HStack<T extends ElementType = 'div'>(
13
- props: HStackProps<T> & Omit<ComponentPropsWithRef<T>, keyof HStackProps<T>>,
14
- ) {
15
- const {as, children, className, style, ...rest} = getProps(props, hStackProps)
16
- const Component = as || 'div'
17
-
12
+ export function HStack<T extends ElementType = 'div'>({
13
+ className,
14
+ ...props
15
+ }: HStackProps<T> & Omit<ComponentPropsWithRef<T>, keyof HStackProps<T>>) {
18
16
  return (
19
17
  <Flex
20
- as={Component}
21
18
  className={clsx(hStackClassName, className)}
22
- style={style}
23
19
  data-ui="HStack"
24
20
  display="inline-flex"
25
21
  alignItems="center"
26
22
  flexWrap="wrap"
27
- {...rest}
28
- >
29
- {children}
30
- </Flex>
23
+ {...(props as ComponentProps)}
24
+ />
31
25
  )
32
26
  }
33
27
 
@@ -1,15 +1,7 @@
1
- import {type GapProps, gapProps} from '../../props/gap'
2
- import {type PropDef} from '../../types/PropDef'
1
+ import type {FlexProps} from '../flex/flex.props'
3
2
 
4
3
  /** @public */
5
- export interface HStackProps<T extends React.ElementType = 'div'> extends Pick<GapProps, 'gap'> {
6
- /** Element to render */
7
- as?: T
8
- }
9
-
10
- export const hStackProps: Record<string, PropDef> = {
11
- as: {
12
- type: 'string',
13
- },
14
- gap: gapProps['gap'] as PropDef,
15
- }
4
+ export interface HStackProps<T extends React.ElementType = 'div'> extends Pick<
5
+ FlexProps<T>,
6
+ 'as' | 'gap'
7
+ > {}
@@ -10,10 +10,9 @@ const headingClassName = suffixClassName('sui-Heading')
10
10
  /** @public */
11
11
  export function Heading<T extends ElementType = 'h2'>({
12
12
  size = 2,
13
- weight = 'bold',
14
13
  ...props
15
14
  }: HeadingProps & Omit<ComponentPropsWithRef<T>, keyof HeadingProps>) {
16
- const {as, children, className, style, ...rest} = getProps({size, weight, ...props}, headingProps)
15
+ const {as, children, className, style, ...rest} = getProps({size, ...props}, headingProps)
17
16
  const Component = as || 'h2'
18
17
 
19
18
  if (props.truncate && props.trim) {
@@ -30,6 +29,7 @@ export function Heading<T extends ElementType = 'h2'>({
30
29
  <span
31
30
  className={clsx(
32
31
  'sui-overflow-hidden',
32
+ 'sui-weight-bold',
33
33
  props.truncate === 1 ? 'sui-text-overflow' : 'sui-line-clamp',
34
34
  )}
35
35
  >
@@ -41,7 +41,12 @@ export function Heading<T extends ElementType = 'h2'>({
41
41
 
42
42
  return (
43
43
  <Component
44
- className={clsx(headingClassName, props.truncate && 'sui-overflow-hidden', className)}
44
+ className={clsx(
45
+ headingClassName,
46
+ props.truncate && 'sui-overflow-hidden',
47
+ 'sui-weight-bold',
48
+ className,
49
+ )}
45
50
  style={style}
46
51
  data-ui="Heading"
47
52
  {...rest}
@@ -2,8 +2,3 @@
2
2
  --heading-color: var(--foreground-high);
3
3
  color: var(--heading-color);
4
4
  }
5
-
6
- .sui-Heading:where(.sui-text-muted) {
7
- --heading-color-muted: var(--foreground-low);
8
- color: var(--heading-color-muted);
9
- }
@@ -1,13 +1,20 @@
1
+ import {marginProps} from '../../props/margin'
2
+ import {toneProps} from '../../props/tone'
1
3
  import {type TypographyProps, typographyProps} from '../../props/typography'
2
4
  import {HEADING_SIZE, HEADING_TAG, type HeadingSize, type HeadingTag} from '../../types/Heading'
3
5
  import {type PropDef} from '../../types/PropDef'
4
6
  import type {Responsive} from '../../types/Responsive'
5
7
 
6
8
  /** @public */
7
- export interface HeadingProps extends TypographyProps {
8
- /** Element to render */
9
- as?: HeadingTag
10
- /** CSS **font-size** property */
9
+ export interface HeadingProps extends Omit<TypographyProps, 'muted' | 'weight'> {
10
+ /**
11
+ * Semantic heading element to render.
12
+ */
13
+ as: HeadingTag
14
+ /**
15
+ * Sets font size.
16
+ * @remarks Independent of `as`.
17
+ */
11
18
  size?: Responsive<HeadingSize>
12
19
  }
13
20
 
@@ -21,5 +28,9 @@ export const headingProps: Record<string, PropDef> = {
21
28
  className: 'text-heading',
22
29
  values: HEADING_SIZE,
23
30
  },
24
- ...typographyProps,
31
+ align: typographyProps['align'] as PropDef,
32
+ trim: typographyProps['trim'] as PropDef,
33
+ truncate: typographyProps['truncate'] as PropDef,
34
+ ...marginProps,
35
+ ...toneProps,
25
36
  }
@@ -0,0 +1,29 @@
1
+ import clsx from 'clsx'
2
+
3
+ import {getProps} from '../../utils/getProps'
4
+ import {suffixClassName} from '../../utils/suffixClassName'
5
+ import {KBD} from '../kbd/KBD'
6
+ import {type HotkeysProps, hotkeysProps} from './hotkeys.props'
7
+
8
+ const hotkeysClassName = suffixClassName('sui-Hotkeys')
9
+
10
+ /** @alpha */
11
+ export function Hotkeys({keys, ...props}: HotkeysProps) {
12
+ const {className, style, ...rest} = getProps(props, hotkeysProps)
13
+
14
+ if (!keys || keys.length === 0) {
15
+ return null
16
+ }
17
+
18
+ const hotkeysClasses = clsx(hotkeysClassName, 'sui-display-inline-flex')
19
+
20
+ return (
21
+ <kbd className={clsx(hotkeysClasses, className)} style={style} data-ui="Hotkeys" {...rest}>
22
+ {keys.map((key) => (
23
+ <KBD key={key} text={key} />
24
+ ))}
25
+ </kbd>
26
+ )
27
+ }
28
+
29
+ export type {HotkeysProps}
@@ -0,0 +1,3 @@
1
+ .sui-Hotkeys {
2
+ gap: calc(var(--space-1) / 2);
3
+ }
@@ -0,0 +1,15 @@
1
+ import {type PropDef} from '../../types/PropDef'
2
+
3
+ /** @public */
4
+ export interface HotkeysProps extends React.ComponentProps<'kbd'> {
5
+ /**
6
+ * The keys in the shortcut, in order. Each one renders as a KBD.
7
+ */
8
+ keys?: string[]
9
+ }
10
+
11
+ export const hotkeysProps: Record<string, PropDef> = {
12
+ keys: {
13
+ type: 'string',
14
+ },
15
+ }
@@ -1,4 +1,5 @@
1
1
  import clsx from 'clsx'
2
+ import {cloneElement, createElement, isValidElement, type ComponentType, type SVGProps} from 'react'
2
3
 
3
4
  import {getProps} from '../../utils/getProps'
4
5
  import {suffixClassName} from '../../utils/suffixClassName'
@@ -7,18 +8,28 @@ import {type IconProps, iconProps} from './icon.props'
7
8
  const iconClassName = suffixClassName('sui-Icon')
8
9
 
9
10
  /** @public */
10
- export function Icon({size = 2, ...props}: IconProps) {
11
- const {className, style, icon: Component, ...rest} = getProps({size, ...props}, iconProps)
11
+ export function Icon({icon, size = 2, ...props}: IconProps) {
12
+ const {className, style, ...rest} = getProps({size, ...props}, iconProps)
13
+ const iconElement = isValidElement(icon) ? icon : null
14
+ const ariaLabel =
15
+ props['aria-label'] || (iconElement ? iconElement.props['aria-label'] : undefined)
12
16
 
13
- return (
14
- <Component
15
- className={clsx(iconClassName, className)}
16
- data-ui="Icon"
17
- style={style}
18
- aria-hidden={props['aria-label'] ? undefined : true}
19
- {...rest}
20
- />
21
- )
17
+ const svgProps = {
18
+ 'className': clsx(
19
+ iconClassName,
20
+ 'sui-display-block',
21
+ className,
22
+ iconElement ? iconElement.props.className : undefined,
23
+ ),
24
+ 'style': iconElement ? {...iconElement.props.style, ...style} : style,
25
+ 'data-ui': 'Icon',
26
+ 'aria-hidden': ariaLabel ? undefined : true,
27
+ ...rest,
28
+ }
29
+
30
+ return iconElement
31
+ ? cloneElement(iconElement, svgProps)
32
+ : createElement(icon as ComponentType<SVGProps<SVGSVGElement>>, svgProps)
22
33
  }
23
34
 
24
35
  export type {IconProps}
@@ -10,9 +10,13 @@ import type {Responsive} from '../../types/Responsive'
10
10
  /** @public */
11
11
  export interface IconProps
12
12
  extends ComponentProps<'svg'>, Pick<TypographyProps, 'muted'>, MarginProps, ToneProps {
13
- /** Icon to render */
14
- icon: React.ComponentType<SVGProps<SVGSVGElement>>
15
- /** CSS **font-size** property */
13
+ /**
14
+ * The icon component to render.
15
+ */
16
+ icon: React.ComponentType<SVGProps<SVGSVGElement>> | React.ReactElement<SVGProps<SVGSVGElement>>
17
+ /**
18
+ * Sets icon size.
19
+ */
16
20
  size?: Responsive<IconSize>
17
21
  }
18
22
 
@@ -9,9 +9,14 @@ export interface IconButtonProps<T extends React.ElementType = 'button'> extends
9
9
  ButtonProps<T>,
10
10
  'as' | 'density' | 'level' | 'loading' | 'tone'
11
11
  > {
12
- /** Button label */
12
+ /**
13
+ * Accessible name for the button.
14
+ * @remarks Because IconButtons have no visible text, this is required.
15
+ */
13
16
  'aria-label': string
14
- /** Icon */
17
+ /**
18
+ * Icon to render.
19
+ */
15
20
  'icon': React.ComponentType<SVGProps<SVGSVGElement>>
16
21
  }
17
22
 
@@ -1,25 +1,36 @@
1
+ @import './avatar/avatar.css';
2
+ @import './avatar-counter/avatar-counter.css';
3
+ @import './avatar-stack/avatar-stack.css';
4
+ @import './badge/badge.css';
1
5
  @import './box/box.css';
2
6
  @import './button/button.css';
3
7
  @import './card/card.css';
4
8
  @import './checkbox/checkbox.css';
5
9
  @import './code/code.css';
6
10
  @import './container/container.css';
11
+ @import './dialog/dialog.css';
7
12
  @import './eyebrow/eyebrow.css';
8
13
  @import './flex/flex.css';
9
14
  @import './grid/grid.css';
10
15
  @import './heading/heading.css';
16
+ @import './hotkeys/hotkeys.css';
11
17
  @import './icon/icon.css';
12
18
  @import './indicator/indicator.css';
13
19
  @import './indicator-stack/indicator-stack.css';
14
20
  @import './inline/inline.css';
15
- @import './label/label.css';
21
+ @import './kbd/kbd.css';
16
22
  @import './link/link.css';
17
23
  @import './list/list.css';
24
+ @import './popover/popover.css';
18
25
  @import './press-area/press-area.css';
19
26
  @import './radio/radio.css';
27
+ @import './select/select.css';
20
28
  @import './spinner/spinner.css';
21
29
  @import './skip-to-content/skip-to-content.css';
22
30
  @import './switch/switch.css';
31
+ @import './tabs/tabs.css';
23
32
  @import './text/text.css';
33
+ @import './text-area/text-area.css';
34
+ @import './text-input/text-input.css';
24
35
  @import './tooltip/tooltip.css';
25
36
  @import './visually-hidden/visually-hidden.css';
@@ -1,4 +1,4 @@
1
1
  .sui-Indicator[class*='sui-tone'] {
2
- --indicator-background: var(--tone-500);
2
+ --indicator-background: var(--separator-high);
3
3
  background-color: var(--indicator-background);
4
4
  }
@@ -3,9 +3,13 @@ import {type PropDef} from '../../types/PropDef'
3
3
 
4
4
  /** @beta */
5
5
  export interface IndicatorProps<T extends React.ElementType = 'span'> extends ToneProps {
6
- /** Element to render */
6
+ /**
7
+ * HTML element to render.
8
+ */
7
9
  as?: T
8
- /** Label for aria-label attribute */
10
+ /**
11
+ * Accessible label.
12
+ */
9
13
  label?: string
10
14
  }
11
15