@sanity/ui 3.0.0-static.27 → 3.0.0-static.29

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 (229) hide show
  1. package/README.md +5 -8
  2. package/dist/_chunks-cjs/_visual-editing.cjs +744 -874
  3. package/dist/_chunks-cjs/_visual-editing.cjs.map +1 -1
  4. package/dist/_chunks-cjs/refractor.cjs +2 -2
  5. package/dist/_chunks-cjs/refractor.cjs.map +1 -1
  6. package/dist/_chunks-es/_visual-editing.js +788 -917
  7. package/dist/_chunks-es/_visual-editing.js.map +1 -1
  8. package/dist/_chunks-es/refractor.js +1 -1
  9. package/dist/{css.cjs → css/index.cjs} +72 -53
  10. package/dist/css/index.cjs.map +1 -0
  11. package/dist/css/index.css +1 -0
  12. package/dist/{css.d.ts → css/index.d.cts} +26 -8
  13. package/dist/{css.d.cts → css/index.d.ts} +26 -8
  14. package/dist/{css.js → css/index.js} +72 -53
  15. package/dist/css/index.js.map +1 -0
  16. package/dist/css/layers.css +4 -0
  17. package/dist/css/primitives/popover/popover.css +4 -0
  18. package/dist/index.cjs +2049 -1811
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +62 -26
  21. package/dist/index.d.ts +62 -26
  22. package/dist/index.js +2056 -1819
  23. package/dist/index.js.map +1 -1
  24. package/dist/theme.cjs +7 -7
  25. package/dist/theme.cjs.map +1 -1
  26. package/dist/theme.js +7 -7
  27. package/dist/theme.js.map +1 -1
  28. package/exports/_visual-editing.ts +1 -1
  29. package/package.json +14 -19
  30. package/src/core/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
  31. package/src/core/components/autocomplete/__workshop__/fullscreen.tsx +1 -1
  32. package/src/core/components/autocomplete/autocomplete.tsx +15 -19
  33. package/src/core/components/autocomplete/autocompleteOption.tsx +1 -1
  34. package/src/core/components/autocomplete/constants.ts +3 -1
  35. package/src/core/components/autocomplete/types.ts +1 -1
  36. package/src/core/components/breadcrumbs/breadcrumbs.tsx +8 -3
  37. package/src/core/components/dialog/__workshop__/activate.tsx +11 -3
  38. package/src/core/components/dialog/__workshop__/panes.tsx +12 -5
  39. package/src/core/components/dialog/dialog.tsx +12 -6
  40. package/src/core/components/dialog/dialogCard.tsx +89 -54
  41. package/src/core/components/dialog/dialogContext.ts +1 -1
  42. package/src/core/components/dialog/dialogProvider.tsx +1 -1
  43. package/src/core/components/dialog/index.ts +1 -0
  44. package/src/core/components/dialog/isTargetWithinScope.ts +1 -1
  45. package/src/core/components/hotkeys/hotkeys.tsx +3 -2
  46. package/src/core/components/menu/__workshop__/avatarMenu.tsx +12 -6
  47. package/src/core/components/menu/__workshop__/customSelectedState.tsx +1 -5
  48. package/src/core/components/menu/__workshop__/shouldFocus.tsx +1 -2
  49. package/src/core/components/menu/helpers.ts +1 -1
  50. package/src/core/components/menu/menu.tsx +6 -3
  51. package/src/core/components/menu/menuButton.tsx +5 -3
  52. package/src/core/components/menu/menuDivider.tsx +1 -1
  53. package/src/core/components/menu/menuGroup.tsx +8 -4
  54. package/src/core/components/menu/menuItem.tsx +4 -2
  55. package/src/core/components/tab/tab.tsx +2 -2
  56. package/src/core/components/tab/tabList.tsx +2 -2
  57. package/src/core/components/tab/tabPanel.tsx +2 -2
  58. package/src/core/components/toast/toast.tsx +21 -17
  59. package/src/core/components/toast/toastLayer.tsx +3 -2
  60. package/src/core/components/toast/toastProvider.tsx +15 -11
  61. package/src/core/components/tree/tree.tsx +2 -2
  62. package/src/core/components/tree/treeGroup.tsx +2 -2
  63. package/src/core/components/tree/treeItem.tsx +13 -6
  64. package/src/core/components/tree/types.ts +0 -1
  65. package/src/core/components/virtualList/virtualList.tsx +10 -5
  66. package/src/core/helpers/focus.ts +0 -8
  67. package/src/core/hooks/useArrayProp.ts +1 -1
  68. package/src/core/hooks/useElementRect/__workshop__/example.tsx +1 -3
  69. package/src/core/hooks/useElementSize.ts +1 -1
  70. package/src/core/hooks/useResponsiveProp.ts +1 -1
  71. package/src/core/index.ts +84 -7
  72. package/src/core/observers/{elementSizeObserver.ts → elementSize.ts} +1 -1
  73. package/src/core/primitives/_selectable/index.ts +1 -0
  74. package/src/core/primitives/_selectable/selectable.tsx +13 -3
  75. package/src/core/{types/selectable.ts → primitives/_selectable/types.ts} +1 -1
  76. package/src/core/primitives/arrow/arrow.tsx +1 -1
  77. package/src/core/primitives/avatar/avatar.tsx +4 -3
  78. package/src/core/primitives/avatar/avatarCounter.tsx +3 -3
  79. package/src/core/primitives/avatar/avatarStack.tsx +4 -4
  80. package/src/core/primitives/avatar/types.ts +17 -0
  81. package/src/core/primitives/badge/badge.tsx +2 -1
  82. package/src/core/primitives/badge/types.ts +11 -2
  83. package/src/core/primitives/box/__workshop__/responsive.tsx +0 -1
  84. package/src/core/primitives/box/box.tsx +1 -1
  85. package/src/core/primitives/box/index.ts +1 -0
  86. package/src/core/primitives/button/__workshop__/disabled.tsx +37 -51
  87. package/src/core/primitives/button/__workshop__/index.ts +5 -0
  88. package/src/core/primitives/button/__workshop__/textOverflow.tsx +13 -0
  89. package/src/core/primitives/button/button.tsx +15 -14
  90. package/src/core/primitives/button/index.ts +1 -0
  91. package/src/core/primitives/card/__workshop__/listNavigation.tsx +2 -2
  92. package/src/core/primitives/card/card.tsx +1 -1
  93. package/src/core/primitives/card/types.ts +3 -0
  94. package/src/core/primitives/checkbox/__workshop__/tones.tsx +9 -1
  95. package/src/core/primitives/checkbox/checkbox.tsx +3 -4
  96. package/src/core/primitives/code/__workshop__/opticalAlignment.tsx +17 -42
  97. package/src/core/primitives/code/code.tsx +1 -1
  98. package/src/core/primitives/container/container.tsx +1 -1
  99. package/src/core/primitives/flex/flex.tsx +1 -1
  100. package/src/core/primitives/flex/index.ts +1 -0
  101. package/src/core/primitives/grid/grid.tsx +1 -1
  102. package/src/core/primitives/grid/index.ts +1 -0
  103. package/src/core/primitives/heading/heading.tsx +1 -1
  104. package/src/core/primitives/inline/inline.tsx +1 -1
  105. package/src/core/primitives/kbd/kbd.tsx +1 -1
  106. package/src/core/primitives/label/label.tsx +1 -1
  107. package/src/core/primitives/layer/layer.test.tsx +1 -1
  108. package/src/core/primitives/layer/layer.tsx +2 -2
  109. package/src/core/primitives/layer/layerCard.tsx +3 -3
  110. package/src/core/primitives/layer/layerProvider.tsx +2 -1
  111. package/src/core/primitives/popover/__workshop__/SidePanelStory.tsx +12 -10
  112. package/src/core/primitives/popover/__workshop__/TestStory.tsx +9 -8
  113. package/src/core/primitives/popover/constants.ts +1 -1
  114. package/src/core/primitives/popover/floating-ui/size.ts +1 -1
  115. package/src/core/primitives/popover/popover.tsx +7 -4
  116. package/src/core/primitives/popover/popoverLayer.tsx +2 -1
  117. package/src/core/primitives/popover/types.ts +5 -0
  118. package/src/core/primitives/radio/radio.tsx +2 -2
  119. package/src/core/primitives/root/Root.tsx +89 -0
  120. package/src/core/primitives/root/__workshop__/boundary.tsx +5 -0
  121. package/src/core/primitives/root/__workshop__/index.ts +8 -0
  122. package/src/core/primitives/root/index.ts +1 -0
  123. package/src/core/primitives/select/select.tsx +2 -2
  124. package/src/core/{components → primitives}/skeleton/__workshop__/index.ts +1 -1
  125. package/src/core/{components → primitives}/skeleton/codeSkeleton.tsx +1 -1
  126. package/src/core/{components → primitives}/skeleton/headingSkeleton.tsx +1 -1
  127. package/src/core/{components → primitives}/skeleton/labelSkeleton.tsx +1 -1
  128. package/src/core/{components → primitives}/skeleton/skeleton.tsx +7 -8
  129. package/src/core/{components → primitives}/skeleton/textSkeleton.tsx +1 -1
  130. package/src/core/primitives/spinner/spinner.tsx +1 -1
  131. package/src/core/primitives/srOnly/srOnly.tsx +1 -1
  132. package/src/core/primitives/stack/stack.tsx +1 -1
  133. package/src/core/primitives/switch/switch.tsx +1 -6
  134. package/src/core/primitives/text/__workshop__/colored.tsx +2 -2
  135. package/src/core/primitives/text/__workshop__/opticalAlignment.tsx +17 -42
  136. package/src/core/primitives/text/text.tsx +3 -1
  137. package/src/core/primitives/textArea/__workshop__/plain.tsx +2 -2
  138. package/src/core/primitives/textArea/textArea.tsx +2 -2
  139. package/src/core/primitives/textInput/textInput.tsx +3 -2
  140. package/src/core/primitives/tooltip/constants.ts +1 -1
  141. package/src/core/primitives/tooltip/tooltip.tsx +5 -3
  142. package/src/core/primitives/tooltip/tooltipLayer.tsx +1 -1
  143. package/src/core/primitives/types.ts +8 -10
  144. package/src/core/types/radius.ts +1 -1
  145. package/src/core/utils/elementQuery/__workshop__/customMedia.tsx +9 -5
  146. package/src/core/utils/elementQuery/elementQuery.tsx +2 -2
  147. package/src/core/utils/portal/portal.tsx +1 -1
  148. package/src/css/components/dialog/dialog.css.ts +26 -1
  149. package/src/css/components/dialog/dialog.ts +27 -7
  150. package/src/css/components/skeleton/skeleton.ts +3 -1
  151. package/src/css/components/skeleton/types.ts +3 -1
  152. package/src/css/components/toast/toast.css.ts +1 -0
  153. package/src/css/defaultTheme.css.ts +55 -2
  154. package/src/css/index.ts +77 -5
  155. package/src/css/primitives/_input/input.ts +2 -1
  156. package/src/css/primitives/_input/types.ts +2 -1
  157. package/src/css/primitives/_selectable/_selectable.css.ts +32 -24
  158. package/src/css/primitives/_selectable/selectable.ts +1 -1
  159. package/src/css/primitives/_selectable/types.ts +1 -1
  160. package/src/css/primitives/avatar/avatar.css.ts +8 -4
  161. package/src/css/primitives/avatar/avatar.ts +1 -1
  162. package/src/css/primitives/badge/types.ts +0 -2
  163. package/src/css/primitives/box/box.ts +35 -37
  164. package/src/css/primitives/box/types.ts +34 -36
  165. package/src/css/primitives/button/button.css.ts +4 -0
  166. package/src/css/primitives/button/button.ts +5 -2
  167. package/src/css/primitives/button/types.ts +4 -11
  168. package/src/css/primitives/card/__workshop__/color.tsx +70 -0
  169. package/src/css/primitives/card/__workshop__/index.ts +14 -0
  170. package/src/css/primitives/card/card.css.ts +4 -0
  171. package/src/css/primitives/code/code.ts +3 -1
  172. package/src/css/primitives/code/types.ts +2 -1
  173. package/src/css/primitives/container/container.ts +3 -1
  174. package/src/css/primitives/heading/heading.ts +4 -1
  175. package/src/css/primitives/heading/types.ts +3 -1
  176. package/src/css/primitives/kbd/kbd.ts +1 -1
  177. package/src/css/primitives/kbd/types.ts +1 -1
  178. package/src/css/primitives/label/label.ts +4 -1
  179. package/src/css/primitives/label/types.ts +3 -1
  180. package/src/css/primitives/root/index.ts +2 -0
  181. package/src/css/primitives/root/root.css.ts +15 -0
  182. package/src/css/primitives/root/root.ts +17 -0
  183. package/src/css/primitives/root/types.ts +10 -0
  184. package/src/css/primitives/switch/switch.css.ts +1 -1
  185. package/src/css/primitives/text/text.ts +6 -1
  186. package/src/css/primitives/text/types.ts +5 -2
  187. package/src/theme/v3/defaultFonts.ts +6 -6
  188. package/src/theme/v3/defaultTokens.ts +1 -1
  189. package/bin/sanity-ui.cjs +0 -5
  190. package/dist/css.cjs.map +0 -1
  191. package/dist/css.js.map +0 -1
  192. package/dist/ui.css +0 -1
  193. package/src/cli/buildCommand.ts +0 -10
  194. package/src/cli/index.ts +0 -26
  195. package/src/core/components/autocomplete/index.ts +0 -2
  196. package/src/core/components/index.ts +0 -10
  197. package/src/core/helpers/index.ts +0 -5
  198. package/src/core/hooks/index.ts +0 -13
  199. package/src/core/observers/index.ts +0 -2
  200. package/src/core/primitives/index.ts +0 -30
  201. package/src/core/types/avatar.ts +0 -16
  202. package/src/core/types/card.ts +0 -4
  203. package/src/core/types/index.ts +0 -15
  204. package/src/core/types/popover.ts +0 -4
  205. package/src/core/utils/index.ts +0 -4
  206. package/src/css/__theme/index.ts +0 -16
  207. package/src/css/__theme/lib/contract/buildVarContract.ts +0 -78
  208. package/src/css/__theme/lib/contract/index.ts +0 -4
  209. package/src/css/__theme/lib/contract/types.ts +0 -17
  210. package/src/css/__theme/resolveTheme.ts +0 -865
  211. package/src/css/components/index.ts +0 -6
  212. package/src/css/primitives/index.ts +0 -24
  213. package/src/css/props/index.ts +0 -37
  214. package/src/css/utils/srOnly/index.ts +0 -1
  215. /package/src/core/{global.ts → __DEV__.ts} +0 -0
  216. /package/src/core/{types/dialog.ts → components/dialog/types.ts} +0 -0
  217. /package/src/core/observers/{resizeObserver.ts → resize.ts} +0 -0
  218. /package/src/core/{types/badge.ts → primitives/badge/types2.ts} +0 -0
  219. /package/src/core/{types/box.ts → primitives/box/types.ts} +0 -0
  220. /package/src/core/{types/button.ts → primitives/button/types.ts} +0 -0
  221. /package/src/core/{types/flex.ts → primitives/flex/types.ts} +0 -0
  222. /package/src/core/{types/grid.ts → primitives/grid/types.ts} +0 -0
  223. /package/src/core/{components → primitives}/skeleton/__workshop__/delay.tsx +0 -0
  224. /package/src/core/{components → primitives}/skeleton/__workshop__/skeleton.tsx +0 -0
  225. /package/src/core/{components → primitives}/skeleton/index.ts +0 -0
  226. /package/src/core/types/{text.ts → textAlign.ts} +0 -0
  227. /package/src/css/{utils → primitives/srOnly}/index.ts +0 -0
  228. /package/src/css/{utils → primitives}/srOnly/srOnly.css.ts +0 -0
  229. /package/src/css/{utils → primitives}/srOnly/srOnly.ts +0 -0
@@ -1,4 +1,4 @@
1
- import type {ThemeColorSchemeKey} from '@sanity/ui/theme'
1
+ import type {Radius, ThemeColorSchemeKey} from '@sanity/ui/theme'
2
2
  import {
3
3
  cloneElement,
4
4
  type FocusEvent,
@@ -14,8 +14,10 @@ import {
14
14
  useState,
15
15
  } from 'react'
16
16
 
17
- import {type ButtonProps, Popover, type PopoverProps} from '../../primitives'
18
- import type {Placement, Props, Radius} from '../../types'
17
+ import type {ButtonProps} from '../../primitives/button'
18
+ import {Popover, type PopoverProps} from '../../primitives/popover'
19
+ import type {Placement} from '../../types/placement'
20
+ import type {Props} from '../../types/props'
19
21
  import type {MenuProps} from './menu'
20
22
 
21
23
  /** @public */
@@ -1,6 +1,6 @@
1
1
  import {menuDivider} from '@sanity/ui/css'
2
2
 
3
- import type {ComponentType, Props} from '../../types'
3
+ import type {ComponentType, Props} from '../../types/props'
4
4
 
5
5
  /** @public */
6
6
  export const DEFAULT_MENU_DIVIDER_ELEMENT = 'hr'
@@ -13,9 +13,12 @@ import {
13
13
  } from 'react'
14
14
  import {isValidElementType} from 'react-is'
15
15
 
16
- import {Box, Flex, Popover, type PopoverProps, Text} from '../../primitives'
17
16
  import {Selectable} from '../../primitives/_selectable'
18
- import type {ComponentType, Props} from '../../types'
17
+ import {Box} from '../../primitives/box'
18
+ import {Flex} from '../../primitives/flex'
19
+ import {Popover, type PopoverProps} from '../../primitives/popover'
20
+ import {Text} from '../../primitives/text'
21
+ import type {ComponentType, Props} from '../../types/props'
19
22
  import {DEFAULT_MENU_ELEMENT, Menu, type MenuProps} from './menu'
20
23
  import {useMenu} from './useMenu'
21
24
 
@@ -199,13 +202,14 @@ export function MenuGroup<E extends MenuGroupElementType = typeof DEFAULT_MENU_G
199
202
  {...rest}
200
203
  aria-pressed={as === 'button' ? withinMenu : undefined}
201
204
  as={as}
202
- data-pressed={as !== 'button' ? withinMenu : undefined}
203
- data-selected={!withinMenu && active ? '' : undefined}
205
+ // data-pressed={as !== 'button' ? withinMenu : undefined}
206
+ // data-selected={!withinMenu && active ? '' : undefined}
204
207
  onClick={handleClick}
205
208
  onKeyDown={handleKeyDown}
206
209
  onMouseEnter={handleMouseEnter}
207
210
  radius={radius}
208
211
  ref={setRootElement}
212
+ selected={withinMenu}
209
213
  tabIndex={-1}
210
214
  tone={tone}
211
215
  type={as === 'button' ? 'button' : undefined}
@@ -19,9 +19,11 @@ import {
19
19
  } from 'react'
20
20
  import {isValidElementType} from 'react-is'
21
21
 
22
- import {Box, Flex, Text} from '../../primitives'
23
22
  import {Selectable} from '../../primitives/_selectable'
24
- import type {ComponentType, Props} from '../../types'
23
+ import {Box} from '../../primitives/box'
24
+ import {Flex} from '../../primitives/flex'
25
+ import {Text} from '../../primitives/text'
26
+ import type {ComponentType, Props} from '../../types/props'
25
27
  import {Hotkeys} from '../hotkeys'
26
28
  import {useMenu} from './useMenu'
27
29
 
@@ -10,8 +10,8 @@ import {
10
10
  useRef,
11
11
  } from 'react'
12
12
 
13
- import {Button} from '../../primitives'
14
- import type {ComponentType, Props} from '../../types'
13
+ import {Button} from '../../primitives/button'
14
+ import type {ComponentType, Props} from '../../types/props'
15
15
 
16
16
  /** @public */
17
17
  export const DEFAULT_TAB_ELEMENT = 'button'
@@ -9,8 +9,8 @@ import {
9
9
  useState,
10
10
  } from 'react'
11
11
 
12
- import {Flex, type FlexOwnProps} from '../../primitives'
13
- import type {ComponentType, Props} from '../../types'
12
+ import {Flex, type FlexOwnProps} from '../../primitives/flex'
13
+ import type {ComponentType, Props} from '../../types/props'
14
14
  import type {TabProps} from './tab'
15
15
 
16
16
  /** @public */
@@ -1,5 +1,5 @@
1
- import {Box, type BoxOwnProps} from '../../primitives'
2
- import type {ComponentType, Props} from '../../types'
1
+ import {Box, type BoxOwnProps} from '../../primitives/box'
2
+ import type {ComponentType, Props} from '../../types/props'
3
3
 
4
4
  /** @public */
5
5
  export const DEFAULT_TAB_PANEL_ELEMENT = 'div'
@@ -1,34 +1,40 @@
1
1
  import {CloseIcon} from '@sanity/icons'
2
2
  import {type RadiusStyleProps, toast} from '@sanity/ui/css'
3
3
  import {motion, type Variant, type Variants} from 'framer-motion'
4
- import type {ReactNode} from 'react'
4
+ import {type ReactNode} from 'react'
5
5
 
6
6
  import {usePrefersReducedMotion} from '../../hooks/usePrefersReducedMotion'
7
- import {Box, Button, Card, Flex, Stack, Text} from '../../primitives'
8
- import type {ComponentType, Props} from '../../types'
9
-
10
- /** @public */
7
+ import {Box} from '../../primitives/box'
8
+ import {Button} from '../../primitives/button'
9
+ import {Card} from '../../primitives/card'
10
+ import {Flex} from '../../primitives/flex'
11
+ import {Stack} from '../../primitives/stack'
12
+ import {Text} from '../../primitives/text'
13
+ import type {ComponentType, Props} from '../../types/props'
14
+
15
+ /** @internal */
11
16
  export const DEFAULT_TOAST_ELEMENT = 'li'
12
17
 
13
- /** @public */
18
+ /** @internal */
14
19
  export type ToastOwnProps = RadiusStyleProps & {
15
20
  closable?: boolean
16
21
  description?: ReactNode
17
22
  onClose?: () => void
18
23
  title?: ReactNode
19
24
  status?: 'error' | 'warning' | 'success' | 'info'
20
- /** @deprecated */
21
25
  duration?: number
22
- /** @deprecated */
23
- updatedAt?: number
24
26
  }
25
27
 
26
- /** @public */
28
+ /** @internal */
27
29
  export type ToastElementType = 'li' | ComponentType
28
30
 
29
- /** @public */
31
+ /** @internal */
30
32
  export type ToastProps<E extends ToastElementType = ToastElementType> = Props<ToastOwnProps, E>
31
33
 
34
+ // Support pattern used by Sanity Studio, that works around the lack of `duration: Infinity` support in older @sanity/ui versions
35
+ // https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value
36
+ const LONG_ENOUGH_BUT_NOT_TOO_LONG = 1000 * 60 * 60 * 24 * 24
37
+
32
38
  const ROLES = {
33
39
  error: 'alert',
34
40
  warning: 'alert',
@@ -53,9 +59,9 @@ const BUTTON_TONE = {
53
59
  /**
54
60
  * The `Toast` component gives feedback to users when an action has taken place.
55
61
  *
56
- * Toasts can be closed with a close button, or auto-dismiss after a certain timeout.
62
+ * Toasts can be closed with a close button, or auto-dismiss when the duration expires.
57
63
  *
58
- * @public
64
+ * @internal
59
65
  */
60
66
  export function Toast<E extends ToastElementType = typeof DEFAULT_TOAST_ELEMENT>(
61
67
  props: ToastProps<E>,
@@ -64,14 +70,11 @@ export function Toast<E extends ToastElementType = typeof DEFAULT_TOAST_ELEMENT>
64
70
  as = DEFAULT_TOAST_ELEMENT,
65
71
  closable,
66
72
  description,
67
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
68
73
  duration,
69
74
  onClose,
70
75
  radius = 3,
71
76
  title,
72
77
  status,
73
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
74
- updatedAt,
75
78
  ...rest
76
79
  } = props as ToastProps<typeof DEFAULT_TOAST_ELEMENT>
77
80
 
@@ -84,7 +87,7 @@ export function Toast<E extends ToastElementType = typeof DEFAULT_TOAST_ELEMENT>
84
87
  const visualDuration: number = prefersReducedMotion ? 0 : 0.26
85
88
  const transition = visualDuration ? {type: 'spring', visualDuration, bounce: 0.25} : {duration: 0}
86
89
 
87
- // const hasDuration = duration && isFinite(duration) && duration < LONG_ENOUGH_BUT_NOT_TOO_LONG
90
+ const hasDuration = duration && isFinite(duration) && duration < LONG_ENOUGH_BUT_NOT_TOO_LONG
88
91
  const initial: ContainerVariants[] = ['hidden', 'initial']
89
92
  const animate: ContainerVariants[] = ['visible', 'slideIn']
90
93
  const exit: ContainerVariants[] = ['hidden', 'slideOut']
@@ -97,6 +100,7 @@ export function Toast<E extends ToastElementType = typeof DEFAULT_TOAST_ELEMENT>
97
100
  role={role}
98
101
  {...rest}
99
102
  custom={visualDuration}
103
+ data-has-duration={hasDuration ? '' : undefined}
100
104
  radius={radius}
101
105
  shadow={2}
102
106
  tone={cardTone}
@@ -1,7 +1,8 @@
1
1
  import {type GapStyleProps, type PaddingStyleProps, toastLayer} from '@sanity/ui/css'
2
2
 
3
- import {Grid, useLayer} from '../../primitives'
4
- import type {ComponentType, Props} from '../../types'
3
+ import {Grid} from '../../primitives/grid'
4
+ import {useLayer} from '../../primitives/layer'
5
+ import type {ComponentType, Props} from '../../types/props'
5
6
 
6
7
  /** @internal */
7
8
  export const DEFAULT_TOAST_LAYER_ELEMENT = 'ul'
@@ -3,7 +3,7 @@ import {AnimatePresence} from 'framer-motion'
3
3
  import {startTransition, useMemo, useState} from 'react'
4
4
 
5
5
  import {useMounted} from '../../hooks/useMounted'
6
- import {LayerProvider} from '../../primitives'
6
+ import {LayerProvider} from '../../primitives/layer'
7
7
  import {Toast} from './toast'
8
8
  import {ToastContext} from './toastContext'
9
9
  import {ToastLayer, type ToastLayerProps} from './toastLayer'
@@ -13,7 +13,6 @@ import type {ToastContextValue, ToastParams} from './types'
13
13
  type ToastState = {
14
14
  dismiss: () => void
15
15
  id: string
16
- updatedAt: number
17
16
  params: ToastParams
18
17
  }[]
19
18
 
@@ -31,8 +30,8 @@ export function ToastProvider(props: ToastProviderProps): React.JSX.Element {
31
30
 
32
31
  const value: ToastContextValue = useMemo(() => {
33
32
  const push = (params: ToastParams) => {
34
- const id = params.id || generateToastId()
35
- const duration = params.duration || 5000
33
+ const id = params.id ?? generateToastId()
34
+ const duration = params.duration ?? 5000
36
35
 
37
36
  startTransition(() => {
38
37
  setState((prevState): ToastState => {
@@ -51,10 +50,17 @@ export function ToastProvider(props: ToastProviderProps): React.JSX.Element {
51
50
  * This function will be passed to the Toast component
52
51
  * and called either on close button click or after duration.
53
52
  */
54
- const dismiss = () =>
55
- startTransition(() =>
56
- setState((currentState) => currentState.filter((toast) => toast.id !== id)),
57
- )
53
+ const dismiss = () => {
54
+ startTransition(() => {
55
+ if (timeoutId) {
56
+ clearTimeout(timeoutId)
57
+ }
58
+
59
+ setState((currentState) => currentState.filter((toast) => toast.id !== id))
60
+ })
61
+ }
62
+
63
+ const timeoutId = setTimeout(dismiss, duration)
58
64
 
59
65
  /**
60
66
  * Create updated state by:
@@ -67,7 +73,6 @@ export function ToastProvider(props: ToastProviderProps): React.JSX.Element {
67
73
  {
68
74
  dismiss,
69
75
  id,
70
- updatedAt: Date.now(),
71
76
  params: {...params, duration},
72
77
  },
73
78
  ]
@@ -87,7 +92,7 @@ export function ToastProvider(props: ToastProviderProps): React.JSX.Element {
87
92
  <LayerProvider zOffset={zOffset}>
88
93
  <ToastLayer padding={padding} paddingX={paddingX} paddingY={paddingY} gap={gap}>
89
94
  <AnimatePresence initial={false} mode="popLayout">
90
- {state.map(({dismiss, id, params, updatedAt}) => (
95
+ {state.map(({dismiss, id, params}) => (
91
96
  <Toast
92
97
  key={id}
93
98
  closable={params.closable}
@@ -96,7 +101,6 @@ export function ToastProvider(props: ToastProviderProps): React.JSX.Element {
96
101
  status={params.status}
97
102
  title={params.title}
98
103
  duration={params.duration}
99
- updatedAt={updatedAt}
100
104
  />
101
105
  ))}
102
106
  </AnimatePresence>
@@ -11,8 +11,8 @@ import {
11
11
  useState,
12
12
  } from 'react'
13
13
 
14
- import {Stack} from '../../primitives'
15
- import type {ComponentType, Props} from '../../types'
14
+ import {Stack} from '../../primitives/stack'
15
+ import type {ComponentType, Props} from '../../types/props'
16
16
  import {_findNextItemElement, _findPrevItemElement, _focusItemElement} from './helpers'
17
17
  import {TreeContext} from './treeContext'
18
18
  import type {TreeContextValue, TreeState} from './types'
@@ -1,7 +1,7 @@
1
1
  import {memo, type ReactElement} from 'react'
2
2
 
3
- import {Stack} from '../../primitives'
4
- import type {ComponentType, Props} from '../../types'
3
+ import {Stack} from '../../primitives/stack'
4
+ import type {ComponentType, Props} from '../../types/props'
5
5
  import {useTree} from './useTree'
6
6
 
7
7
  /** @public */
@@ -15,9 +15,12 @@ import {
15
15
  useRef,
16
16
  } from 'react'
17
17
 
18
- import {Box, type BoxProps, type CardOwnProps, Flex, Text} from '../../primitives'
19
18
  import {Selectable, type SelectableElementType} from '../../primitives/_selectable'
20
- import type {ComponentType, Props} from '../../types'
19
+ import {Box, type BoxProps} from '../../primitives/box'
20
+ import type {CardOwnProps} from '../../primitives/card'
21
+ import {Flex} from '../../primitives/flex'
22
+ import {Text} from '../../primitives/text'
23
+ import type {ComponentType, Props} from '../../types/props'
21
24
  import {TreeContext} from './treeContext'
22
25
  import {TreeGroup} from './treeGroup'
23
26
  import {useTree} from './useTree'
@@ -32,6 +35,7 @@ export type TreeItemOwnProps = CardOwnProps & {
32
35
  icon?: ElementType
33
36
  /**
34
37
  * Allows passing a custom element type to the link component
38
+ * @internal
35
39
  */
36
40
  linkAs?: SelectableElementType
37
41
  onClick?: MouseEventHandler<HTMLAnchorElement | HTMLLIElement>
@@ -86,9 +90,9 @@ export function TreeItem<E extends TreeItemElementType = typeof DEFAULT_TREE_ITE
86
90
  const itemPath = useMemo(() => path.concat([id || '']), [id, path])
87
91
  const itemKey = itemPath.join('/')
88
92
  const itemState = tree.state[itemKey]
89
- const focused = tree.focusedElement === rootRef.current
90
93
  const expanded = itemState?.expanded === undefined ? expandedProp : itemState?.expanded || false
91
- const tabIndex = tree.focusedElement && tree.focusedElement === rootRef.current ? 0 : -1
94
+ const focused = tree.focusedElement && tree.focusedElement === rootRef.current
95
+ const tabIndex = focused ? 0 : -1
92
96
  const contextValue = useMemo(
93
97
  () => ({...tree, level: tree.level + 1, path: itemPath}),
94
98
  [itemPath, tree],
@@ -174,12 +178,13 @@ export function TreeItem<E extends TreeItemElementType = typeof DEFAULT_TREE_ITE
174
178
  <Selectable
175
179
  aria-expanded={expanded}
176
180
  as={linkAs}
177
- data-pressed={selected ? '' : undefined}
181
+ // data-pressed={selected ? '' : undefined}
178
182
  data-ui="TreeItem__box"
179
183
  href={href}
180
184
  radius={radius}
181
185
  ref={treeitemRef}
182
186
  role="treeitem"
187
+ selected={selected}
183
188
  tabIndex={tabIndex}
184
189
  style={{
185
190
  paddingLeft: `calc(${vars.space[2]} * ${tree.level})`,
@@ -212,9 +217,11 @@ export function TreeItem<E extends TreeItemElementType = typeof DEFAULT_TREE_ITE
212
217
  >
213
218
  <Selectable
214
219
  as="button"
215
- data-pressed={selected ? '' : undefined}
220
+ // data-pressed={selected ? '' : undefined}
221
+ data-focused={focused ? '' : undefined}
216
222
  data-ui="TreeItem__box"
217
223
  radius={radius}
224
+ selected={selected}
218
225
  style={{
219
226
  paddingLeft: `calc(${vars.space[2]} * ${tree.level})`,
220
227
  }}
@@ -19,7 +19,6 @@ export interface TreeContextValue {
19
19
  registerItem: (element: HTMLElement, path: string, expanded: boolean, selected: boolean) => void
20
20
  setExpanded: (path: string, expanded: boolean) => void
21
21
  setFocusedElement: (focusedElement: HTMLElement | null) => void
22
- // space: number | number[]
23
22
  space: ResponsiveProp<Space>
24
23
  state: TreeState
25
24
  }
@@ -10,10 +10,10 @@ import {
10
10
  useState,
11
11
  } from 'react'
12
12
 
13
- import {_isScrollable} from '../../helpers'
14
- import {_ResizeObserver} from '../../observers'
15
- import {Box} from '../../primitives'
16
- import type {ComponentType, Props} from '../../types'
13
+ import {_isScrollable} from '../../helpers/scroll'
14
+ import {_ResizeObserver} from '../../observers/resize'
15
+ import {Box} from '../../primitives/box'
16
+ import type {ComponentType, Props} from '../../types/props'
17
17
 
18
18
  /** @beta */
19
19
  export const DEFAULT_VIRTUAL_LIST_ELEMENT = 'div'
@@ -139,6 +139,11 @@ export function VirtualList<E extends VirtualListElementType = typeof DEFAULT_VI
139
139
  })
140
140
  }, [fromIndex, gapValue, itemHeight, onChange, scrollHeight, scrollTop, toIndex])
141
141
 
142
+ useEffect(() => {
143
+ // console.log('renderItem', renderItem)
144
+ setItemHeight(-1)
145
+ }, [renderItem])
146
+
142
147
  const children = useMemo(() => {
143
148
  if (!renderItem || items.length === 0) return null
144
149
 
@@ -174,7 +179,7 @@ export function VirtualList<E extends VirtualListElementType = typeof DEFAULT_VI
174
179
  insetRight={0}
175
180
  key={key}
176
181
  position="absolute"
177
- style={{top: itemIndex * (itemHeight + gapValue) - gapValue}}
182
+ style={{top: itemIndex * (itemHeight + gapValue)}}
178
183
  >
179
184
  {node}
180
185
  </Box>
@@ -7,10 +7,6 @@ import {
7
7
  isHTMLTextAreaElement,
8
8
  } from './element'
9
9
 
10
- // export const globalFocusState = {
11
- // IgnoreUtilFocusChanges: false,
12
- // }
13
-
14
10
  /**
15
11
  * @internal
16
12
  */
@@ -56,16 +52,12 @@ export function attemptFocus(element: HTMLElement): boolean {
56
52
  return false
57
53
  }
58
54
 
59
- // globalFocusState.IgnoreUtilFocusChanges = true
60
-
61
55
  try {
62
56
  element.focus()
63
57
  } catch {
64
58
  // ignore
65
59
  }
66
60
 
67
- // globalFocusState.IgnoreUtilFocusChanges = false
68
-
69
61
  return document.activeElement === element
70
62
  }
71
63
 
@@ -1,6 +1,6 @@
1
1
  import {useState} from 'react'
2
2
 
3
- import {_getArrayProp} from '../helpers'
3
+ import {_getArrayProp} from '../helpers/props'
4
4
 
5
5
  /**
6
6
  * This API might change. DO NOT USE IN PRODUCTION.
@@ -1,8 +1,6 @@
1
- import {Box, Card, Code, Container, Stack, Text, useElementRect} from '@sanity/ui'
1
+ import {Box, Card, Code, Container, Grid, Stack, Text, useElementRect} from '@sanity/ui'
2
2
  import {useState} from 'react'
3
3
 
4
- import {Grid} from '../../../primitives'
5
-
6
4
  export default function ExampleStory() {
7
5
  const [element, setElement] = useState<HTMLElement | null>(null)
8
6
  const rect = useElementRect(element)
@@ -1,6 +1,6 @@
1
1
  import {useEffect, useState} from 'react'
2
2
 
3
- import {_elementSizeObserver, type ElementSize} from '../observers/elementSizeObserver'
3
+ import {_elementSizeObserver, type ElementSize} from '../observers/elementSize'
4
4
 
5
5
  /**
6
6
  * Subscribe to the size of a DOM element.
@@ -1,7 +1,7 @@
1
1
  import type {Breakpoint, ResponsiveProp} from '@sanity/ui/css'
2
2
  import {useState} from 'react'
3
3
 
4
- import {_getResponsiveProp} from '../helpers'
4
+ import {_getResponsiveProp} from '../helpers/props'
5
5
 
6
6
  /**
7
7
  * This API might change. DO NOT USE IN PRODUCTION.
package/src/core/index.ts CHANGED
@@ -1,8 +1,85 @@
1
1
  export * from './_compat'
2
- export * from './components'
3
- export * from './helpers'
4
- export * from './hooks'
5
- export * from './observers'
6
- export * from './primitives'
7
- export * from './types'
8
- export * from './utils'
2
+
3
+ // components
4
+ export * from './components/autocomplete/autocomplete'
5
+ export * from './components/autocomplete/types'
6
+ export * from './components/breadcrumbs'
7
+ export * from './components/dialog'
8
+ export * from './components/hotkeys'
9
+ export * from './components/menu'
10
+ export * from './components/tab'
11
+ export * from './components/toast'
12
+ export * from './components/tree'
13
+ export * from './components/virtualList'
14
+
15
+ // helpers
16
+ export * from './helpers/animation'
17
+ export * from './helpers/element'
18
+ export * from './helpers/focus'
19
+ export * from './helpers/props'
20
+ export * from './helpers/scroll'
21
+
22
+ // hooks
23
+ export * from './hooks/useArrayProp'
24
+ export * from './hooks/useClickOutside'
25
+ export * from './hooks/useClickOutsideEvent'
26
+ export * from './hooks/useCustomValidity'
27
+ export * from './hooks/useElementRect'
28
+ export * from './hooks/useElementSize'
29
+ export * from './hooks/useForwardedRef'
30
+ export * from './hooks/useGlobalKeyDown'
31
+ export * from './hooks/useMatchMedia'
32
+ export * from './hooks/useMediaIndex'
33
+ export * from './hooks/usePrefersDark'
34
+ export * from './hooks/usePrefersReducedMotion'
35
+ export * from './hooks/useResponsiveProp'
36
+
37
+ // observers
38
+ export * from './observers/elementSize'
39
+ export * from './observers/resize'
40
+
41
+ // primitives
42
+ export * from './primitives/_selectable'
43
+ export * from './primitives/arrow'
44
+ export * from './primitives/avatar'
45
+ export * from './primitives/badge'
46
+ export * from './primitives/box'
47
+ export * from './primitives/button'
48
+ export * from './primitives/card'
49
+ export * from './primitives/checkbox'
50
+ export * from './primitives/code'
51
+ export * from './primitives/container'
52
+ export * from './primitives/flex'
53
+ export * from './primitives/grid'
54
+ export * from './primitives/heading'
55
+ export * from './primitives/inline'
56
+ export * from './primitives/kbd'
57
+ export * from './primitives/label'
58
+ export * from './primitives/layer'
59
+ export * from './primitives/popover'
60
+ export * from './primitives/radio'
61
+ export * from './primitives/root'
62
+ export * from './primitives/select'
63
+ export * from './primitives/skeleton'
64
+ export * from './primitives/spinner'
65
+ export * from './primitives/srOnly'
66
+ export * from './primitives/stack'
67
+ export * from './primitives/switch'
68
+ export * from './primitives/text'
69
+ export * from './primitives/textArea'
70
+ export * from './primitives/textInput'
71
+ export * from './primitives/tooltip'
72
+ export * from './primitives/types'
73
+
74
+ // utils
75
+ export * from './utils/boundaryElement'
76
+ export * from './utils/elementQuery'
77
+ export * from './utils/errorBoundary'
78
+ export * from './utils/portal'
79
+
80
+ // types
81
+ export * from './types/gridItem'
82
+ export * from './types/placement'
83
+ export * from './types/props'
84
+ export * from './types/radius'
85
+ export * from './types/textAlign'
@@ -1,4 +1,4 @@
1
- import {_ResizeObserver} from './resizeObserver'
1
+ import {_ResizeObserver} from './resize'
2
2
 
3
3
  /**
4
4
  * @beta
@@ -1 +1,2 @@
1
1
  export * from './selectable'
2
+ export * from './types'
@@ -1,6 +1,7 @@
1
1
  import {_selectable, type SelectableStyleProps} from '@sanity/ui/css'
2
+ import type {ThemeColorStateToneKey} from '@sanity/ui/theme'
2
3
 
3
- import type {ComponentType, Props, SelectableTone} from '../../types'
4
+ import type {ComponentType, Props} from '../../types/props'
4
5
  import {Box, type BoxOwnProps} from '../box'
5
6
 
6
7
  /** @internal */
@@ -11,7 +12,8 @@ export type SelectableOwnProps = BoxOwnProps &
11
12
  SelectableStyleProps & {
12
13
  disabled?: boolean
13
14
  href?: string
14
- tone?: SelectableTone
15
+ selected?: boolean
16
+ tone?: ThemeColorStateToneKey
15
17
  type?: 'button'
16
18
  }
17
19
 
@@ -32,9 +34,17 @@ export function Selectable<E extends SelectableElementType = typeof DEFAULT_SELE
32
34
  as = DEFAULT_SELECTABLE_ELEMENT,
33
35
  className,
34
36
  radius,
37
+ selected,
35
38
  tone,
36
39
  ...rest
37
40
  } = props as SelectableProps<typeof DEFAULT_SELECTABLE_ELEMENT>
38
41
 
39
- return <Box {...rest} as={as} className={_selectable({className, radius, tone})} />
42
+ return (
43
+ <Box
44
+ {...rest}
45
+ as={as}
46
+ className={_selectable({className, radius, tone})}
47
+ data-selected={selected ? '' : undefined}
48
+ />
49
+ )
40
50
  }
@@ -1,7 +1,7 @@
1
1
  import type {ThemeColorStateToneKey} from '@sanity/ui/theme'
2
2
 
3
3
  /**
4
- * @public
4
+ * @internal
5
5
  * @deprecated Use `ThemeColorStateToneKey` instead
6
6
  */
7
7
  export type SelectableTone = ThemeColorStateToneKey
@@ -2,7 +2,7 @@ import {_arrow, _arrowShape, _arrowStroke, _arrowStrokeMask, _arrowSvg, vars} fr
2
2
  import {assignInlineVars} from '@vanilla-extract/dynamic'
3
3
  import {useMemo} from 'react'
4
4
 
5
- import type {ComponentType, Props} from '../../types'
5
+ import type {ComponentType, Props} from '../../types/props'
6
6
  import {compileCommands, getRoundedCommands, type Point} from './cmds'
7
7
 
8
8
  /** @internal */