@sanity/ui 3.2.0 → 3.3.0

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 (59) hide show
  1. package/dist/_chunks-cjs/_visual-editing.js +54 -43
  2. package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
  3. package/dist/_chunks-es/_visual-editing.mjs +54 -43
  4. package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
  5. package/dist/_visual-editing.d.mts +129 -75
  6. package/dist/_visual-editing.d.ts +129 -75
  7. package/dist/index.d.mts +222 -139
  8. package/dist/index.d.ts +222 -139
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/theme.d.mts +10 -4
  12. package/dist/theme.d.ts +10 -4
  13. package/package.json +1 -1
  14. package/src/core/components/autocomplete/autocomplete.tsx +1 -1
  15. package/src/core/components/autocomplete/types.ts +2 -2
  16. package/src/core/components/menu/__workshop__/asComponent.tsx +1 -1
  17. package/src/core/components/menu/menuDivider.ts +16 -5
  18. package/src/core/components/menu/menuGroup.spacing.test.tsx +1 -7
  19. package/src/core/components/menu/menuGroup.tsx +14 -6
  20. package/src/core/components/menu/menuItem.tsx +17 -6
  21. package/src/core/components/skeleton/skeleton.tsx +2 -2
  22. package/src/core/components/tab/tabList.tsx +2 -2
  23. package/src/core/components/tab/tabPanel.tsx +2 -2
  24. package/src/core/components/toast/styles.ts +2 -2
  25. package/src/core/components/tree/__workshop__/basic.perf.ts +1 -1
  26. package/src/core/components/tree/__workshop__/tabFromElement.tsx +1 -1
  27. package/src/core/components/tree/tree.tsx +9 -6
  28. package/src/core/components/tree/treeGroup.tsx +1 -1
  29. package/src/core/components/tree/treeItem.tsx +3 -2
  30. package/src/core/primitives/avatar/avatar.tsx +19 -11
  31. package/src/core/primitives/badge/badge.tsx +20 -12
  32. package/src/core/primitives/box/__workshop__/asComponent.tsx +31 -0
  33. package/src/core/primitives/box/__workshop__/index.ts +5 -0
  34. package/src/core/primitives/box/box.test.tsx +12 -4
  35. package/src/core/primitives/box/box.tsx +23 -12
  36. package/src/core/primitives/button/__workshop__/disabled.tsx +2 -2
  37. package/src/core/primitives/button/__workshop__/sanityUploadButton.tsx +1 -1
  38. package/src/core/primitives/button/__workshop__/uploadButton.tsx +1 -1
  39. package/src/core/primitives/button/button.test.tsx +3 -3
  40. package/src/core/primitives/button/button.tsx +28 -9
  41. package/src/core/primitives/card/__workshop__/asComponent.tsx +1 -1
  42. package/src/core/primitives/card/card.tsx +24 -13
  43. package/src/core/primitives/code/code.tsx +16 -7
  44. package/src/core/primitives/container/container.tsx +23 -10
  45. package/src/core/primitives/flex/flex.tsx +21 -11
  46. package/src/core/primitives/grid/grid.test.tsx +3 -1
  47. package/src/core/primitives/grid/grid.tsx +22 -9
  48. package/src/core/primitives/heading/heading.tsx +19 -11
  49. package/src/core/primitives/inline/inline.tsx +19 -9
  50. package/src/core/primitives/kbd/kbd.tsx +19 -11
  51. package/src/core/primitives/label/label.tsx +19 -11
  52. package/src/core/primitives/popover/__workshop__/SidePanelStory.tsx +1 -1
  53. package/src/core/primitives/stack/stack.tsx +20 -11
  54. package/src/core/primitives/text/text.tsx +19 -11
  55. package/src/core/primitives/textInput/textInput.tsx +2 -2
  56. package/src/core/types/component.ts +32 -0
  57. package/src/core/types/index.ts +1 -0
  58. package/src/core/utils/virtualList/virtualList.tsx +2 -2
  59. package/src/theme/system/css.ts +10 -4
@@ -3,20 +3,24 @@ import {css, styled} from 'styled-components'
3
3
 
4
4
  import {_getArrayProp} from '../../styles'
5
5
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
6
- import {Radius} from '../../types'
6
+ import {ElementType, Props, Radius} from '../../types'
7
7
  import {Box} from '../box'
8
8
  import {Text} from '../text'
9
9
 
10
10
  /**
11
11
  * @public
12
12
  */
13
- export interface KBDProps {
14
- as?: React.ElementType | keyof React.JSX.IntrinsicElements
13
+ export interface KBDOwnProps {
15
14
  fontSize?: number | number[]
16
15
  padding?: number | number[]
17
16
  radius?: Radius | Radius[]
18
17
  }
19
18
 
19
+ /**
20
+ * @public
21
+ */
22
+ export type KBDProps<E extends ElementType = 'kbd'> = Props<KBDOwnProps, E>
23
+
20
24
  function kbdStyle() {
21
25
  return css`
22
26
  --card-bg-color: var(--card-kbd-bg-color);
@@ -37,13 +41,8 @@ function kbdStyle() {
37
41
 
38
42
  const StyledKBD = styled.kbd<ResponsiveRadiusStyleProps>(responsiveRadiusStyle, kbdStyle)
39
43
 
40
- /**
41
- * Used to define some text as keyboard input.
42
- *
43
- * @public
44
- */
45
- export const KBD = forwardRef(function KBD(
46
- props: KBDProps & Omit<React.HTMLProps<HTMLElement>, 'as' | 'ref' | 'size'>,
44
+ const KBDComponent = forwardRef(function KBD(
45
+ props: KBDOwnProps & {as?: ElementType} & Omit<React.HTMLProps<HTMLElement>, 'as' | 'ref' | 'size'>,
47
46
  ref: React.ForwardedRef<HTMLDivElement>,
48
47
  ) {
49
48
  const {children, fontSize = 0, padding = 1, radius = 2, ...restProps} = props
@@ -58,4 +57,13 @@ export const KBD = forwardRef(function KBD(
58
57
  </StyledKBD>
59
58
  )
60
59
  })
61
- KBD.displayName = 'ForwardRef(KBD)'
60
+ KBDComponent.displayName = 'ForwardRef(KBD)'
61
+
62
+ /**
63
+ * Used to define some text as keyboard input.
64
+ *
65
+ * @public
66
+ */
67
+ export const KBD = KBDComponent as unknown as <E extends ElementType = 'kbd'>(
68
+ props: KBDProps<E>,
69
+ ) => React.JSX.Element
@@ -4,17 +4,16 @@ import {styled} from 'styled-components'
4
4
 
5
5
  import {_getArrayProp} from '../../styles'
6
6
  import {responsiveLabelFont, responsiveTextAlignStyle} from '../../styles/internal'
7
- import {TextAlign} from '../../types'
7
+ import {ElementType, Props, TextAlign} from '../../types'
8
8
  import {SpanWithTextOverflow} from '../../utils/spanWithTextOverflow'
9
9
  import {labelBaseStyle} from './styles'
10
10
 
11
11
  /**
12
12
  * @public
13
13
  */
14
- export interface LabelProps {
14
+ export interface LabelOwnProps {
15
15
  accent?: boolean
16
16
  align?: TextAlign | TextAlign[]
17
- as?: React.ElementType | keyof React.JSX.IntrinsicElements
18
17
  muted?: boolean
19
18
  size?: number | number[]
20
19
  /**
@@ -26,6 +25,11 @@ export interface LabelProps {
26
25
  weight?: ThemeFontWeightKey
27
26
  }
28
27
 
28
+ /**
29
+ * @public
30
+ */
31
+ export type LabelProps<E extends ElementType = 'div'> = Props<LabelOwnProps, E>
32
+
29
33
  const StyledLabel = styled.div<{
30
34
  $accent?: boolean
31
35
  $align: TextAlign[]
@@ -33,13 +37,8 @@ const StyledLabel = styled.div<{
33
37
  $size: number[]
34
38
  }>(responsiveLabelFont, responsiveTextAlignStyle, labelBaseStyle)
35
39
 
36
- /**
37
- * Typographic labels.
38
- *
39
- * @public
40
- */
41
- export const Label = forwardRef(function Label(
42
- props: LabelProps & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'size'>,
40
+ const LabelComponent = forwardRef(function Label(
41
+ props: LabelOwnProps & {as?: ElementType} & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'size'>,
43
42
  ref: React.ForwardedRef<HTMLDivElement>,
44
43
  ) {
45
44
  const {
@@ -76,4 +75,13 @@ export const Label = forwardRef(function Label(
76
75
  </StyledLabel>
77
76
  )
78
77
  })
79
- Label.displayName = 'ForwardRef(Label)'
78
+ LabelComponent.displayName = 'ForwardRef(Label)'
79
+
80
+ /**
81
+ * Typographic labels.
82
+ *
83
+ * @public
84
+ */
85
+ export const Label = LabelComponent as unknown as <E extends ElementType = 'div'>(
86
+ props: LabelProps<E>,
87
+ ) => React.JSX.Element
@@ -34,7 +34,7 @@ export default function SidePanelStory() {
34
34
  </Box>
35
35
  </Card>
36
36
  <BoundaryElementProvider element={sidePanel}>
37
- <Card borderLeft flex="none" ref={setSidePanel} style={{width: sidePanelWidth}} width={0}>
37
+ <Card borderLeft flex="none" ref={setSidePanel} style={{width: sidePanelWidth}}>
38
38
  <Stack padding={4} space={5}>
39
39
  <Text muted size={1}>
40
40
  Click the <code>reference</code> text below to toggle the popover.
@@ -2,14 +2,14 @@ import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
4
  import {_getArrayProp} from '../../styles'
5
- import {Box, BoxProps} from '../box'
5
+ import {ElementType, Props} from '../../types'
6
+ import {Box, BoxOwnProps} from '../box'
6
7
  import {responsiveStackSpaceStyle, ResponsiveStackSpaceStyleProps, stackBaseStyle} from './styles'
7
8
 
8
9
  /**
9
10
  * @public
10
11
  */
11
- export interface StackProps extends BoxProps {
12
- as?: React.ElementType | keyof React.JSX.IntrinsicElements
12
+ export interface StackOwnProps extends BoxOwnProps {
13
13
  gap?: number | number[]
14
14
  /**
15
15
  * @deprecated Use `gap` instead. `space` will be removed in v4.
@@ -17,18 +17,18 @@ export interface StackProps extends BoxProps {
17
17
  space?: number | number[]
18
18
  }
19
19
 
20
+ /**
21
+ * @public
22
+ */
23
+ export type StackProps<E extends ElementType = 'div'> = Props<StackOwnProps, E>
24
+
20
25
  const StyledStack = styled(Box)<ResponsiveStackSpaceStyleProps>(
21
26
  stackBaseStyle,
22
27
  responsiveStackSpaceStyle,
23
28
  )
24
29
 
25
- /**
26
- * The `Stack` component is used to place elements on top of each other.
27
- *
28
- * @public
29
- */
30
- export const Stack = forwardRef(function Stack(
31
- props: StackProps & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'ref'>,
30
+ const StackComponent = forwardRef(function Stack(
31
+ props: StackOwnProps & {as?: ElementType} & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'ref'>,
32
32
  ref: React.ForwardedRef<HTMLDivElement>,
33
33
  ) {
34
34
  const {as, gap, space: deprecated_space, ...restProps} = props
@@ -45,4 +45,13 @@ export const Stack = forwardRef(function Stack(
45
45
  />
46
46
  )
47
47
  })
48
- Stack.displayName = 'ForwardRef(Stack)'
48
+ StackComponent.displayName = 'ForwardRef(Stack)'
49
+
50
+ /**
51
+ * The `Stack` component is used to place elements on top of each other.
52
+ *
53
+ * @public
54
+ */
55
+ export const Stack = StackComponent as unknown as <E extends ElementType = 'div'>(
56
+ props: StackProps<E>,
57
+ ) => React.JSX.Element
@@ -8,17 +8,16 @@ import {
8
8
  responsiveTextAlignStyle,
9
9
  responsiveTextFont,
10
10
  } from '../../styles/internal'
11
- import {TextAlign} from '../../types'
11
+ import {ElementType, Props, TextAlign} from '../../types'
12
12
  import {SpanWithTextOverflow} from '../../utils/spanWithTextOverflow'
13
13
  import {textBaseStyle} from './styles'
14
14
 
15
15
  /**
16
16
  * @public
17
17
  */
18
- export interface TextProps {
18
+ export interface TextOwnProps {
19
19
  accent?: boolean
20
20
  align?: TextAlign | TextAlign[]
21
- as?: React.ElementType | keyof React.JSX.IntrinsicElements
22
21
  /** When `true` the text color will be muted. */
23
22
  muted?: boolean
24
23
  size?: number | number[]
@@ -31,19 +30,19 @@ export interface TextProps {
31
30
  weight?: ThemeFontWeightKey
32
31
  }
33
32
 
33
+ /**
34
+ * @public
35
+ */
36
+ export type TextProps<E extends ElementType = 'div'> = Props<TextOwnProps, E>
37
+
34
38
  const StyledText = styled.div<ResponsiveFontStyleProps>(
35
39
  responsiveTextFont,
36
40
  responsiveTextAlignStyle,
37
41
  textBaseStyle,
38
42
  )
39
43
 
40
- /**
41
- * The `Text` component is an agile, themed typographic element.
42
- *
43
- * @public
44
- */
45
- export const Text = forwardRef(function Text(
46
- props: TextProps & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'size'>,
44
+ const TextComponent = forwardRef(function Text(
45
+ props: TextOwnProps & {as?: ElementType} & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'size'>,
47
46
  ref: React.ForwardedRef<HTMLDivElement>,
48
47
  ) {
49
48
  const {
@@ -78,4 +77,13 @@ export const Text = forwardRef(function Text(
78
77
  </StyledText>
79
78
  )
80
79
  })
81
- Text.displayName = 'ForwardRef(Text)'
80
+ TextComponent.displayName = 'ForwardRef(Text)'
81
+
82
+ /**
83
+ * The `Text` component is an agile, themed typographic element.
84
+ *
85
+ * @public
86
+ */
87
+ export const Text = TextComponent as unknown as <E extends ElementType = 'div'>(
88
+ props: TextProps<E>,
89
+ ) => React.JSX.Element
@@ -22,14 +22,14 @@ import {
22
22
  import {useRootTheme} from '../../theme'
23
23
  import {Radius} from '../../types'
24
24
  import {Box} from '../box'
25
- import {Button, ButtonProps} from '../button'
25
+ import {Button, ButtonOwnProps} from '../button'
26
26
  import {Card} from '../card'
27
27
  import {Text} from '../text'
28
28
 
29
29
  /**
30
30
  * @public
31
31
  */
32
- export type TextInputClearButtonProps = Omit<ButtonProps, 'as'> &
32
+ export type TextInputClearButtonProps = ButtonOwnProps &
33
33
  Omit<React.HTMLProps<HTMLButtonElement>, 'as' | 'onClick' | 'onMouseDown' | 'ref'>
34
34
 
35
35
  /**
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Assign properties from `U` to `T`, excluding properties that already exist in `T`.
3
+ *
4
+ * @public
5
+ */
6
+ export type Assign<T extends object, U extends object> = Omit<T, keyof U> & U
7
+
8
+ /** @public */
9
+ export type EmptyProps = object
10
+
11
+ /** @public */
12
+ export type TagType = keyof React.JSX.IntrinsicElements
13
+
14
+ /** @public */
15
+ export type ComponentType<P = any> =
16
+ | React.FunctionComponent<P>
17
+ | React.ComponentClass<P>
18
+ | React.ExoticComponent<P>
19
+
20
+ /** @public */
21
+ export type ElementType<P = any> = TagType | ComponentType<P>
22
+
23
+ /**
24
+ * Resolves the props of a polymorphic component: the props of the element/component passed to `as`
25
+ * (defaulting to the component's own element), with the component's own props assigned on top.
26
+ *
27
+ * @public
28
+ */
29
+ export type Props<P extends EmptyProps, E extends ElementType<P>> = Assign<
30
+ E extends TagType ? React.JSX.IntrinsicElements[E] : React.ComponentProps<E>,
31
+ P & {as?: E}
32
+ >
@@ -3,6 +3,7 @@ export * from './badge'
3
3
  export * from './box'
4
4
  export * from './button'
5
5
  export * from './card'
6
+ export * from './component'
6
7
  export * from './dialog'
7
8
  export * from './flex'
8
9
  export * from './grid'
@@ -3,7 +3,7 @@ import {styled} from 'styled-components'
3
3
 
4
4
  import {_isScrollable} from '../../helpers'
5
5
  import {_ResizeObserver} from '../../observers'
6
- import {StackProps} from '../../primitives'
6
+ import {StackOwnProps} from '../../primitives'
7
7
  import {useTheme_v2} from '../../theme'
8
8
 
9
9
  /**
@@ -45,7 +45,7 @@ const ItemWrapper = styled.div`
45
45
  */
46
46
  export const VirtualList = forwardRef(function VirtualList(
47
47
  props: VirtualListProps &
48
- StackProps &
48
+ StackOwnProps &
49
49
  Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'children' | 'onChange' | 'ref'>,
50
50
  forwardedRef: React.ForwardedRef<HTMLDivElement>,
51
51
  ): React.JSX.Element {
@@ -1,8 +1,14 @@
1
- import type {StyledObject} from 'styled-components'
1
+ import type * as CSS from 'csstype'
2
2
 
3
3
  /**
4
- * Work around types that are missing in `styled-components@6`
5
- * https://github.com/styled-components/styled-components/issues/4062
4
+ * A CSS-in-JS style object: standard CSS properties plus an index signature that allows nested
5
+ * selectors, at-rules and custom properties.
6
+ *
7
+ * This is a self-owned definition (based on `csstype`) so the published `.d.ts` types stay fully
8
+ * controlled by us and do not reference any external CSS-in-JS library types.
9
+ *
6
10
  * @internal
7
11
  */
8
- export type CSSObject = StyledObject<any>
12
+ export interface CSSObject extends CSS.Properties<number | (string & {})> {
13
+ [key: string]: CSSObject | string | number | undefined
14
+ }