@sanity/ui 0.37.10 → 0.37.13

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 (242) hide show
  1. package/lib/dts/src/components/autocomplete/autocomplete.d.ts +2 -2
  2. package/lib/dts/src/components/autocomplete/autocomplete.d.ts.map +1 -1
  3. package/lib/dts/src/components/autocomplete/autocomplete.styles.d.ts.map +1 -1
  4. package/lib/dts/src/components/autocomplete/constants.d.ts +0 -4
  5. package/lib/dts/src/components/autocomplete/constants.d.ts.map +1 -1
  6. package/lib/dts/src/components/breadcrumbs/breadcrumbs.d.ts.map +1 -1
  7. package/lib/dts/src/components/dialog/dialog.d.ts.map +1 -1
  8. package/lib/dts/src/components/dialog/styles.d.ts +1 -1
  9. package/lib/dts/src/components/dialog/styles.d.ts.map +1 -1
  10. package/lib/dts/src/components/hotkeys/hotkeys.d.ts.map +1 -1
  11. package/lib/dts/src/components/menu/menuButton.d.ts.map +1 -1
  12. package/lib/dts/src/components/menu/menuGroup.d.ts.map +1 -1
  13. package/lib/dts/src/components/menu/menuItem.d.ts.map +1 -1
  14. package/lib/dts/src/components/skeleton/skeleton.d.ts.map +1 -1
  15. package/lib/dts/src/hooks/_internal/useUnique.d.ts +2 -3
  16. package/lib/dts/src/hooks/_internal/useUnique.d.ts.map +1 -1
  17. package/lib/dts/src/hooks/index.d.ts +2 -1
  18. package/lib/dts/src/hooks/index.d.ts.map +1 -1
  19. package/lib/dts/src/hooks/useArrayProp.d.ts +7 -0
  20. package/lib/dts/src/hooks/useArrayProp.d.ts.map +1 -0
  21. package/lib/dts/src/hooks/useElementRect/useElementRect.d.ts +1 -1
  22. package/lib/dts/src/hooks/useElementRect/useElementRect.d.ts.map +1 -1
  23. package/lib/dts/src/hooks/useElementSize.d.ts +7 -0
  24. package/lib/dts/src/hooks/useElementSize.d.ts.map +1 -0
  25. package/lib/dts/src/index.d.ts +1 -0
  26. package/lib/dts/src/index.d.ts.map +1 -1
  27. package/lib/dts/src/observers/elementSizeObserver.d.ts +37 -0
  28. package/lib/dts/src/observers/elementSizeObserver.d.ts.map +1 -0
  29. package/lib/dts/src/observers/index.d.ts +3 -0
  30. package/lib/dts/src/observers/index.d.ts.map +1 -0
  31. package/lib/dts/src/observers/resizeObserver.d.ts +5 -0
  32. package/lib/dts/src/observers/resizeObserver.d.ts.map +1 -0
  33. package/lib/dts/src/primitives/_selectable/selectable.d.ts +1 -2
  34. package/lib/dts/src/primitives/_selectable/selectable.d.ts.map +1 -1
  35. package/lib/dts/src/primitives/avatar/avatar.d.ts.map +1 -1
  36. package/lib/dts/src/primitives/avatar/avatarCounter.d.ts +1 -0
  37. package/lib/dts/src/primitives/avatar/avatarCounter.d.ts.map +1 -1
  38. package/lib/dts/src/primitives/avatar/avatarStack.d.ts +1 -0
  39. package/lib/dts/src/primitives/avatar/avatarStack.d.ts.map +1 -1
  40. package/lib/dts/src/primitives/avatar/styles.d.ts.map +1 -1
  41. package/lib/dts/src/primitives/badge/badge.d.ts.map +1 -1
  42. package/lib/dts/src/primitives/box/box.d.ts.map +1 -1
  43. package/lib/dts/src/primitives/button/button.d.ts.map +1 -1
  44. package/lib/dts/src/primitives/card/card.d.ts.map +1 -1
  45. package/lib/dts/src/primitives/code/code.d.ts.map +1 -1
  46. package/lib/dts/src/primitives/container/container.d.ts.map +1 -1
  47. package/lib/dts/src/primitives/container/styles.d.ts.map +1 -1
  48. package/lib/dts/src/primitives/container/types.d.ts +1 -1
  49. package/lib/dts/src/primitives/container/types.d.ts.map +1 -1
  50. package/lib/dts/src/primitives/flex/flex.d.ts.map +1 -1
  51. package/lib/dts/src/primitives/grid/grid.d.ts.map +1 -1
  52. package/lib/dts/src/primitives/heading/heading.d.ts.map +1 -1
  53. package/lib/dts/src/primitives/inline/inline.d.ts.map +1 -1
  54. package/lib/dts/src/primitives/inline/styles.d.ts.map +1 -1
  55. package/lib/dts/src/primitives/inline/types.d.ts +1 -1
  56. package/lib/dts/src/primitives/inline/types.d.ts.map +1 -1
  57. package/lib/dts/src/primitives/kbd/kbd.d.ts.map +1 -1
  58. package/lib/dts/src/primitives/label/label.d.ts.map +1 -1
  59. package/lib/dts/src/primitives/popover/popover.d.ts.map +1 -1
  60. package/lib/dts/src/primitives/select/styles.d.ts +5 -1
  61. package/lib/dts/src/primitives/select/styles.d.ts.map +1 -1
  62. package/lib/dts/src/primitives/stack/stack.d.ts.map +1 -1
  63. package/lib/dts/src/primitives/stack/styles.d.ts +1 -1
  64. package/lib/dts/src/primitives/stack/styles.d.ts.map +1 -1
  65. package/lib/dts/src/primitives/text/text.d.ts.map +1 -1
  66. package/lib/dts/src/primitives/textArea/textArea.d.ts.map +1 -1
  67. package/lib/dts/src/primitives/textInput/textInput.d.ts.map +1 -1
  68. package/lib/dts/src/primitives/tooltip/tooltip.d.ts.map +1 -1
  69. package/lib/dts/src/primitives/types.d.ts +1 -1
  70. package/lib/dts/src/primitives/types.d.ts.map +1 -1
  71. package/lib/dts/src/styles/border/types.d.ts +5 -5
  72. package/lib/dts/src/styles/border/types.d.ts.map +1 -1
  73. package/lib/dts/src/styles/box/types.d.ts +4 -4
  74. package/lib/dts/src/styles/box/types.d.ts.map +1 -1
  75. package/lib/dts/src/styles/flex/flexItemStyle.d.ts.map +1 -1
  76. package/lib/dts/src/styles/flex/types.d.ts +6 -6
  77. package/lib/dts/src/styles/flex/types.d.ts.map +1 -1
  78. package/lib/dts/src/styles/font/responsiveFont.d.ts +1 -1
  79. package/lib/dts/src/styles/font/responsiveFont.d.ts.map +1 -1
  80. package/lib/dts/src/styles/font/types.d.ts +3 -3
  81. package/lib/dts/src/styles/font/types.d.ts.map +1 -1
  82. package/lib/dts/src/styles/grid/types.d.ts +14 -14
  83. package/lib/dts/src/styles/grid/types.d.ts.map +1 -1
  84. package/lib/dts/src/styles/helpers.d.ts +4 -4
  85. package/lib/dts/src/styles/helpers.d.ts.map +1 -1
  86. package/lib/dts/src/styles/input/responsiveInputPaddingStyle.d.ts +12 -12
  87. package/lib/dts/src/styles/input/responsiveInputPaddingStyle.d.ts.map +1 -1
  88. package/lib/dts/src/styles/input/textInputStyle.d.ts +4 -1
  89. package/lib/dts/src/styles/input/textInputStyle.d.ts.map +1 -1
  90. package/lib/dts/src/styles/margin/types.d.ts +7 -7
  91. package/lib/dts/src/styles/margin/types.d.ts.map +1 -1
  92. package/lib/dts/src/styles/padding/types.d.ts +7 -7
  93. package/lib/dts/src/styles/padding/types.d.ts.map +1 -1
  94. package/lib/dts/src/styles/radius/types.d.ts +1 -1
  95. package/lib/dts/src/styles/radius/types.d.ts.map +1 -1
  96. package/lib/dts/src/styles/shadow/shadowStyle.d.ts.map +1 -1
  97. package/lib/dts/src/styles/shadow/types.d.ts +1 -1
  98. package/lib/dts/src/styles/shadow/types.d.ts.map +1 -1
  99. package/lib/dts/src/theme/lib/theme/fonts.d.ts +1 -3
  100. package/lib/dts/src/theme/lib/theme/fonts.d.ts.map +1 -1
  101. package/lib/dts/src/theme/studioTheme/fonts.d.ts.map +1 -1
  102. package/lib/dts/src/types/index.d.ts +2 -1
  103. package/lib/dts/src/types/index.d.ts.map +1 -1
  104. package/lib/dts/src/types/placement.d.ts +7 -0
  105. package/lib/dts/src/types/placement.d.ts.map +1 -0
  106. package/lib/dts/src/types/text.d.ts +5 -0
  107. package/lib/dts/src/types/text.d.ts.map +1 -0
  108. package/lib/dts/src/utils/elementQuery/elementQuery.d.ts.map +1 -1
  109. package/lib/dts/src/utils/index.d.ts +0 -1
  110. package/lib/dts/src/utils/index.d.ts.map +1 -1
  111. package/lib/dts/src/utils/virtualList/virtualList.d.ts.map +1 -1
  112. package/lib/sanity-ui.js +738 -627
  113. package/lib/sanity-ui.js.map +1 -1
  114. package/lib/{sanity-ui.modern.js → sanity-ui.modern.mjs} +736 -616
  115. package/lib/sanity-ui.modern.mjs.map +1 -0
  116. package/lib/sanity-ui.module.js +732 -623
  117. package/lib/sanity-ui.module.js.map +1 -1
  118. package/package.json +11 -11
  119. package/src/__workshop__/color/overview.tsx +9 -11
  120. package/src/components/autocomplete/__workshop__/async.tsx +14 -12
  121. package/src/components/autocomplete/__workshop__/constrainedHeight.tsx +36 -0
  122. package/src/components/autocomplete/autocomplete.styles.tsx +0 -1
  123. package/src/components/autocomplete/autocomplete.tsx +14 -7
  124. package/src/components/autocomplete/constants.ts +0 -5
  125. package/src/components/breadcrumbs/breadcrumbs.tsx +3 -2
  126. package/src/components/dialog/dialog.tsx +17 -9
  127. package/src/components/dialog/styles.ts +3 -3
  128. package/src/components/hotkeys/hotkeys.tsx +3 -1
  129. package/src/components/menu/__workshop__/constrainedInBoundary.tsx +11 -14
  130. package/src/components/menu/__workshop__/groups.tsx +1 -1
  131. package/src/components/menu/menuButton.tsx +21 -13
  132. package/src/components/menu/menuGroup.tsx +3 -2
  133. package/src/components/menu/menuItem.tsx +4 -5
  134. package/src/components/skeleton/skeleton.tsx +10 -1
  135. package/src/components/skeleton/textSkeleton.tsx +7 -7
  136. package/src/hooks/_internal/useUnique.ts +4 -5
  137. package/src/hooks/index.ts +2 -1
  138. package/src/hooks/useArrayProp.ts +23 -0
  139. package/src/hooks/useElementRect/useElementRect.ts +4 -16
  140. package/src/hooks/useElementSize.ts +18 -0
  141. package/src/index.ts +1 -0
  142. package/src/observers/elementSizeObserver.ts +116 -0
  143. package/src/observers/index.ts +2 -0
  144. package/src/{utils → observers}/resizeObserver.ts +1 -4
  145. package/src/primitives/_selectable/selectable.tsx +5 -4
  146. package/src/primitives/avatar/avatar.tsx +7 -5
  147. package/src/primitives/avatar/avatarCounter.tsx +14 -12
  148. package/src/primitives/avatar/avatarStack.tsx +19 -13
  149. package/src/primitives/avatar/styles.ts +2 -2
  150. package/src/primitives/badge/badge.tsx +3 -2
  151. package/src/primitives/box/box.tsx +27 -26
  152. package/src/primitives/button/button.tsx +22 -10
  153. package/src/primitives/card/card.tsx +13 -11
  154. package/src/primitives/checkbox/__workshop__/example.tsx +4 -2
  155. package/src/primitives/checkbox/__workshop__/props.tsx +4 -2
  156. package/src/primitives/checkbox/__workshop__/readOnly.tsx +4 -2
  157. package/src/primitives/code/__workshop__/props.tsx +1 -1
  158. package/src/primitives/code/code.tsx +2 -1
  159. package/src/primitives/container/container.tsx +10 -1
  160. package/src/primitives/container/styles.ts +2 -2
  161. package/src/primitives/container/types.ts +1 -1
  162. package/src/primitives/flex/flex.tsx +6 -5
  163. package/src/primitives/grid/__workshop__/responsive.tsx +13 -12
  164. package/src/primitives/grid/grid.tsx +9 -8
  165. package/src/primitives/heading/__workshop__/opticalAlignment.tsx +19 -7
  166. package/src/primitives/heading/heading.tsx +3 -2
  167. package/src/primitives/inline/inline.tsx +12 -6
  168. package/src/primitives/inline/styles.ts +2 -2
  169. package/src/primitives/inline/types.ts +1 -1
  170. package/src/primitives/kbd/kbd.tsx +2 -1
  171. package/src/primitives/label/label.tsx +4 -3
  172. package/src/primitives/popover/__workshop__/{margins.tsx → MarginsStory.tsx} +1 -1
  173. package/src/primitives/popover/__workshop__/{matchReferenceWidth.tsx → MatchReferenceWidthStory.tsx} +0 -0
  174. package/src/primitives/popover/__workshop__/{plain.tsx → PlainStory.tsx} +12 -14
  175. package/src/primitives/popover/__workshop__/{recursive.tsx → RecursiveStory.tsx} +4 -1
  176. package/src/primitives/popover/__workshop__/RightAlignedStory.tsx +60 -0
  177. package/src/primitives/popover/__workshop__/TestStory.tsx +79 -0
  178. package/src/primitives/popover/__workshop__/index.ts +10 -5
  179. package/src/primitives/popover/popover.tsx +5 -3
  180. package/src/primitives/select/select.tsx +9 -9
  181. package/src/primitives/select/styles.ts +10 -4
  182. package/src/primitives/stack/stack.tsx +2 -1
  183. package/src/primitives/stack/styles.ts +3 -3
  184. package/src/primitives/text/__workshop__/opticalAlignment.tsx +15 -5
  185. package/src/primitives/text/text.tsx +3 -2
  186. package/src/primitives/textArea/__workshop__/plain.tsx +23 -18
  187. package/src/primitives/textArea/textArea.tsx +17 -5
  188. package/src/primitives/textInput/__workshop__/clearButton.tsx +14 -8
  189. package/src/primitives/textInput/__workshop__/index.ts +2 -2
  190. package/src/primitives/textInput/__workshop__/plain.tsx +39 -32
  191. package/src/primitives/textInput/__workshop__/tones.tsx +97 -75
  192. package/src/primitives/textInput/__workshop__/typed.tsx +8 -2
  193. package/src/primitives/textInput/textInput.tsx +43 -12
  194. package/src/primitives/tooltip/__workshop__/props.tsx +5 -1
  195. package/src/primitives/tooltip/tooltip.tsx +3 -2
  196. package/src/primitives/types.ts +1 -1
  197. package/src/styles/border/borderStyle.ts +6 -6
  198. package/src/styles/border/types.ts +5 -5
  199. package/src/styles/box/boxStyle.ts +5 -5
  200. package/src/styles/box/types.ts +4 -4
  201. package/src/styles/flex/flexItemStyle.ts +5 -4
  202. package/src/styles/flex/flexStyle.ts +6 -6
  203. package/src/styles/flex/types.ts +6 -6
  204. package/src/styles/font/responsiveFont.ts +7 -27
  205. package/src/styles/font/textAlignStyle.ts +2 -2
  206. package/src/styles/font/types.ts +4 -3
  207. package/src/styles/grid/gridItemStyle.ts +7 -7
  208. package/src/styles/grid/gridStyle.ts +9 -9
  209. package/src/styles/grid/types.ts +14 -14
  210. package/src/styles/helpers.ts +9 -9
  211. package/src/styles/input/responsiveInputPaddingStyle.ts +24 -27
  212. package/src/styles/input/textInputStyle.ts +89 -79
  213. package/src/styles/margin/marginStyle.ts +8 -8
  214. package/src/styles/margin/marginsStyle.test.ts +1 -1
  215. package/src/styles/margin/types.ts +7 -7
  216. package/src/styles/padding/paddingStyle.test.ts +1 -1
  217. package/src/styles/padding/paddingStyle.ts +8 -8
  218. package/src/styles/padding/types.ts +7 -7
  219. package/src/styles/radius/radiusStyle.ts +2 -2
  220. package/src/styles/radius/types.ts +1 -1
  221. package/src/styles/shadow/shadowStyle.ts +2 -5
  222. package/src/styles/shadow/types.ts +1 -1
  223. package/src/theme/lib/theme/fonts.ts +1 -3
  224. package/src/theme/studioTheme/fonts.ts +5 -9
  225. package/src/types/index.ts +2 -2
  226. package/src/types/placement.ts +18 -0
  227. package/src/types/text.ts +4 -0
  228. package/src/utils/elementQuery/elementQuery.tsx +5 -18
  229. package/src/utils/index.ts +0 -1
  230. package/src/utils/layer/layer.tsx +1 -1
  231. package/src/utils/layer/layerProvider.tsx +2 -2
  232. package/src/utils/virtualList/virtualList.tsx +8 -7
  233. package/lib/dts/src/hooks/useResponsiveProp.d.ts +0 -6
  234. package/lib/dts/src/hooks/useResponsiveProp.d.ts.map +0 -1
  235. package/lib/dts/src/types/common.d.ts +0 -11
  236. package/lib/dts/src/types/common.d.ts.map +0 -1
  237. package/lib/dts/src/utils/resizeObserver.d.ts +0 -6
  238. package/lib/dts/src/utils/resizeObserver.d.ts.map +0 -1
  239. package/lib/sanity-ui.modern.js.map +0 -1
  240. package/src/hooks/useResponsiveProp.ts +0 -10
  241. package/src/primitives/popover/__workshop__/rightAligned.tsx +0 -57
  242. package/src/types/common.ts +0 -12
@@ -0,0 +1,60 @@
1
+ import {EllipsisVerticalIcon} from '@sanity/icons'
2
+ import {Button, Card, Flex, Popover, Text, useClickOutside} from '@sanity/ui'
3
+ import {useBoolean} from '@sanity/ui-workshop'
4
+ import React, {useCallback, useState} from 'react'
5
+
6
+ export default function RightAlignedStory() {
7
+ const constrainSize = useBoolean('Constrain size', false)
8
+
9
+ const [open, setOpen] = useState(false)
10
+ const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
11
+ const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
12
+ const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
13
+
14
+ const content = (
15
+ <Text>
16
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque at nisl at sem tempor
17
+ hendrerit scelerisque ut libero. Maecenas iaculis efficitur lorem, ac faucibus mi imperdiet
18
+ quis. Cras a consectetur erat. Fusce imperdiet, dolor et pellentesque iaculis, ex quam luctus
19
+ felis, non ultrices enim sem vitae quam. Duis lorem velit, lacinia at rhoncus a, tempus vel
20
+ neque. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae;
21
+ Sed id mauris quam. Nam finibus sapien non lacinia ultricies. Integer fermentum tortor at
22
+ pellentesque faucibus. In venenatis commodo placerat. Curabitur commodo tortor libero, vel
23
+ pellentesque elit luctus sodales. Donec mattis tristique nunc ac lacinia. Vestibulum non
24
+ pulvinar turpis, posuere consequat arcu. Fusce ut urna blandit, finibus nisi a, molestie elit.
25
+ Nulla sed eleifend mi.
26
+ </Text>
27
+ )
28
+
29
+ const handleToggleOpen = useCallback(() => setOpen((v) => !v), [])
30
+ const handleClose = useCallback(() => setOpen(false), [])
31
+
32
+ useClickOutside(handleClose, [buttonElement, popoverElement])
33
+
34
+ return (
35
+ <Card height="fill" padding={[4, 5, 6]} sizing="border" tone="transparent">
36
+ <Card height="fill" padding={2} ref={setBoundaryElement} shadow={1}>
37
+ <Flex justify="flex-end" padding={0}>
38
+ <Popover
39
+ boundaryElement={boundaryElement}
40
+ constrainSize={constrainSize}
41
+ content={content}
42
+ open={open}
43
+ padding={3}
44
+ portal
45
+ placement="bottom"
46
+ ref={setPopoverElement}
47
+ >
48
+ <Button
49
+ icon={EllipsisVerticalIcon}
50
+ mode="bleed"
51
+ onClick={handleToggleOpen}
52
+ ref={setButtonElement}
53
+ selected={open}
54
+ />
55
+ </Popover>
56
+ </Flex>
57
+ </Card>
58
+ </Card>
59
+ )
60
+ }
@@ -0,0 +1,79 @@
1
+ import {useBoolean, useSelect, useText} from '@sanity/ui-workshop'
2
+ import React, {ReactElement, useState} from 'react'
3
+ import {
4
+ WORKSHOP_CONTAINER_WIDTH_OPTIONS,
5
+ WORKSHOP_PLACEMENT_OPTIONS,
6
+ WORKSHOP_RADIUS_OPTIONS,
7
+ } from '../../../__workshop__/constants'
8
+ import {BoundaryElementProvider, PortalProvider} from '../../../utils'
9
+ import {Button} from '../../button'
10
+ import {Card} from '../../card'
11
+ import {Text} from '../../text'
12
+ import {Popover} from '../popover'
13
+
14
+ export default function TestStory(): ReactElement {
15
+ const [portalElement, setPortalElement] = useState<HTMLDivElement | null>(null)
16
+ const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
17
+ const arrow = useBoolean('Arrow', true)
18
+ const matchReferenceWidth = useBoolean('Match reference width', false)
19
+ const open = useBoolean('Open', true)
20
+ const placement = useSelect('Placement', WORKSHOP_PLACEMENT_OPTIONS, 'bottom')
21
+ const preventOverflow = useBoolean('Prevent overflow', true)
22
+ const radius = useSelect('Radius', WORKSHOP_RADIUS_OPTIONS, 2)
23
+ const referenceWide = useBoolean('Reference wide?', false)
24
+ const width = useSelect('Width', WORKSHOP_CONTAINER_WIDTH_OPTIONS, 'auto')
25
+
26
+ const text = useText('Text', 'Test')
27
+
28
+ return (
29
+ <Card
30
+ ref={setBoundaryElement}
31
+ shadow={2}
32
+ style={{
33
+ position: 'absolute',
34
+ top: 50,
35
+ right: 50,
36
+ bottom: 50,
37
+ left: 50,
38
+ }}
39
+ >
40
+ <div
41
+ data-portal=""
42
+ ref={setPortalElement}
43
+ style={{
44
+ position: 'absolute',
45
+ top: 0,
46
+ right: 0,
47
+ bottom: 0,
48
+ left: 0,
49
+ overflow: 'hidden',
50
+ pointerEvents: 'none',
51
+ }}
52
+ />
53
+
54
+ <div style={{width: '100%', height: '100%', overflow: 'auto'}}>
55
+ <div style={{padding: '150vh'}}>
56
+ <PortalProvider element={portalElement}>
57
+ <BoundaryElementProvider element={boundaryElement}>
58
+ <Popover
59
+ arrow={arrow}
60
+ content={<Text size={1}>{text}</Text>}
61
+ fallbackPlacements={['left', 'bottom', 'right', 'top']}
62
+ matchReferenceWidth={matchReferenceWidth}
63
+ open={open}
64
+ padding={3}
65
+ placement={placement}
66
+ portal
67
+ preventOverflow={preventOverflow}
68
+ radius={radius}
69
+ width={width}
70
+ >
71
+ <Button text="reference" style={{width: referenceWide ? 300 : undefined}} />
72
+ </Popover>
73
+ </BoundaryElementProvider>
74
+ </PortalProvider>
75
+ </div>
76
+ </div>
77
+ </Card>
78
+ )
79
+ }
@@ -2,29 +2,34 @@ import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
4
  export default defineScope('primitives/popover', 'Popover', [
5
+ {
6
+ name: 'test',
7
+ title: 'Test',
8
+ component: lazy(() => import('./TestStory')),
9
+ },
5
10
  {
6
11
  name: 'plain',
7
12
  title: 'Plain',
8
- component: lazy(() => import('./plain')),
13
+ component: lazy(() => import('./PlainStory')),
9
14
  },
10
15
  {
11
16
  name: 'recursive',
12
17
  title: 'Recursive',
13
- component: lazy(() => import('./recursive')),
18
+ component: lazy(() => import('./RecursiveStory')),
14
19
  },
15
20
  {
16
21
  name: 'match-ref-width',
17
22
  title: 'Match reference width',
18
- component: lazy(() => import('./matchReferenceWidth')),
23
+ component: lazy(() => import('./MatchReferenceWidthStory')),
19
24
  },
20
25
  {
21
26
  name: 'margins',
22
27
  title: 'Margins',
23
- component: lazy(() => import('./margins')),
28
+ component: lazy(() => import('./MarginsStory')),
24
29
  },
25
30
  {
26
31
  name: 'right-aligned',
27
32
  title: 'Right-aligned',
28
- component: lazy(() => import('./rightAligned')),
33
+ component: lazy(() => import('./RightAlignedStory')),
29
34
  },
30
35
  ])
@@ -2,7 +2,7 @@ import React, {cloneElement, forwardRef, useCallback, useEffect, useMemo, useSta
2
2
  import {usePopper} from 'react-popper'
3
3
  import styled, {css} from 'styled-components'
4
4
  import {EMPTY_RECORD} from '../../constants'
5
- import {useForwardedRef} from '../../hooks'
5
+ import {useArrayProp, useForwardedRef} from '../../hooks'
6
6
  import {ThemeColorSchemeKey, useTheme} from '../../theme'
7
7
  import {CardTone, Placement, PopoverMargins} from '../../types'
8
8
  import {Layer, LayerProps, Portal, useBoundaryElement, usePortal} from '../../utils'
@@ -71,6 +71,7 @@ const PopoverCard = styled(Card)<
71
71
  ResponsiveWidthStyleProps & {
72
72
  $constrainSize?: boolean
73
73
  $preventOverflow?: boolean
74
+ $width: (number | 'auto')[]
74
75
  }
75
76
  >(
76
77
  ({$constrainSize}) => css`
@@ -126,7 +127,7 @@ export const Popover = forwardRef(function Popover(
126
127
  tether,
127
128
  tetherOffset,
128
129
  tone = 'inherit',
129
- width = 0,
130
+ width: widthProp = 0,
130
131
  zOffset = theme.sanity.layer?.popover.zOffset,
131
132
  ...restProps
132
133
  } = props
@@ -136,6 +137,7 @@ export const Popover = forwardRef(function Popover(
136
137
  const [popperElement, setPopperElement] = useState<HTMLElement | null>(null)
137
138
  const [arrowElement, setArrowElement] = useState<HTMLElement | null>(null)
138
139
  const popperReferenceElement = referenceElementProp || referenceElement
140
+ const width = useArrayProp(widthProp)
139
141
 
140
142
  const modifiers = usePopoverModifiers({
141
143
  allowedAutoPlacements,
@@ -212,13 +214,13 @@ export const Popover = forwardRef(function Popover(
212
214
  >
213
215
  <PopoverCard
214
216
  $constrainSize={constrainSize}
217
+ $width={width}
215
218
  data-ui="PopoverCard"
216
219
  padding={padding}
217
220
  radius={radius}
218
221
  scheme={scheme}
219
222
  shadow={shadow}
220
223
  tone={tone}
221
- width={width as any}
222
224
  >
223
225
  {arrow && <PopoverArrow ref={setArrowElement} style={styles.arrow} />}
224
226
  {content}
@@ -1,7 +1,7 @@
1
1
  import {SelectIcon} from '@sanity/icons'
2
2
  import React, {forwardRef} from 'react'
3
3
  import styled from 'styled-components'
4
- import {useForwardedRef, useCustomValidity} from '../../hooks'
4
+ import {useForwardedRef, useCustomValidity, useArrayProp} from '../../hooks'
5
5
  import {Box} from '../box'
6
6
  import {Text} from '../text'
7
7
  import {selectStyle} from './styles'
@@ -20,10 +20,10 @@ export interface SelectProps {
20
20
  const Root = styled.div(selectStyle.root)
21
21
 
22
22
  const Input = styled.select<{
23
- $fontSize?: number | number[]
24
- $padding?: number | number[]
25
- $radius?: number | number[]
26
- $space?: number | number[]
23
+ $fontSize: number[]
24
+ $padding: number[]
25
+ $radius: number[]
26
+ $space: number[]
27
27
  }>(selectStyle.input)
28
28
 
29
29
  const IconBox = styled(Box)(selectStyle.iconBox)
@@ -57,10 +57,10 @@ export const Select = forwardRef(function Select(
57
57
  data-read-only={!disabled && readOnly ? '' : undefined}
58
58
  data-ui="Select"
59
59
  {...restProps}
60
- $fontSize={fontSize}
61
- $padding={padding}
62
- $radius={radius}
63
- $space={space}
60
+ $fontSize={useArrayProp(fontSize)}
61
+ $padding={useArrayProp(padding)}
62
+ $radius={useArrayProp(radius)}
63
+ $space={useArrayProp(space)}
64
64
  disabled={disabled || readOnly}
65
65
  ref={ref}
66
66
  >
@@ -1,5 +1,5 @@
1
1
  import {css, CSSObject, FlattenSimpleInterpolation} from 'styled-components'
2
- import {getResponsiveProp, rem, responsive, ThemeProps} from '../../styles'
2
+ import {rem, _responsive, ThemeProps} from '../../styles'
3
3
  import {
4
4
  focusRingBorderStyle,
5
5
  focusRingStyle,
@@ -100,17 +100,23 @@ function textSize(size: ThemeFontSize) {
100
100
  return {fontSize: rem(size.fontSize), lineHeight: rem(size.lineHeight)}
101
101
  }
102
102
 
103
- function inputTextSizeStyle(props: {$fontSize?: number | number[]} & ThemeProps) {
103
+ function inputTextSizeStyle(props: {$fontSize: number[]} & ThemeProps) {
104
104
  const {theme, $fontSize} = props
105
105
  const {sizes} = theme.sanity.fonts.text
106
106
 
107
- return responsive(theme.sanity.media, getResponsiveProp($fontSize), (sizeIndex) =>
107
+ return _responsive(theme.sanity.media, $fontSize, (sizeIndex) =>
108
108
  textSize(sizes[sizeIndex] || sizes[2])
109
109
  )
110
110
  }
111
111
 
112
112
  function inputStyle(): Array<
113
- | ((props: ResponsiveRadiusStyleProps & ThemeProps) => CSSObject[])
113
+ | ((
114
+ props: ResponsiveRadiusStyleProps & {
115
+ $fontSize: number[]
116
+ $padding: number[]
117
+ $space: number[]
118
+ } & ThemeProps
119
+ ) => CSSObject[])
114
120
  | ((props: ThemeProps) => FlattenSimpleInterpolation)
115
121
  > {
116
122
  return [
@@ -1,5 +1,6 @@
1
1
  import React, {forwardRef} from 'react'
2
2
  import styled from 'styled-components'
3
+ import {useArrayProp} from '../../hooks'
3
4
  import {Box, BoxProps} from '../box'
4
5
  import {stackBaseStyle, responsiveStackSpaceStyle, ResponsiveStackSpaceStyleProps} from './styles'
5
6
 
@@ -27,7 +28,7 @@ export const Stack = forwardRef(function Stack(
27
28
  data-as={typeof as === 'string' ? as : undefined}
28
29
  data-ui="Stack"
29
30
  {...restProps}
30
- $space={space}
31
+ $space={useArrayProp(space)}
31
32
  forwardedAs={as}
32
33
  ref={ref}
33
34
  />
@@ -1,8 +1,8 @@
1
1
  import {CSSObject} from 'styled-components'
2
- import {getResponsiveProp, rem, responsive, ThemeProps} from '../../styles'
2
+ import {rem, _responsive, ThemeProps} from '../../styles'
3
3
 
4
4
  export interface ResponsiveStackSpaceStyleProps {
5
- $space?: number | number[]
5
+ $space: number[]
6
6
  }
7
7
 
8
8
  const BASE_STYLE: CSSObject = {
@@ -26,7 +26,7 @@ export function responsiveStackSpaceStyle(
26
26
  const {theme} = props
27
27
  const {media, space} = theme.sanity
28
28
 
29
- return responsive(media, getResponsiveProp(props.$space), (spaceIndex) => ({
29
+ return _responsive(media, props.$space, (spaceIndex) => ({
30
30
  gridGap: rem(space[spaceIndex]),
31
31
  }))
32
32
  }
@@ -8,31 +8,41 @@ export default function OpticalAlignment() {
8
8
  <Stack space={1}>
9
9
  <Flex>
10
10
  <Card padding={0} scheme="dark">
11
- <Text size={4}>Hamburgefonstiv M</Text>
11
+ <Text accent size={4}>
12
+ Hamburgefonstiv M
13
+ </Text>
12
14
  </Card>
13
15
  </Flex>
14
16
 
15
17
  <Flex>
16
18
  <Card padding={0} scheme="dark">
17
- <Text size={3}>Hamburgefonstiv M</Text>
19
+ <Text accent size={3}>
20
+ Hamburgefonstiv M
21
+ </Text>
18
22
  </Card>
19
23
  </Flex>
20
24
 
21
25
  <Flex>
22
26
  <Card padding={0} scheme="dark">
23
- <Text size={2}>Hamburgefonstiv M</Text>
27
+ <Text accent size={2}>
28
+ Hamburgefonstiv M
29
+ </Text>
24
30
  </Card>
25
31
  </Flex>
26
32
 
27
33
  <Flex>
28
34
  <Card padding={0} scheme="dark">
29
- <Text size={1}>Hamburgefonstiv M</Text>
35
+ <Text accent size={1}>
36
+ Hamburgefonstiv M
37
+ </Text>
30
38
  </Card>
31
39
  </Flex>
32
40
 
33
41
  <Flex>
34
42
  <Card padding={0} scheme="dark">
35
- <Text size={0}>Hamburgefonstiv M</Text>
43
+ <Text accent size={0}>
44
+ Hamburgefonstiv M
45
+ </Text>
36
46
  </Card>
37
47
  </Flex>
38
48
 
@@ -1,5 +1,6 @@
1
1
  import React, {forwardRef} from 'react'
2
2
  import styled from 'styled-components'
3
+ import {useArrayProp} from '../../hooks'
3
4
  import {
4
5
  ResponsiveFontStyleProps,
5
6
  responsiveTextAlignStyle,
@@ -69,10 +70,10 @@ export const Text = forwardRef(function Text(
69
70
  data-ui="Text"
70
71
  {...restProps}
71
72
  $accent={accent}
72
- $align={align}
73
+ $align={useArrayProp(align)}
73
74
  $muted={muted}
74
75
  ref={ref}
75
- $size={size}
76
+ $size={useArrayProp(size)}
76
77
  $weight={weight}
77
78
  >
78
79
  <span>{children}</span>
@@ -1,7 +1,8 @@
1
- import {Container, Flex, Stack, Text, TextArea} from '@sanity/ui'
1
+ import {Card, Container, Flex, Stack, Text, TextArea} from '@sanity/ui'
2
2
  import {useBoolean, useSelect, useText} from '@sanity/ui-workshop'
3
3
  import React from 'react'
4
4
  import {
5
+ WORKSHOP_CARD_TONE_OPTIONS,
5
6
  WORKSHOP_FONT_WEIGHT_OPTIONS,
6
7
  WORKSHOP_RADIUS_OPTIONS,
7
8
  WORKSHOP_SPACE_OPTIONS,
@@ -9,6 +10,8 @@ import {
9
10
  } from '../../../__workshop__/constants'
10
11
 
11
12
  export default function PlainStory() {
13
+ const tone = useSelect('Tone', WORKSHOP_CARD_TONE_OPTIONS)
14
+
12
15
  const border = useBoolean('Border', true, 'Props')
13
16
  const customValidity = useText('Custom validity', '', 'Props') || undefined
14
17
  const disabled = useBoolean('Disabled', false, 'Props')
@@ -22,23 +25,25 @@ export default function PlainStory() {
22
25
  return (
23
26
  <Flex align="center" height="fill" justify="center" padding={[4, 5, 6]} sizing="border">
24
27
  <Container width={0}>
25
- <Stack space={3}>
26
- <Text as="label" htmlFor="text-area-example" size={1} weight="semibold">
27
- TextArea
28
- </Text>
29
- <TextArea
30
- border={border}
31
- customValidity={customValidity}
32
- disabled={disabled}
33
- fontSize={fontSize}
34
- id="text-area-example"
35
- padding={padding}
36
- placeholder={placeholder}
37
- radius={radius}
38
- readOnly={readOnly}
39
- weight={weight}
40
- />
41
- </Stack>
28
+ <Card padding={3} tone={tone}>
29
+ <Stack space={3}>
30
+ <Text as="label" htmlFor="text-area-example" size={1} weight="semibold">
31
+ TextArea
32
+ </Text>
33
+ <TextArea
34
+ border={border}
35
+ customValidity={customValidity}
36
+ disabled={disabled}
37
+ fontSize={fontSize}
38
+ id="text-area-example"
39
+ padding={padding}
40
+ placeholder={placeholder}
41
+ radius={radius}
42
+ readOnly={readOnly}
43
+ weight={weight}
44
+ />
45
+ </Stack>
46
+ </Card>
42
47
  </Container>
43
48
  </Flex>
44
49
  )
@@ -1,6 +1,6 @@
1
1
  import React, {forwardRef} from 'react'
2
2
  import styled from 'styled-components'
3
- import {useForwardedRef, useCustomValidity} from '../../hooks'
3
+ import {useForwardedRef, useCustomValidity, useArrayProp} from '../../hooks'
4
4
  import {
5
5
  responsiveInputPaddingStyle,
6
6
  responsiveRadiusStyle,
@@ -13,7 +13,7 @@ import {
13
13
  textInputFontSizeStyle,
14
14
  textInputRepresentationStyle,
15
15
  } from '../../styles/internal'
16
- import {ThemeFontWeightKey} from '../../theme'
16
+ import {ThemeFontWeightKey, useRootTheme} from '../../theme'
17
17
  import {ResponsiveRadiusProps} from '../types'
18
18
 
19
19
  /**
@@ -61,11 +61,14 @@ export const TextArea = forwardRef(function TextArea(
61
61
  fontSize = 2,
62
62
  padding = 3,
63
63
  radius = 1,
64
+ weight,
64
65
  ...restProps
65
66
  } = props
66
67
 
67
68
  const ref = useForwardedRef(forwardedRef)
68
69
 
70
+ const rootTheme = useRootTheme()
71
+
69
72
  useCustomValidity(ref, customValidity)
70
73
 
71
74
  return (
@@ -73,13 +76,22 @@ export const TextArea = forwardRef(function TextArea(
73
76
  <InputRoot>
74
77
  <Input
75
78
  data-as="textarea"
79
+ data-tone={rootTheme.tone}
76
80
  {...restProps}
77
- $fontSize={fontSize}
78
- $padding={padding}
81
+ $fontSize={useArrayProp(fontSize)}
82
+ $padding={useArrayProp(padding)}
83
+ $space={useArrayProp(0)}
84
+ $tone={rootTheme.tone}
85
+ $weight={weight}
79
86
  disabled={disabled}
80
87
  ref={ref}
81
88
  />
82
- <Presentation $border={border} $radius={radius} />
89
+ <Presentation
90
+ $border={border}
91
+ $radius={useArrayProp(radius)}
92
+ $tone={rootTheme.tone}
93
+ data-tone={rootTheme.tone}
94
+ />
83
95
  </InputRoot>
84
96
  </Root>
85
97
  )
@@ -1,7 +1,10 @@
1
- import {TextInput} from '@sanity/ui'
1
+ import {Box, TextInput} from '@sanity/ui'
2
+ import {useText} from '@sanity/ui-workshop'
2
3
  import React, {useCallback, useState} from 'react'
3
4
 
4
5
  export default function ClearButtonStory() {
6
+ const customValidity = useText('Custom validitiy')
7
+
5
8
  const [value, setValue] = useState('')
6
9
 
7
10
  const handleChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
@@ -13,12 +16,15 @@ export default function ClearButtonStory() {
13
16
  }, [])
14
17
 
15
18
  return (
16
- <TextInput
17
- clearButton
18
- onChange={handleChange}
19
- onClear={handleClear}
20
- placeholder="Enter text"
21
- value={value}
22
- />
19
+ <Box padding={4}>
20
+ <TextInput
21
+ clearButton
22
+ customValidity={customValidity}
23
+ onChange={handleChange}
24
+ onClear={handleClear}
25
+ placeholder="Enter text"
26
+ value={value}
27
+ />
28
+ </Box>
23
29
  )
24
30
  }
@@ -13,8 +13,8 @@ export default defineScope('primitives/text-input', 'TextInput', [
13
13
  component: lazy(() => import('./customValidity')),
14
14
  },
15
15
  {
16
- name: 'types',
17
- title: 'Types',
16
+ name: 'typed',
17
+ title: 'Typed',
18
18
  component: lazy(() => import('./typed')),
19
19
  },
20
20
  {
@@ -30,15 +30,33 @@ const typingPerfTest: PerfTestProps<HTMLInputElement> = {
30
30
  export default function PlainStory() {
31
31
  const {ref, Wrapper} = usePerfTest(typingPerfTest)
32
32
 
33
+ return (
34
+ <Flex align="center" height="fill" justify="center" padding={[4, 5, 6]} sizing="border">
35
+ <Container width={0}>
36
+ <Stack space={3}>
37
+ <Text as="label" htmlFor="text-input-example" size={1} weight="semibold">
38
+ TextInput
39
+ </Text>
40
+ <Wrapper>
41
+ <TextInputTest inputRef={ref} />
42
+ </Wrapper>
43
+ </Stack>
44
+ </Container>
45
+ </Flex>
46
+ )
47
+ }
48
+
49
+ function TextInputTest(props: {inputRef: React.Ref<HTMLInputElement>}) {
50
+ const {inputRef: ref} = props
33
51
  const border = useBoolean('Border', true, 'Props')
34
52
  const customValidity = useText('Custom validity', '', 'Props') || undefined
35
53
  const disabled = useBoolean('Disabled', false, 'Props')
36
54
  const fontSize = useSelect('Font size', WORKSHOP_TEXT_FONT_SIZE_OPTIONS, 2, 'Props')
37
- const icon = useSelect('Icon', WORKSHOP_ICON_SYMBOL_OPTIONS, 'add-circle', 'Props') as IconSymbol
55
+ const icon = useSelect('Icon', WORKSHOP_ICON_SYMBOL_OPTIONS, 'search', 'Props') as IconSymbol
38
56
  const iconRight = useSelect(
39
57
  'Icon (right)',
40
58
  WORKSHOP_ICON_SYMBOL_OPTIONS,
41
- 'add-circle',
59
+ 'close',
42
60
  'Props'
43
61
  ) as IconSymbol
44
62
  const padding = useSelect('Padding', WORKSHOP_SPACE_OPTIONS, 3, 'Props')
@@ -56,35 +74,24 @@ export default function PlainStory() {
56
74
  )
57
75
 
58
76
  return (
59
- <Flex align="center" height="fill" justify="center" padding={[4, 5, 6]} sizing="border">
60
- <Container width={0}>
61
- <Stack space={3}>
62
- <Text as="label" htmlFor="text-input-example" size={1} weight="semibold">
63
- TextInput
64
- </Text>
65
- <Wrapper>
66
- <TextInput
67
- border={border}
68
- customValidity={customValidity}
69
- disabled={disabled}
70
- fontSize={fontSize}
71
- icon={icon && icons[icon]}
72
- iconRight={iconRight && icons[iconRight]}
73
- id="text-input-example"
74
- name="email"
75
- onChange={handleChange}
76
- padding={padding}
77
- placeholder={placeholder}
78
- radius={radius}
79
- readOnly={readOnly}
80
- ref={ref}
81
- space={space}
82
- value={value}
83
- weight={weight}
84
- />
85
- </Wrapper>
86
- </Stack>
87
- </Container>
88
- </Flex>
77
+ <TextInput
78
+ border={border}
79
+ customValidity={customValidity}
80
+ disabled={disabled}
81
+ fontSize={fontSize}
82
+ icon={icon && icons[icon]}
83
+ iconRight={iconRight && icons[iconRight]}
84
+ id="text-input-example"
85
+ name="email"
86
+ onChange={handleChange}
87
+ padding={padding}
88
+ placeholder={placeholder}
89
+ radius={radius}
90
+ readOnly={readOnly}
91
+ ref={ref}
92
+ space={space}
93
+ value={value}
94
+ weight={weight}
95
+ />
89
96
  )
90
97
  }