@sanity/ui 5.0.0-alpha.24 → 5.0.0-alpha.26

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 (86) hide show
  1. package/dist/index.d.ts +145 -147
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +256 -179
  4. package/dist/index.js.map +1 -1
  5. package/dist/styles.css +1 -1
  6. package/package.json +1 -1
  7. package/src/components/avatar/avatar.props.ts +4 -2
  8. package/src/components/avatar-counter/avatarCounter.props.ts +4 -2
  9. package/src/components/avatar-stack/avatarStack.props.ts +4 -2
  10. package/src/components/badge/Badge.tsx +2 -5
  11. package/src/components/badge/badge.props.ts +15 -15
  12. package/src/components/box/Box.tsx +2 -5
  13. package/src/components/box/box.props.ts +18 -12
  14. package/src/components/button/Button.tsx +2 -2
  15. package/src/components/button/button.props.ts +49 -43
  16. package/src/components/card/Card.tsx +2 -2
  17. package/src/components/card/card.props.ts +19 -13
  18. package/src/components/checkbox/Checkbox.tsx +3 -2
  19. package/src/components/checkbox/checkbox.props.ts +4 -2
  20. package/src/components/code/code.props.ts +5 -3
  21. package/src/components/container/Container.tsx +2 -2
  22. package/src/components/container/container.props.ts +17 -11
  23. package/src/components/dialog/Dialog.tsx +13 -7
  24. package/src/components/dialog/dialog.props.ts +11 -3
  25. package/src/components/divider/divider.props.ts +4 -2
  26. package/src/components/eyebrow/Eyebrow.tsx +2 -5
  27. package/src/components/eyebrow/eyebrow.props.ts +19 -12
  28. package/src/components/flex/Flex.tsx +2 -5
  29. package/src/components/flex/flex.props.ts +19 -12
  30. package/src/components/grid/Grid.tsx +2 -5
  31. package/src/components/grid/grid.props.ts +20 -16
  32. package/src/components/h-stack/HStack.tsx +2 -5
  33. package/src/components/h-stack/hStack.props.ts +7 -4
  34. package/src/components/heading/Heading.tsx +2 -5
  35. package/src/components/heading/heading.props.ts +18 -13
  36. package/src/components/hotkeys/hotkeys.props.ts +4 -2
  37. package/src/components/icon/icon.props.ts +3 -3
  38. package/src/components/icon-button/IconButton.tsx +2 -4
  39. package/src/components/icon-button/iconButton.props.ts +17 -17
  40. package/src/components/index.css +1 -0
  41. package/src/components/indicator/Indicator.tsx +2 -2
  42. package/src/components/indicator/indicator.props.ts +17 -11
  43. package/src/components/indicator-stack/IndicatorStack.tsx +2 -4
  44. package/src/components/indicator-stack/indicatorStack.props.ts +13 -7
  45. package/src/components/inline/Inline.tsx +2 -2
  46. package/src/components/inline/inline.props.ts +17 -11
  47. package/src/components/kbd/kbd.props.ts +4 -2
  48. package/src/components/link/link.props.ts +4 -2
  49. package/src/components/list/List.tsx +47 -97
  50. package/src/components/list/list.css +28 -9
  51. package/src/components/list/list.props.ts +59 -68
  52. package/src/components/popover/popover.props.ts +7 -5
  53. package/src/components/press-area/PressArea.tsx +2 -4
  54. package/src/components/press-area/press-area.css +9 -3
  55. package/src/components/press-area/pressArea.props.ts +13 -7
  56. package/src/components/radio/radio.props.ts +2 -1
  57. package/src/components/search-input/SearchInput.tsx +90 -0
  58. package/src/components/search-input/search-input.css +125 -0
  59. package/src/components/search-input/searchInput.props.ts +18 -0
  60. package/src/components/select/Select.tsx +6 -1
  61. package/src/components/select/select.css +10 -12
  62. package/src/components/select/select.props.ts +4 -2
  63. package/src/components/skip-to-content/skipToContent.props.ts +4 -2
  64. package/src/components/spinner/spinner.props.ts +4 -2
  65. package/src/components/switch/switch.props.ts +4 -2
  66. package/src/components/tabs/tabs.props.ts +8 -9
  67. package/src/components/text/Text.tsx +2 -5
  68. package/src/components/text/text.props.ts +19 -12
  69. package/src/components/text-area/textArea.props.ts +4 -5
  70. package/src/components/text-input/textInput.props.ts +5 -3
  71. package/src/components/tooltip/tooltip.props.ts +7 -5
  72. package/src/components/tooltip-group/TooltipGroup.tsx +8 -9
  73. package/src/components/tooltip-group/tooltipGroup.props.ts +13 -7
  74. package/src/components/v-stack/VStack.tsx +2 -5
  75. package/src/components/v-stack/vStack.props.ts +7 -4
  76. package/src/components/visually-hidden/VisuallyHidden.tsx +2 -4
  77. package/src/components/visually-hidden/visuallyHidden.props.ts +18 -12
  78. package/src/index.ts +1 -0
  79. package/src/types/Interactive.ts +3 -1
  80. package/src/types/Polymorphic.ts +9 -0
  81. package/src/types/Tone.ts +1 -1
  82. package/src/utils/composeRefs.test.ts +130 -0
  83. package/src/utils/composeRefs.ts +52 -0
  84. package/src/utils/getProps.test.ts +18 -0
  85. package/src/utils/getProps.ts +31 -16
  86. package/src/version.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "5.0.0-alpha.24",
3
+ "version": "5.0.0-alpha.26",
4
4
  "description": "Sanity UI Library",
5
5
  "keywords": [
6
6
  "components",
@@ -1,11 +1,13 @@
1
+ import type {ComponentProps} from 'react'
2
+
1
3
  import {heightProps} from '../../props/height'
2
4
  import {AVATAR_COLOR, AVATAR_SIZE, type AvatarColor, type AvatarSize} from '../../types/Avatar'
3
- import {type PropDef} from '../../types/PropDef'
5
+ import type {PropDef} from '../../types/PropDef'
4
6
  import type {Responsive} from '../../types/Responsive'
5
7
  import {TEXT_SIZE} from '../../types/Text'
6
8
 
7
9
  /** @public */
8
- export interface AvatarProps extends React.ComponentProps<'figure'> {
10
+ export interface AvatarProps extends ComponentProps<'figure'> {
9
11
  /** Avatar color */
10
12
  color?: AvatarColor
11
13
  /** Avatar name, only first letter will be displayed */
@@ -1,10 +1,12 @@
1
+ import type {ComponentProps} from 'react'
2
+
1
3
  import {heightProps} from '../../props/height'
2
4
  import {AVATAR_SIZE, type AvatarSize} from '../../types/Avatar'
3
- import {type PropDef} from '../../types/PropDef'
5
+ import type {PropDef} from '../../types/PropDef'
4
6
  import {TEXT_SIZE} from '../../types/Text'
5
7
 
6
8
  /** @public */
7
- export interface AvatarCounterProps extends React.ComponentProps<'figure'> {
9
+ export interface AvatarCounterProps extends ComponentProps<'figure'> {
8
10
  /** Count */
9
11
  count: number
10
12
  /** Composite prop for setting height and font size */
@@ -1,8 +1,10 @@
1
+ import type {ComponentProps} from 'react'
2
+
1
3
  import {AVATAR_SIZE, type AvatarSize} from '../../types/Avatar'
2
- import {type PropDef} from '../../types/PropDef'
4
+ import type {PropDef} from '../../types/PropDef'
3
5
 
4
6
  /** @public */
5
- export interface AvatarStackProps extends React.ComponentProps<'ul'> {
7
+ export interface AvatarStackProps extends ComponentProps<'ul'> {
6
8
  /** Max number of avatars to display */
7
9
  maxLength?: number
8
10
  /** Avatar and AvatarCounter size */
@@ -1,5 +1,5 @@
1
1
  import clsx from 'clsx'
2
- import {isValidElement, type ComponentPropsWithRef, type ElementType} from 'react'
2
+ import {isValidElement, type ElementType} from 'react'
3
3
 
4
4
  import {getProps} from '../../utils/getProps'
5
5
  import {suffixClassName} from '../../utils/suffixClassName'
@@ -10,10 +10,7 @@ import {type BadgeProps, badgeProps} from './badge.props'
10
10
  const badgeClassName = suffixClassName('sui-Badge')
11
11
 
12
12
  /** @public */
13
- export function Badge<T extends ElementType = 'span'>({
14
- tone = 'neutral',
15
- ...props
16
- }: BadgeProps<T> & Omit<ComponentPropsWithRef<T>, keyof BadgeProps<T>>) {
13
+ export function Badge<T extends ElementType = 'span'>({tone = 'neutral', ...props}: BadgeProps<T>) {
17
14
  const {
18
15
  as,
19
16
  children,
@@ -1,21 +1,21 @@
1
+ import type {ReactNode, ElementType} from 'react'
2
+
1
3
  import {type ToneProps, toneProps} from '../../props/tone'
2
- import {type PropDef} from '../../types/PropDef'
4
+ import type {Polymorphic} from '../../types/Polymorphic'
5
+ import type {PropDef} from '../../types/PropDef'
3
6
 
4
7
  /** @public */
5
- export interface BadgeProps<T extends React.ElementType = 'span'> extends ToneProps {
6
- /**
7
- * HTML element to render.
8
- */
9
- as?: T
10
- /**
11
- * Shows an icon in the start position (left side in left-to-right languages).
12
- */
13
- iconStart?: React.ElementType | React.ReactNode
14
- /**
15
- * Sets Badge's text label. Use instead of children unless you have a special use case.
16
- */
17
- text?: string
18
- }
8
+ export type BadgeProps<T extends ElementType = 'span'> = Polymorphic<
9
+ T,
10
+ ToneProps & {
11
+ /** HTML element to render. */
12
+ as?: T
13
+ /** Shows an icon in the start position (left side in left-to-right languages). */
14
+ iconStart?: ElementType | ReactNode
15
+ /** Sets Badge's text label. Use instead of children unless you have a special use case. */
16
+ text?: string
17
+ }
18
+ >
19
19
 
20
20
  export const badgeProps: Record<string, PropDef> = {
21
21
  as: {
@@ -1,5 +1,5 @@
1
1
  import clsx from 'clsx'
2
- import type {ComponentPropsWithRef, ElementType} from 'react'
2
+ import type {ElementType} from 'react'
3
3
 
4
4
  import {getProps} from '../../utils/getProps'
5
5
  import {suffixClassName} from '../../utils/suffixClassName'
@@ -8,10 +8,7 @@ import {type BoxProps, boxProps} from './box.props'
8
8
  const boxClassName = suffixClassName('sui-Box')
9
9
 
10
10
  /** @public */
11
- export function Box<T extends ElementType = 'div'>({
12
- display = 'block',
13
- ...props
14
- }: BoxProps<T> & Omit<ComponentPropsWithRef<T>, keyof BoxProps<T>>) {
11
+ export function Box<T extends ElementType = 'div'>({display = 'block', ...props}: BoxProps<T>) {
15
12
  const {as, children, className, style, ...rest} = getProps({display, ...props}, boxProps)
16
13
  const Component = as || 'div'
17
14
 
@@ -1,20 +1,26 @@
1
+ import type {ElementType} from 'react'
2
+
1
3
  import {type LayoutProps, layoutProps} from '../../props/layout'
2
4
  import {DISPLAY_BLOCK, type DisplayBlock} from '../../types/Display'
3
- import {type PropDef} from '../../types/PropDef'
5
+ import type {Polymorphic} from '../../types/Polymorphic'
6
+ import type {PropDef} from '../../types/PropDef'
4
7
  import type {Responsive} from '../../types/Responsive'
5
8
 
6
9
  /** @public */
7
- export interface BoxProps<T extends React.ElementType = 'div'> extends LayoutProps {
8
- /**
9
- * HTML element or component to render.
10
- */
11
- as?: T
12
- /**
13
- * CSS `display` property.
14
- * @remarks Does not include `'flex'` or `'grid'`. Use the Flex or Grid components for those.
15
- */
16
- display?: Responsive<DisplayBlock>
17
- }
10
+ export type BoxProps<T extends ElementType = 'div'> = Polymorphic<
11
+ T,
12
+ LayoutProps & {
13
+ /**
14
+ * HTML element or component to render.
15
+ */
16
+ as?: T
17
+ /**
18
+ * CSS `display` property.
19
+ * @remarks Does not include `'flex'` or `'grid'`. Use the Flex or Grid components for those.
20
+ */
21
+ display?: Responsive<DisplayBlock>
22
+ }
23
+ >
18
24
 
19
25
  export const boxProps: Record<string, PropDef> = {
20
26
  as: {
@@ -1,5 +1,5 @@
1
1
  import clsx from 'clsx'
2
- import {type ComponentPropsWithRef, type ElementType, isValidElement} from 'react'
2
+ import {type ElementType, isValidElement} from 'react'
3
3
 
4
4
  import {getProps} from '../../utils/getProps'
5
5
  import {suffixClassName} from '../../utils/suffixClassName'
@@ -17,7 +17,7 @@ export function Button<T extends ElementType = 'button'>({
17
17
  level = 'primary',
18
18
  tone = 'neutral',
19
19
  ...props
20
- }: ButtonProps<T> & Omit<ComponentPropsWithRef<T>, keyof ButtonProps<T>>) {
20
+ }: ButtonProps<T>) {
21
21
  const {
22
22
  as,
23
23
  children,
@@ -1,3 +1,5 @@
1
+ import type {ReactNode, ElementType} from 'react'
2
+
1
3
  import {gapProps} from '../../props/gap'
2
4
  import {heightProps} from '../../props/height'
3
5
  import {paddingProps} from '../../props/padding'
@@ -11,52 +13,56 @@ import {
11
13
  type ButtonTone,
12
14
  } from '../../types/Button'
13
15
  import type {InteractiveAs} from '../../types/Interactive'
14
- import {type PropDef} from '../../types/PropDef'
16
+ import type {Polymorphic} from '../../types/Polymorphic'
17
+ import type {PropDef} from '../../types/PropDef'
15
18
  import type {Responsive} from '../../types/Responsive'
16
19
 
17
20
  /** @public */
18
- export interface ButtonProps<T extends React.ElementType = 'button'> {
19
- /**
20
- * HTML element to render.
21
- */
22
- as?: InteractiveAs<T>
23
- /**
24
- * Sets padding and gap together to specify size.
25
- */
26
- density?: ButtonDensity
27
- /**
28
- * Sets Button to fill the width of its container.
29
- */
30
- fullWidth?: Responsive<boolean>
31
- /**
32
- * Shows an icon in the start position (left side in left-to-right languages).
33
- */
34
- iconStart?: React.ElementType | React.ReactNode
35
- /**
36
- * Shows an icon in the end position (right side in left-to-right languages).
37
- */
38
- iconEnd?: React.ElementType | React.ReactNode
39
- /**
40
- * Sets the importance of Button's action.
41
- */
42
- level?: ButtonLevel
43
- /**
44
- * Places Button into a loading state.
45
- */
46
- loading?: boolean
47
- /**
48
- * Visually styles the button in a pressed state, and sets aria-pressed to the provided value
49
- */
50
- pressed?: boolean
51
- /**
52
- * Sets Button's text label.
53
- */
54
- text?: string
55
- /**
56
- * Sets Button's semantic meaning and related color.
57
- */
58
- tone?: ButtonTone
59
- }
21
+ export type ButtonProps<T extends ElementType = 'button'> = Polymorphic<
22
+ T,
23
+ {
24
+ /**
25
+ * HTML element to render.
26
+ */
27
+ as?: InteractiveAs<T>
28
+ /**
29
+ * Sets padding and gap together to specify size.
30
+ */
31
+ density?: ButtonDensity
32
+ /**
33
+ * Sets Button to fill the width of its container.
34
+ */
35
+ fullWidth?: Responsive<boolean>
36
+ /**
37
+ * Shows an icon in the start position (left side in left-to-right languages).
38
+ */
39
+ iconStart?: ElementType | ReactNode
40
+ /**
41
+ * Shows an icon in the end position (right side in left-to-right languages).
42
+ */
43
+ iconEnd?: ElementType | ReactNode
44
+ /**
45
+ * Sets the importance of Button's action.
46
+ */
47
+ level?: ButtonLevel
48
+ /**
49
+ * Places Button into a loading state.
50
+ */
51
+ loading?: boolean
52
+ /**
53
+ * Visually styles the button in a pressed state, and sets aria-pressed to the provided value
54
+ */
55
+ pressed?: boolean
56
+ /**
57
+ * Sets Button's text label.
58
+ */
59
+ text?: string
60
+ /**
61
+ * Sets Button's semantic meaning and related color.
62
+ */
63
+ tone?: ButtonTone
64
+ }
65
+ >
60
66
 
61
67
  export const buttonProps: Record<string, PropDef> = {
62
68
  as: {
@@ -1,5 +1,5 @@
1
1
  import clsx from 'clsx'
2
- import type {ComponentPropsWithRef, ElementType} from 'react'
2
+ import type {ElementType} from 'react'
3
3
 
4
4
  import {getProps} from '../../utils/getProps'
5
5
  import {suffixClassName} from '../../utils/suffixClassName'
@@ -12,7 +12,7 @@ export function Card<T extends ElementType = 'div'>({
12
12
  density = 'regular',
13
13
  tone = 'default',
14
14
  ...props
15
- }: CardProps<T> & Omit<ComponentPropsWithRef<T>, keyof CardProps<T>>) {
15
+ }: CardProps<T>) {
16
16
  const {as, children, className, style, ...rest} = getProps({density, tone, ...props}, cardProps)
17
17
  const Component = as || 'div'
18
18
 
@@ -1,24 +1,30 @@
1
+ import type {ElementType} from 'react'
2
+
1
3
  import {borderProps} from '../../props/border'
2
4
  import {gapProps} from '../../props/gap'
3
5
  import {type MarginProps, marginProps} from '../../props/margin'
4
6
  import {paddingProps} from '../../props/padding'
5
7
  import {toneWithDefaultProps, type ToneWithDefaultProps} from '../../props/tone'
6
8
  import {DENSITY, type Density} from '../../types/Density'
7
- import {type PropDef} from '../../types/PropDef'
8
- import {type Responsive} from '../../types/Responsive'
9
+ import type {Polymorphic} from '../../types/Polymorphic'
10
+ import type {PropDef} from '../../types/PropDef'
11
+ import type {Responsive} from '../../types/Responsive'
9
12
 
10
13
  /** @public */
11
- export interface CardProps<T extends React.ElementType = 'div'>
12
- extends MarginProps, ToneWithDefaultProps {
13
- /**
14
- * HTML element or component to render.
15
- */
16
- as?: T
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
- */
20
- density?: Responsive<Density>
21
- }
14
+ export type CardProps<T extends ElementType = 'div'> = Polymorphic<
15
+ T,
16
+ MarginProps &
17
+ ToneWithDefaultProps & {
18
+ /**
19
+ * HTML element or component to render.
20
+ */
21
+ as?: T
22
+ /**
23
+ * Sets padding, gap, and border-radius together to specify size. This prop is used in place of separate `padding`, `gap`, and `border-radius` props.
24
+ */
25
+ density?: Responsive<Density>
26
+ }
27
+ >
22
28
 
23
29
  export const cardProps: Record<string, PropDef> = {
24
30
  as: {
@@ -3,6 +3,7 @@ import {RemoveIcon} from '@sanity/icons/Remove'
3
3
  import clsx from 'clsx'
4
4
  import {useEffect, useRef} from 'react'
5
5
 
6
+ import {composeRefs} from '../../utils/composeRefs'
6
7
  import {getProps} from '../../utils/getProps'
7
8
  import {suffixClassName} from '../../utils/suffixClassName'
8
9
  import {Box} from '../box/Box'
@@ -12,7 +13,7 @@ const checkboxClassName = suffixClassName('sui-Checkbox')
12
13
  const checkboxInputClassName = suffixClassName('sui-CheckboxInput')
13
14
 
14
15
  /** @beta */
15
- export function Checkbox(props: CheckboxProps) {
16
+ export function Checkbox({ref, ...props}: CheckboxProps) {
16
17
  const inputRef = useRef<HTMLInputElement>(null)
17
18
  const {className, style, hasError, indeterminate, ...rest} = getProps(props, checkboxProps)
18
19
 
@@ -38,7 +39,7 @@ export function Checkbox(props: CheckboxProps) {
38
39
  <input
39
40
  type="checkbox"
40
41
  className={checkboxInputClassName}
41
- ref={inputRef}
42
+ ref={composeRefs(inputRef, ref)}
42
43
  aria-invalid={hasError || undefined}
43
44
  {...rest}
44
45
  />
@@ -1,7 +1,9 @@
1
- import {type PropDef} from '../../types/PropDef'
1
+ import type {ComponentProps} from 'react'
2
+
3
+ import type {PropDef} from '../../types/PropDef'
2
4
 
3
5
  /** @beta */
4
- export interface CheckboxProps extends React.ComponentProps<'input'> {
6
+ export interface CheckboxProps extends ComponentProps<'input'> {
5
7
  /**
6
8
  * Applies error styling to the checkbox mark for invalid states.
7
9
  * @remarks Use when form validation fails. Pair with a visible error message.
@@ -1,7 +1,9 @@
1
+ import type {ComponentPropsWithRef} from 'react'
2
+
1
3
  import {marginProps, type MarginProps} from '../../props/margin'
2
4
  import {type TypographyProps, typographyProps} from '../../props/typography'
3
5
  import {CODE_SIZE, type CodeSize} from '../../types/Code'
4
- import {type PropDef} from '../../types/PropDef'
6
+ import type {PropDef} from '../../types/PropDef'
5
7
  import type {Responsive} from '../../types/Responsive'
6
8
 
7
9
  interface CodeBaseProps
@@ -24,10 +26,10 @@ export type CodeProps =
24
26
  * @remarks Block code is wrapped in a `<pre>` tag.
25
27
  */
26
28
  inline?: false
27
- } & Omit<React.ComponentPropsWithRef<'pre'>, keyof CodeBaseProps>)
29
+ } & Omit<ComponentPropsWithRef<'pre'>, keyof CodeBaseProps>)
28
30
  | (CodeBaseProps & {
29
31
  inline: true
30
- } & Omit<React.ComponentPropsWithRef<'span'>, keyof CodeBaseProps>)
32
+ } & Omit<ComponentPropsWithRef<'span'>, keyof CodeBaseProps>)
31
33
 
32
34
  export const codeProps: Record<string, PropDef> = {
33
35
  inline: {
@@ -1,5 +1,5 @@
1
1
  import clsx from 'clsx'
2
- import type {ComponentPropsWithRef, ElementType} from 'react'
2
+ import type {ElementType} from 'react'
3
3
 
4
4
  import {getProps} from '../../utils/getProps'
5
5
  import {suffixClassName} from '../../utils/suffixClassName'
@@ -12,7 +12,7 @@ export function Container<T extends ElementType = 'div'>({
12
12
  marginX = 'auto',
13
13
  size = 2,
14
14
  ...props
15
- }: ContainerProps<T> & Omit<ComponentPropsWithRef<T>, keyof ContainerProps<T>>) {
15
+ }: ContainerProps<T>) {
16
16
  const {as, children, className, style, ...rest} = getProps(
17
17
  {marginX, size, ...props},
18
18
  containerProps,
@@ -1,19 +1,25 @@
1
+ import type {ElementType} from 'react'
2
+
1
3
  import {type LayoutProps, layoutProps} from '../../props/layout'
2
4
  import {CONTAINER_SIZE, type ContainerSize} from '../../types/Container'
3
- import {type PropDef} from '../../types/PropDef'
5
+ import type {Polymorphic} from '../../types/Polymorphic'
6
+ import type {PropDef} from '../../types/PropDef'
4
7
  import type {Responsive} from '../../types/Responsive'
5
8
 
6
9
  /** @public */
7
- export interface ContainerProps<T extends React.ElementType = 'div'> extends LayoutProps {
8
- /**
9
- * HTML element or component to render.
10
- */
11
- as?: T
12
- /**
13
- * Maximum width of the container.
14
- */
15
- size?: Responsive<ContainerSize>
16
- }
10
+ export type ContainerProps<T extends ElementType = 'div'> = Polymorphic<
11
+ T,
12
+ LayoutProps & {
13
+ /**
14
+ * HTML element or component to render.
15
+ */
16
+ as?: T
17
+ /**
18
+ * Maximum width of the container.
19
+ */
20
+ size?: Responsive<ContainerSize>
21
+ }
22
+ >
17
23
 
18
24
  export const containerProps: Record<string, PropDef> = {
19
25
  as: {
@@ -1,20 +1,26 @@
1
1
  import {CloseIcon} from '@sanity/icons/Close'
2
2
  import clsx from 'clsx'
3
- import {type ComponentProps, useEffect, useId, useRef} from 'react'
3
+ import {useEffect, useId, useRef} from 'react'
4
4
 
5
+ import {composeRefs} from '../../utils/composeRefs'
5
6
  import {getProps} from '../../utils/getProps'
6
7
  import {suffixClassName} from '../../utils/suffixClassName'
7
8
  import {Box} from '../box/Box'
8
9
  import {Flex} from '../flex/Flex'
9
10
  import {Heading} from '../heading/Heading'
10
11
  import {IconButton} from '../icon-button/IconButton'
11
- import {type DialogProps, dialogProps} from './dialog.props'
12
+ import {
13
+ type DialogContentProps,
14
+ type DialogFooterProps,
15
+ type DialogProps,
16
+ dialogProps,
17
+ } from './dialog.props'
12
18
 
13
19
  const dialogClassName = suffixClassName('sui-Dialog')
14
20
  const dialogContentClassName = suffixClassName('sui-DialogContent')
15
21
  const dialogFooterClassName = suffixClassName('sui-DialogFooter')
16
22
 
17
- function DialogRoot({open = false, size = 0, ...props}: DialogProps) {
23
+ function DialogRoot({open = false, size = 0, ref, ...props}: DialogProps) {
18
24
  const {children, className, style, header, onClose, ...rest} = getProps(
19
25
  {size, ...props},
20
26
  dialogProps,
@@ -56,7 +62,7 @@ function DialogRoot({open = false, size = 0, ...props}: DialogProps) {
56
62
  return (
57
63
  <dialog
58
64
  {...rest}
59
- ref={dialogRef}
65
+ ref={composeRefs(dialogRef, ref)}
60
66
  closedby="any"
61
67
  aria-labelledby={header ? headerId : undefined}
62
68
  onClose={onClose}
@@ -84,7 +90,7 @@ function DialogRoot({open = false, size = 0, ...props}: DialogProps) {
84
90
  )
85
91
  }
86
92
 
87
- function DialogContent(props: ComponentProps<'div'>) {
93
+ function DialogContent(props: DialogContentProps) {
88
94
  const {children, className, style, ...rest} = getProps(props, {})
89
95
 
90
96
  return (
@@ -101,7 +107,7 @@ function DialogContent(props: ComponentProps<'div'>) {
101
107
  )
102
108
  }
103
109
 
104
- function DialogFooter(props: ComponentProps<'div'>) {
110
+ function DialogFooter(props: DialogFooterProps) {
105
111
  const {children, className, style, ...rest} = getProps(props, {})
106
112
 
107
113
  return (
@@ -136,4 +142,4 @@ export const Dialog = DialogRoot
136
142
  DialogRoot.Content = DialogContent
137
143
  DialogRoot.Footer = DialogFooter
138
144
 
139
- export type {DialogProps}
145
+ export type {DialogProps, DialogContentProps, DialogFooterProps}
@@ -1,9 +1,11 @@
1
+ import type {ComponentProps, ReactEventHandler} from 'react'
2
+
1
3
  import {CONTAINER_SIZE, type ContainerSize} from '../../types/Container'
2
- import {type PropDef} from '../../types/PropDef'
4
+ import type {PropDef} from '../../types/PropDef'
3
5
  import type {Responsive} from '../../types/Responsive'
4
6
 
5
7
  /** @beta */
6
- export interface DialogProps extends Omit<React.ComponentProps<'dialog'>, 'open'> {
8
+ export interface DialogProps extends Omit<ComponentProps<'dialog'>, 'open'> {
7
9
  /**
8
10
  * Text for the dialog heading.
9
11
  * @remarks Recommended for accessibility. The component sets `aria-labelledby` to the heading when you give this prop.
@@ -13,7 +15,7 @@ export interface DialogProps extends Omit<React.ComponentProps<'dialog'>, 'open'
13
15
  * A function to call alongside the native `close` event.
14
16
  * @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
17
  */
16
- onClose: React.ReactEventHandler<HTMLDialogElement>
18
+ onClose: ReactEventHandler<HTMLDialogElement>
17
19
  /**
18
20
  * Toggles the dialog's open state.
19
21
  * @remarks `true` calls `showModal()` on the element. `false` calls `close()`.
@@ -43,3 +45,9 @@ export const dialogProps: Record<string, PropDef> = {
43
45
  variable: '--top-anchor',
44
46
  },
45
47
  }
48
+
49
+ /** @beta */
50
+ export interface DialogContentProps extends ComponentProps<'div'> {}
51
+
52
+ /** @beta */
53
+ export interface DialogFooterProps extends ComponentProps<'div'> {}
@@ -1,8 +1,10 @@
1
+ import type {ComponentProps} from 'react'
2
+
1
3
  import {type MarginProps, marginProps} from '../../props/margin'
2
- import {type PropDef} from '../../types/PropDef'
4
+ import type {PropDef} from '../../types/PropDef'
3
5
 
4
6
  /** @public */
5
- export interface DividerProps extends React.ComponentProps<'hr'>, MarginProps {}
7
+ export interface DividerProps extends ComponentProps<'hr'>, MarginProps {}
6
8
 
7
9
  export const dividerProps: Record<string, PropDef> = {
8
10
  ...marginProps,
@@ -1,5 +1,5 @@
1
1
  import clsx from 'clsx'
2
- import type {ComponentPropsWithRef, ElementType} from 'react'
2
+ import type {ElementType} from 'react'
3
3
 
4
4
  import {getProps} from '../../utils/getProps'
5
5
  import {suffixClassName} from '../../utils/suffixClassName'
@@ -8,10 +8,7 @@ import {type EyebrowProps, eyebrowProps} from './eyebrow.props'
8
8
  const eyebrowClassName = suffixClassName('sui-Eyebrow')
9
9
 
10
10
  /** @public */
11
- export function Eyebrow<T extends ElementType = 'span'>({
12
- size = 2,
13
- ...props
14
- }: EyebrowProps<T> & Omit<ComponentPropsWithRef<T>, keyof EyebrowProps<T>>) {
11
+ export function Eyebrow<T extends ElementType = 'span'>({size = 2, ...props}: EyebrowProps<T>) {
15
12
  const {as, children, className, style, ...rest} = getProps({size, ...props}, eyebrowProps)
16
13
  const Component = as || 'span'
17
14
 
@@ -1,22 +1,29 @@
1
+ import type {ElementType} from 'react'
2
+
1
3
  import {marginProps, type MarginProps} from '../../props/margin'
2
4
  import {toneProps, type ToneProps} from '../../props/tone'
3
5
  import {type TypographyProps, typographyProps} from '../../props/typography'
4
6
  import {EYEBROW_SIZE, type EyebrowSize} from '../../types/Eyebrow'
5
- import {type PropDef} from '../../types/PropDef'
7
+ import type {Polymorphic} from '../../types/Polymorphic'
8
+ import type {PropDef} from '../../types/PropDef'
6
9
  import type {Responsive} from '../../types/Responsive'
7
10
 
8
11
  /** @public */
9
- export interface EyebrowProps<T extends React.ElementType = 'span'>
10
- extends MarginProps, ToneProps, Omit<TypographyProps, 'weight'> {
11
- /**
12
- * HTML element to render.
13
- */
14
- as?: T
15
- /**
16
- * Sets font size. Uses the same scale as Label.
17
- */
18
- size?: Responsive<EyebrowSize>
19
- }
12
+ export type EyebrowProps<T extends ElementType = 'span'> = Polymorphic<
13
+ T,
14
+ MarginProps &
15
+ ToneProps &
16
+ Omit<TypographyProps, 'weight'> & {
17
+ /**
18
+ * HTML element to render.
19
+ */
20
+ as?: T
21
+ /**
22
+ * Sets font size. Uses the same scale as Label.
23
+ */
24
+ size?: Responsive<EyebrowSize>
25
+ }
26
+ >
20
27
 
21
28
  export const eyebrowProps: Record<string, PropDef> = {
22
29
  as: {