@sanity/ui 0.37.20 → 0.37.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/lib/dts/src/components/breadcrumbs/breadcrumbs.d.ts.map +1 -1
  2. package/lib/dts/src/components/dialog/dialog.d.ts.map +1 -1
  3. package/lib/dts/src/components/dialog/styles.d.ts +1 -1
  4. package/lib/dts/src/components/dialog/styles.d.ts.map +1 -1
  5. package/lib/dts/src/components/hotkeys/hotkeys.d.ts.map +1 -1
  6. package/lib/dts/src/components/menu/menuGroup.d.ts.map +1 -1
  7. package/lib/dts/src/components/skeleton/skeleton.d.ts.map +1 -1
  8. package/lib/dts/src/hooks/index.d.ts +1 -2
  9. package/lib/dts/src/hooks/index.d.ts.map +1 -1
  10. package/lib/dts/src/hooks/useElementRect/useElementRect.d.ts +1 -1
  11. package/lib/dts/src/hooks/useElementRect/useElementRect.d.ts.map +1 -1
  12. package/lib/dts/src/hooks/useResponsiveProp.d.ts +6 -0
  13. package/lib/dts/src/hooks/useResponsiveProp.d.ts.map +1 -0
  14. package/lib/dts/src/index.d.ts +0 -1
  15. package/lib/dts/src/index.d.ts.map +1 -1
  16. package/lib/dts/src/primitives/_selectable/selectable.d.ts +2 -1
  17. package/lib/dts/src/primitives/_selectable/selectable.d.ts.map +1 -1
  18. package/lib/dts/src/primitives/avatar/avatar.d.ts.map +1 -1
  19. package/lib/dts/src/primitives/avatar/avatarCounter.d.ts.map +1 -1
  20. package/lib/dts/src/primitives/avatar/avatarStack.d.ts.map +1 -1
  21. package/lib/dts/src/primitives/avatar/styles.d.ts.map +1 -1
  22. package/lib/dts/src/primitives/badge/badge.d.ts.map +1 -1
  23. package/lib/dts/src/primitives/box/box.d.ts.map +1 -1
  24. package/lib/dts/src/primitives/button/button.d.ts.map +1 -1
  25. package/lib/dts/src/primitives/card/card.d.ts.map +1 -1
  26. package/lib/dts/src/primitives/code/code.d.ts.map +1 -1
  27. package/lib/dts/src/primitives/container/container.d.ts.map +1 -1
  28. package/lib/dts/src/primitives/container/styles.d.ts.map +1 -1
  29. package/lib/dts/src/primitives/container/types.d.ts +1 -1
  30. package/lib/dts/src/primitives/container/types.d.ts.map +1 -1
  31. package/lib/dts/src/primitives/flex/flex.d.ts.map +1 -1
  32. package/lib/dts/src/primitives/grid/grid.d.ts.map +1 -1
  33. package/lib/dts/src/primitives/heading/heading.d.ts.map +1 -1
  34. package/lib/dts/src/primitives/inline/inline.d.ts.map +1 -1
  35. package/lib/dts/src/primitives/inline/styles.d.ts.map +1 -1
  36. package/lib/dts/src/primitives/inline/types.d.ts +1 -1
  37. package/lib/dts/src/primitives/inline/types.d.ts.map +1 -1
  38. package/lib/dts/src/primitives/kbd/kbd.d.ts.map +1 -1
  39. package/lib/dts/src/primitives/label/label.d.ts.map +1 -1
  40. package/lib/dts/src/primitives/popover/popover.d.ts.map +1 -1
  41. package/lib/dts/src/primitives/select/styles.d.ts +1 -5
  42. package/lib/dts/src/primitives/select/styles.d.ts.map +1 -1
  43. package/lib/dts/src/primitives/stack/stack.d.ts.map +1 -1
  44. package/lib/dts/src/primitives/stack/styles.d.ts +1 -1
  45. package/lib/dts/src/primitives/stack/styles.d.ts.map +1 -1
  46. package/lib/dts/src/primitives/text/text.d.ts.map +1 -1
  47. package/lib/dts/src/primitives/textArea/textArea.d.ts.map +1 -1
  48. package/lib/dts/src/primitives/textInput/textInput.d.ts.map +1 -1
  49. package/lib/dts/src/primitives/tooltip/tooltip.d.ts.map +1 -1
  50. package/lib/dts/src/primitives/types.d.ts +1 -1
  51. package/lib/dts/src/primitives/types.d.ts.map +1 -1
  52. package/lib/dts/src/styles/border/types.d.ts +5 -5
  53. package/lib/dts/src/styles/border/types.d.ts.map +1 -1
  54. package/lib/dts/src/styles/box/types.d.ts +4 -4
  55. package/lib/dts/src/styles/box/types.d.ts.map +1 -1
  56. package/lib/dts/src/styles/flex/flexItemStyle.d.ts.map +1 -1
  57. package/lib/dts/src/styles/flex/types.d.ts +6 -6
  58. package/lib/dts/src/styles/flex/types.d.ts.map +1 -1
  59. package/lib/dts/src/styles/font/responsiveFont.d.ts.map +1 -1
  60. package/lib/dts/src/styles/font/types.d.ts +3 -3
  61. package/lib/dts/src/styles/font/types.d.ts.map +1 -1
  62. package/lib/dts/src/styles/grid/types.d.ts +14 -14
  63. package/lib/dts/src/styles/grid/types.d.ts.map +1 -1
  64. package/lib/dts/src/styles/helpers.d.ts +4 -4
  65. package/lib/dts/src/styles/helpers.d.ts.map +1 -1
  66. package/lib/dts/src/styles/input/responsiveInputPaddingStyle.d.ts +12 -12
  67. package/lib/dts/src/styles/input/responsiveInputPaddingStyle.d.ts.map +1 -1
  68. package/lib/dts/src/styles/input/textInputStyle.d.ts +2 -7
  69. package/lib/dts/src/styles/input/textInputStyle.d.ts.map +1 -1
  70. package/lib/dts/src/styles/margin/types.d.ts +7 -7
  71. package/lib/dts/src/styles/margin/types.d.ts.map +1 -1
  72. package/lib/dts/src/styles/padding/types.d.ts +7 -7
  73. package/lib/dts/src/styles/padding/types.d.ts.map +1 -1
  74. package/lib/dts/src/styles/radius/types.d.ts +1 -1
  75. package/lib/dts/src/styles/radius/types.d.ts.map +1 -1
  76. package/lib/dts/src/styles/shadow/shadowStyle.d.ts.map +1 -1
  77. package/lib/dts/src/styles/shadow/types.d.ts +1 -1
  78. package/lib/dts/src/styles/shadow/types.d.ts.map +1 -1
  79. package/lib/dts/src/theme/studioTheme/color.d.ts.map +1 -1
  80. package/lib/dts/src/utils/elementQuery/elementQuery.d.ts.map +1 -1
  81. package/lib/dts/src/utils/index.d.ts +1 -0
  82. package/lib/dts/src/utils/index.d.ts.map +1 -1
  83. package/lib/dts/src/utils/resizeObserver.d.ts +6 -0
  84. package/lib/dts/src/utils/resizeObserver.d.ts.map +1 -0
  85. package/lib/dts/src/utils/virtualList/virtualList.d.ts.map +1 -1
  86. package/lib/sanity-ui.js +570 -731
  87. package/lib/sanity-ui.js.map +1 -1
  88. package/lib/sanity-ui.modern.js +591 -762
  89. package/lib/sanity-ui.modern.js.map +1 -1
  90. package/lib/sanity-ui.module.js +566 -725
  91. package/lib/sanity-ui.module.js.map +1 -1
  92. package/package.json +11 -11
  93. package/src/__workshop__/color/overview.tsx +11 -9
  94. package/src/components/autocomplete/__workshop__/async.tsx +12 -14
  95. package/src/components/autocomplete/__workshop__/constrainedHeight.tsx +0 -36
  96. package/src/components/autocomplete/autocomplete.tsx +2 -2
  97. package/src/components/breadcrumbs/breadcrumbs.tsx +2 -3
  98. package/src/components/dialog/dialog.tsx +9 -17
  99. package/src/components/dialog/styles.ts +4 -4
  100. package/src/components/hotkeys/hotkeys.tsx +1 -3
  101. package/src/components/menu/__workshop__/constrainedInBoundary.tsx +14 -11
  102. package/src/components/menu/__workshop__/groups.tsx +1 -1
  103. package/src/components/menu/menuGroup.tsx +2 -3
  104. package/src/components/menu/menuItem.tsx +3 -3
  105. package/src/components/skeleton/skeleton.tsx +1 -10
  106. package/src/components/skeleton/textSkeleton.tsx +7 -7
  107. package/src/hooks/index.ts +1 -2
  108. package/src/hooks/useElementRect/useElementRect.ts +16 -4
  109. package/src/hooks/useResponsiveProp.ts +10 -0
  110. package/src/index.ts +0 -1
  111. package/src/primitives/_selectable/selectable.tsx +4 -5
  112. package/src/primitives/avatar/avatar.tsx +5 -7
  113. package/src/primitives/avatar/avatarCounter.tsx +11 -12
  114. package/src/primitives/avatar/avatarStack.tsx +10 -15
  115. package/src/primitives/avatar/styles.ts +2 -2
  116. package/src/primitives/badge/badge.tsx +2 -3
  117. package/src/primitives/box/box.tsx +25 -26
  118. package/src/primitives/button/button.tsx +10 -22
  119. package/src/primitives/card/card.tsx +7 -8
  120. package/src/primitives/checkbox/__workshop__/example.tsx +2 -4
  121. package/src/primitives/checkbox/__workshop__/props.tsx +2 -4
  122. package/src/primitives/checkbox/__workshop__/readOnly.tsx +2 -4
  123. package/src/primitives/code/__workshop__/props.tsx +1 -1
  124. package/src/primitives/code/code.tsx +1 -2
  125. package/src/primitives/container/container.tsx +1 -10
  126. package/src/primitives/container/styles.ts +2 -2
  127. package/src/primitives/container/types.ts +1 -1
  128. package/src/primitives/flex/flex.tsx +5 -6
  129. package/src/primitives/grid/__workshop__/responsive.tsx +12 -13
  130. package/src/primitives/grid/grid.tsx +8 -9
  131. package/src/primitives/heading/__workshop__/opticalAlignment.tsx +7 -19
  132. package/src/primitives/heading/heading.tsx +2 -3
  133. package/src/primitives/inline/inline.tsx +6 -12
  134. package/src/primitives/inline/styles.ts +2 -2
  135. package/src/primitives/inline/types.ts +1 -1
  136. package/src/primitives/kbd/kbd.tsx +1 -2
  137. package/src/primitives/label/label.tsx +3 -4
  138. package/src/primitives/popover/__workshop__/index.ts +5 -10
  139. package/src/primitives/popover/__workshop__/{MarginsStory.tsx → margins.tsx} +1 -1
  140. package/src/primitives/popover/__workshop__/{MatchReferenceWidthStory.tsx → matchReferenceWidth.tsx} +0 -0
  141. package/src/primitives/popover/__workshop__/{PlainStory.tsx → plain.tsx} +14 -12
  142. package/src/primitives/popover/__workshop__/{RecursiveStory.tsx → recursive.tsx} +1 -4
  143. package/src/primitives/popover/__workshop__/rightAligned.tsx +57 -0
  144. package/src/primitives/popover/popover.tsx +10 -29
  145. package/src/primitives/select/select.tsx +9 -9
  146. package/src/primitives/select/styles.ts +4 -10
  147. package/src/primitives/stack/stack.tsx +1 -2
  148. package/src/primitives/stack/styles.ts +3 -3
  149. package/src/primitives/text/__workshop__/opticalAlignment.tsx +5 -15
  150. package/src/primitives/text/text.tsx +2 -3
  151. package/src/primitives/textArea/__workshop__/plain.tsx +18 -23
  152. package/src/primitives/textArea/textArea.tsx +5 -21
  153. package/src/primitives/textInput/__workshop__/clearButton.tsx +8 -14
  154. package/src/primitives/textInput/__workshop__/index.ts +2 -2
  155. package/src/primitives/textInput/__workshop__/plain.tsx +32 -39
  156. package/src/primitives/textInput/__workshop__/tones.tsx +95 -234
  157. package/src/primitives/textInput/__workshop__/typed.tsx +2 -8
  158. package/src/primitives/textInput/textInput.tsx +12 -47
  159. package/src/primitives/tooltip/__workshop__/props.tsx +2 -7
  160. package/src/primitives/tooltip/tooltip.tsx +9 -19
  161. package/src/primitives/types.ts +1 -1
  162. package/src/styles/border/borderStyle.ts +6 -6
  163. package/src/styles/border/types.ts +5 -5
  164. package/src/styles/box/boxStyle.ts +5 -5
  165. package/src/styles/box/types.ts +4 -4
  166. package/src/styles/flex/flexItemStyle.ts +4 -5
  167. package/src/styles/flex/flexStyle.ts +6 -6
  168. package/src/styles/flex/types.ts +6 -6
  169. package/src/styles/font/responsiveFont.ts +4 -2
  170. package/src/styles/font/textAlignStyle.ts +2 -2
  171. package/src/styles/font/types.ts +3 -4
  172. package/src/styles/grid/gridItemStyle.ts +7 -7
  173. package/src/styles/grid/gridStyle.ts +9 -9
  174. package/src/styles/grid/types.ts +14 -14
  175. package/src/styles/helpers.ts +9 -9
  176. package/src/styles/input/responsiveInputPaddingStyle.ts +27 -24
  177. package/src/styles/input/textInputStyle.ts +80 -92
  178. package/src/styles/margin/marginStyle.ts +8 -8
  179. package/src/styles/margin/marginsStyle.test.ts +1 -1
  180. package/src/styles/margin/types.ts +7 -7
  181. package/src/styles/padding/paddingStyle.test.ts +1 -1
  182. package/src/styles/padding/paddingStyle.ts +8 -8
  183. package/src/styles/padding/types.ts +7 -7
  184. package/src/styles/radius/radiusStyle.ts +2 -2
  185. package/src/styles/radius/types.ts +1 -1
  186. package/src/styles/shadow/shadowStyle.ts +5 -2
  187. package/src/styles/shadow/types.ts +1 -1
  188. package/src/theme/studioTheme/color.ts +14 -15
  189. package/src/theme/studioTheme/fonts.ts +4 -4
  190. package/src/utils/elementQuery/elementQuery.tsx +18 -5
  191. package/src/utils/index.ts +1 -0
  192. package/src/utils/layer/layerProvider.tsx +2 -2
  193. package/src/{observers → utils}/resizeObserver.ts +3 -1
  194. package/src/utils/virtualList/virtualList.tsx +1 -3
  195. package/lib/dts/src/hooks/useArrayProp.d.ts +0 -7
  196. package/lib/dts/src/hooks/useArrayProp.d.ts.map +0 -1
  197. package/lib/dts/src/hooks/useElementSize.d.ts +0 -7
  198. package/lib/dts/src/hooks/useElementSize.d.ts.map +0 -1
  199. package/lib/dts/src/observers/elementSizeObserver.d.ts +0 -37
  200. package/lib/dts/src/observers/elementSizeObserver.d.ts.map +0 -1
  201. package/lib/dts/src/observers/index.d.ts +0 -3
  202. package/lib/dts/src/observers/index.d.ts.map +0 -1
  203. package/lib/dts/src/observers/resizeObserver.d.ts +0 -5
  204. package/lib/dts/src/observers/resizeObserver.d.ts.map +0 -1
  205. package/src/hooks/useArrayProp.ts +0 -23
  206. package/src/hooks/useElementSize.ts +0 -18
  207. package/src/observers/elementSizeObserver.ts +0 -116
  208. package/src/observers/index.ts +0 -2
  209. package/src/primitives/popover/__workshop__/RightAlignedStory.tsx +0 -60
  210. package/src/primitives/popover/__workshop__/TestStory.tsx +0 -79
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "0.37.20",
3
+ "version": "0.37.21",
4
4
  "sideEffects": false,
5
5
  "source": "./src/index.ts",
6
6
  "exports": {
@@ -19,7 +19,7 @@
19
19
  "license": "MIT",
20
20
  "scripts": {
21
21
  "build": "run-s build:microbundle",
22
- "build:microbundle": "microbundle --format modern,esm,cjs --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react --no-compress --tsconfig tsconfig.lib.json",
22
+ "build:microbundle": "microbundle --format modern,esm,cjs --jsx React.createElement --jsxImportSource react --no-compress --tsconfig tsconfig.lib.json",
23
23
  "clean": "rimraf lib",
24
24
  "lint": "eslint . --ext .js,.jsx,.mjs,.ts,.tsx --quiet",
25
25
  "prebuild": "yarn clean",
@@ -30,20 +30,20 @@
30
30
  "watch:es": "tsc --preserveWatchOutput -w --module ES6 --outDir lib/esm --project tsconfig.lib.json --rootDir src --target ES6"
31
31
  },
32
32
  "dependencies": {
33
- "@juggle/resize-observer": "^3.4.0",
34
- "@popperjs/core": "^2.11.6",
35
- "@reach/auto-id": "^0.17.0",
36
- "@sanity/color": "^2.1.14",
37
- "@sanity/icons": "^1.3.4",
33
+ "@juggle/resize-observer": "^3.3.1",
34
+ "@popperjs/core": "^2.11.5",
35
+ "@reach/auto-id": "^0.16.0",
36
+ "@sanity/color": "^2.1.11",
37
+ "@sanity/icons": "^1.3.1",
38
38
  "framer-motion": "6.3.0",
39
39
  "popper-max-size-modifier": "^0.2.0",
40
40
  "react-is": "^17.0.2",
41
- "react-popper": "^2.3.0",
41
+ "react-popper": "^2.2.5",
42
42
  "react-refractor": "^2.1.7"
43
43
  },
44
44
  "devDependencies": {
45
- "@testing-library/dom": "^8.17.1",
46
- "@testing-library/jest-dom": "^5.16.5",
45
+ "@testing-library/dom": "^8.13.0",
46
+ "@testing-library/jest-dom": "^5.16.4",
47
47
  "@testing-library/react": "^12.1.5",
48
48
  "@types/refractor": "^3.0.2",
49
49
  "react": "^17.0.2",
@@ -72,5 +72,5 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "707079756d209432e82fc886b87e8eb641be9b0d"
75
+ "gitHead": "4f7ef1d42b0b536e746ac2670c113a24148c6fdc"
76
76
  }
@@ -19,7 +19,7 @@ const clipboard = {
19
19
 
20
20
  export default function ColorOverviewStory(): React.ReactElement {
21
21
  return (
22
- <Grid columns={[1, 1, 2, 3]} gapX={[4, 4, 5]} gapY={[5, 5, 6]} padding={[4, 5, 6]}>
22
+ <Grid columns={[1, 1, 2, 3]} gapX={[3, 4, 5]} gapY={[4, 5, 6]} padding={[3, 4, 5]}>
23
23
  {COLOR_HUES.map((hueKey) => (
24
24
  <ColorHuePreview tints={hues[hueKey]} hueKey={hueKey} key={hueKey} />
25
25
  ))}
@@ -32,7 +32,7 @@ function ColorHuePreview(props: {hueKey: string; tints: ColorTints}) {
32
32
 
33
33
  return (
34
34
  <Box>
35
- <Heading as="h2" size={1}>
35
+ <Heading as="h2" size={[1, 1, 2]}>
36
36
  {ucfirst(hueKey)}
37
37
  </Heading>
38
38
 
@@ -78,20 +78,22 @@ function ColorTintPreview(props: {tint: ColorValue}) {
78
78
  as="button"
79
79
  onClick={handleClick}
80
80
  radius={2}
81
- style={{
82
- ['--card-bg-color' as any]: tint.hex,
83
- ['--card-fg-color' as any]: hsl.l < 50 ? white.hex : black.hex,
84
- cursor: 'pointer',
85
- }}
81
+ style={
82
+ {
83
+ '--card-bg-color': tint.hex,
84
+ '--card-fg-color': hsl.l < 50 ? white.hex : black.hex,
85
+ cursor: 'pointer',
86
+ } as any
87
+ }
86
88
  >
87
89
  <Flex padding={3}>
88
90
  <Box flex={1}>
89
- <Code size={1} style={{color: 'inherit'}}>
91
+ <Code size={[1, 1, 2]} style={{color: 'inherit'}}>
90
92
  {tint.title}
91
93
  </Code>
92
94
  </Box>
93
95
  <Box>
94
- <Code size={1} style={{color: 'inherit'}}>
96
+ <Code size={[1, 1, 2]} style={{color: 'inherit'}}>
95
97
  {tint.hex}
96
98
  </Code>
97
99
  </Box>
@@ -1,11 +1,11 @@
1
- import {EarthAmericasIcon, SearchIcon} from '@sanity/icons'
1
+ import {LinkIcon} from '@sanity/icons'
2
2
  import {
3
3
  Autocomplete,
4
4
  BaseAutocompleteOption,
5
5
  Box,
6
+ Button,
6
7
  Card,
7
8
  Code,
8
- Flex,
9
9
  LayerProvider,
10
10
  Stack,
11
11
  Text,
@@ -88,7 +88,6 @@ export default function AsyncStory() {
88
88
  <Autocomplete
89
89
  disabled={loadingCurrentRef}
90
90
  filterOption={filterOption}
91
- icon={value ? EarthAmericasIcon : SearchIcon}
92
91
  id="async"
93
92
  loading={loading}
94
93
  onChange={setValue}
@@ -96,6 +95,11 @@ export default function AsyncStory() {
96
95
  openButton={{onClick: handleOpenButtonClick}}
97
96
  options={options}
98
97
  placeholder="Search"
98
+ prefix={
99
+ <Box padding={1}>
100
+ <Button disabled={!value} icon={LinkIcon} mode="bleed" padding={2} />
101
+ </Box>
102
+ }
99
103
  radius={1}
100
104
  renderOption={renderOption}
101
105
  renderValue={renderValue}
@@ -136,19 +140,13 @@ function AsyncOption(props: {
136
140
  selected={selected}
137
141
  tabIndex={tabIndex}
138
142
  >
139
- <Flex gap={3}>
140
- <Text>
141
- <EarthAmericasIcon />
143
+ {loading && (
144
+ <Text muted>
145
+ <>Loading…</>
142
146
  </Text>
147
+ )}
143
148
 
144
- {loading && (
145
- <Text muted>
146
- <>Loading…</>
147
- </Text>
148
- )}
149
-
150
- {!loading && <Text muted={!data}>{data ? data.title : <>Untitled</>}</Text>}
151
- </Flex>
149
+ {!loading && <Text muted={!data}>{data ? data.title : <>Untitled</>}</Text>}
152
150
  </Card>
153
151
  )
154
152
  }
@@ -8,9 +8,7 @@ import {
8
8
  Text,
9
9
  } from '@sanity/ui'
10
10
  import React, {useCallback, useState} from 'react'
11
- import {Popover} from '../../../primitives'
12
11
  import countries from '../__fixtures__/countries'
13
- import {AutocompleteProps} from '../autocomplete'
14
12
  import {ExampleOption} from './types'
15
13
 
16
14
  export default function ConstrainedHeightStory() {
@@ -73,38 +71,6 @@ function ConstrainedHeightExampleField({id, label}: {id: string; label: string})
73
71
 
74
72
  const options = countries.map((item) => ({value: item.code, title: item.name}))
75
73
 
76
- const renderPopover: AutocompleteProps['renderPopover'] = useCallback(
77
- (
78
- popoverProps: {
79
- content: React.ReactElement | null
80
- hidden: boolean
81
- inputElement: HTMLInputElement | null
82
- onMouseEnter: () => void
83
- onMouseLeave: () => void
84
- },
85
- popoverRef: React.Ref<HTMLDivElement>
86
- ) => {
87
- const {hidden, inputElement, ...restProps} = popoverProps
88
-
89
- if (hidden) return null
90
-
91
- return (
92
- <Popover
93
- {...restProps}
94
- arrow={false}
95
- constrainSize
96
- matchReferenceWidth
97
- open
98
- placement="bottom"
99
- radius={1}
100
- ref={popoverRef}
101
- referenceElement={inputElement}
102
- />
103
- )
104
- },
105
- []
106
- )
107
-
108
74
  return (
109
75
  <Stack space={3}>
110
76
  <Text size={1} weight="medium">
@@ -118,10 +84,8 @@ function ConstrainedHeightExampleField({id, label}: {id: string; label: string})
118
84
  openButton
119
85
  options={options}
120
86
  placeholder="Search"
121
- // popover={{allowedAutoPlacements: ['bottom-start', 'top-start']}}
122
87
  radius={1}
123
88
  renderOption={renderOption}
124
- renderPopover={renderPopover}
125
89
  renderValue={renderValue}
126
90
  value={value}
127
91
  />
@@ -11,7 +11,7 @@ import React, {
11
11
  } from 'react'
12
12
  import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
13
13
  import {_hasFocus, _raf, focusFirstDescendant} from '../../helpers'
14
- import {useForwardedRef, useArrayProp} from '../../hooks'
14
+ import {useForwardedRef, useResponsiveProp} from '../../hooks'
15
15
  import {Box, BoxProps, Button, Card, PopoverProps, Stack, Text, TextInput} from '../../primitives'
16
16
  import {AnimatedSpinnerIcon, ListBox, ResultsPopover, Root} from './autocomplete.styles'
17
17
  import {AutocompleteOption} from './autocompleteOption'
@@ -175,7 +175,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
175
175
  const popoverMouseWithinRef = useRef(false)
176
176
  const listBoxId = `${id}-listbox`
177
177
  const options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY
178
- const padding = useArrayProp(paddingProp)
178
+ const padding = useResponsiveProp(paddingProp)
179
179
  const currentOption = useMemo(
180
180
  () => (value !== null ? options.find((o) => o.value === value) : undefined),
181
181
  [options, value]
@@ -7,7 +7,7 @@ import React, {
7
7
  useMemo,
8
8
  useState,
9
9
  } from 'react'
10
- import {useArrayProp, useClickOutside} from '../../hooks'
10
+ import {useClickOutside} from '../../hooks'
11
11
  import {Box, Popover, Stack, Text} from '../../primitives'
12
12
  import {ExpandButton, Root} from './breadcrumbs.styles'
13
13
 
@@ -27,8 +27,7 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
27
27
  props: BreadcrumbsProps & Omit<React.HTMLProps<HTMLOListElement>, 'as' | 'ref' | 'type'>,
28
28
  ref: React.ForwardedRef<HTMLOListElement>
29
29
  ) {
30
- const {children, maxLength, separator, space: spaceRaw = 2, ...restProps} = props
31
- const space = useArrayProp(spaceRaw)
30
+ const {children, maxLength, separator, space = 2, ...restProps} = props
32
31
  const [open, setOpen] = useState(false)
33
32
  const [expandElement, setExpandElement] = useState<HTMLButtonElement | null>(null)
34
33
  const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
@@ -2,7 +2,7 @@ import {CloseIcon} from '@sanity/icons'
2
2
  import React, {forwardRef, useCallback, useEffect, useRef, useState} from 'react'
3
3
  import styled from 'styled-components'
4
4
  import {focusFirstDescendant, focusLastDescendant} from '../../helpers'
5
- import {useArrayProp, useClickOutside, useForwardedRef, useGlobalKeyDown} from '../../hooks'
5
+ import {useClickOutside, useForwardedRef, useGlobalKeyDown} from '../../hooks'
6
6
  import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
7
7
  import {ResponsivePaddingProps, ResponsiveWidthProps} from '../../primitives/types'
8
8
  import {responsivePaddingStyle, ResponsivePaddingStyleProps} from '../../styles/internal'
@@ -138,14 +138,11 @@ const DialogCard = forwardRef(function DialogCard(
138
138
  id,
139
139
  onClickOutside,
140
140
  onClose,
141
- radius: radiusProp,
141
+ radius,
142
142
  scheme,
143
- shadow: shadowProp,
144
- width: widthProp,
143
+ shadow,
144
+ width,
145
145
  } = props
146
- const radius = useArrayProp(radiusProp)
147
- const shadow = useArrayProp(shadowProp)
148
- const width = useArrayProp(widthProp)
149
146
  const forwardedRef = useForwardedRef(ref)
150
147
  const [rootElement, setRootElement] = useState<HTMLDivElement | null>(null)
151
148
  const localContentRef = useRef<HTMLDivElement | null>(null)
@@ -258,7 +255,7 @@ export const Dialog = forwardRef(function Dialog(
258
255
  const {
259
256
  __unstable_autoFocus: autoFocus = true,
260
257
  __unstable_hideCloseButton: hideCloseButton = false,
261
- cardRadius: cardRadiusProp = 3,
258
+ cardRadius = 3,
262
259
  cardShadow = 4,
263
260
  children,
264
261
  contentRef,
@@ -267,19 +264,14 @@ export const Dialog = forwardRef(function Dialog(
267
264
  id,
268
265
  onClickOutside,
269
266
  onClose,
270
- padding: paddingProp = 4,
267
+ padding = 4,
271
268
  portal,
272
- position: positionProp = dialog.position || 'fixed',
269
+ position = dialog.position || 'fixed',
273
270
  scheme,
274
- width: widthProp = 0,
275
- zOffset: zOffsetProp = dialog.zOffset || theme.sanity.layer?.dialog.zOffset,
271
+ width = 0,
272
+ zOffset = dialog.zOffset || theme.sanity.layer?.dialog.zOffset,
276
273
  ...restProps
277
274
  } = props
278
- const cardRadius = useArrayProp(cardRadiusProp)
279
- const padding = useArrayProp(paddingProp)
280
- const position = useArrayProp(positionProp)
281
- const width = useArrayProp(widthProp)
282
- const zOffset = useArrayProp(zOffsetProp)
283
275
  const preDivRef = useRef<HTMLDivElement | null>(null)
284
276
  const postDivRef = useRef<HTMLDivElement | null>(null)
285
277
  const cardRef = useRef<HTMLDivElement | null>(null)
@@ -1,12 +1,12 @@
1
1
  import {CSSObject} from 'styled-components'
2
- import {_responsive, ThemeProps} from '../../styles'
2
+ import {getResponsiveProp, responsive, ThemeProps} from '../../styles'
3
3
  import {DialogPosition} from '../../types'
4
4
 
5
5
  /**
6
6
  * @internal
7
7
  */
8
8
  export interface ResponsiveDialogPositionStyleProps {
9
- $position: DialogPosition[]
9
+ $position: DialogPosition | DialogPosition[]
10
10
  }
11
11
 
12
12
  export function dialogStyle({theme}: ThemeProps): CSSObject {
@@ -24,7 +24,7 @@ export function dialogStyle({theme}: ThemeProps): CSSObject {
24
24
  alignItems: 'center',
25
25
  justifyContent: 'center',
26
26
  outline: 'none',
27
- background: color.shadow.umbra,
27
+ background: color.shadow.penumbra,
28
28
  }
29
29
  }
30
30
 
@@ -34,5 +34,5 @@ export function responsiveDialogPositionStyle(
34
34
  const {theme} = props
35
35
  const {media} = theme.sanity
36
36
 
37
- return _responsive(media, props.$position, (position) => ({'&&': {position}}))
37
+ return responsive(media, getResponsiveProp(props.$position), (position) => ({'&&': {position}}))
38
38
  }
@@ -1,6 +1,5 @@
1
1
  import React, {forwardRef} from 'react'
2
2
  import styled from 'styled-components'
3
- import {useArrayProp} from '../../hooks'
4
3
  import {Inline, KBD} from '../../primitives'
5
4
 
6
5
  /**
@@ -34,8 +33,7 @@ export const Hotkeys = forwardRef(function Hotkeys(
34
33
  props: HotkeysProps & Omit<React.HTMLProps<HTMLElement>, 'as' | 'ref' | 'size'>,
35
34
  ref: React.Ref<HTMLElement>
36
35
  ) {
37
- const {fontSize, keys, padding, radius, space: spaceProp = 1, ...restProps} = props
38
- const space = useArrayProp(spaceProp)
36
+ const {fontSize, keys, padding, radius, space = 1, ...restProps} = props
39
37
 
40
38
  if (!keys || keys.length === 0) {
41
39
  return <></>
@@ -8,19 +8,11 @@ import {
8
8
  Menu,
9
9
  MenuButton,
10
10
  MenuItem,
11
+ PopoverProps,
11
12
  SelectableTone,
12
13
  Text,
13
14
  } from '@sanity/ui'
14
- import React, {useState} from 'react'
15
- import {MenuButtonProps} from '../menuButton'
16
-
17
- const POPOVER_PROPS: MenuButtonProps['popover'] = {
18
- constrainSize: true,
19
- placement: 'bottom',
20
- portal: true,
21
- // preventOverflow: true,
22
- // width: 1,
23
- }
15
+ import React, {useMemo, useState} from 'react'
24
16
 
25
17
  const items: {tone: SelectableTone; message: string}[] = [
26
18
  {
@@ -96,6 +88,17 @@ const items: {tone: SelectableTone; message: string}[] = [
96
88
  export default function ConstrainedInBoundaryStory() {
97
89
  const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
98
90
 
91
+ const popoverProps: PopoverProps = useMemo(
92
+ () => ({
93
+ constrainSize: true,
94
+ placement: 'bottom',
95
+ portal: true,
96
+ preventOverflow: true,
97
+ width: 1,
98
+ }),
99
+ []
100
+ )
101
+
99
102
  return (
100
103
  <Box height="fill" padding={[4, 5, 6]} sizing="border">
101
104
  <Card height="fill" shadow={1}>
@@ -126,7 +129,7 @@ export default function ConstrainedInBoundaryStory() {
126
129
  })}
127
130
  </Menu>
128
131
  }
129
- popover={POPOVER_PROPS}
132
+ popover={popoverProps}
130
133
  />
131
134
  </BoundaryElementProvider>
132
135
  </Box>
@@ -129,7 +129,7 @@ export default function GroupsStory() {
129
129
  />
130
130
  </Menu>
131
131
  }
132
- // popover={{constrainSize: true, portal: true, preventOverflow: true}}
132
+ popover={{constrainSize: true, portal: true, preventOverflow: true}}
133
133
  />
134
134
  </LayerProvider>
135
135
 
@@ -1,7 +1,6 @@
1
1
  import {ChevronRightIcon} from '@sanity/icons'
2
2
  import React, {createElement, isValidElement, useCallback, useEffect, useRef, useState} from 'react'
3
3
  import {isValidElementType} from 'react-is'
4
- import {useArrayProp} from '../../hooks'
5
4
  import {Box, Flex, Popover, PopoverProps, Text} from '../../primitives'
6
5
  import {Selectable} from '../../primitives/_selectable'
7
6
  import {SelectableTone} from '../../types/selectable'
@@ -37,7 +36,7 @@ export function MenuGroup(
37
36
  icon,
38
37
  onClick,
39
38
  padding = 3,
40
- popover,
39
+ popover = {},
41
40
  radius = 2,
42
41
  space = 3,
43
42
  text,
@@ -164,7 +163,7 @@ export function MenuGroup(
164
163
  aria-pressed={as === 'button' ? withinMenu : undefined}
165
164
  data-pressed={as !== 'button' ? withinMenu : undefined}
166
165
  data-selected={!withinMenu && active ? '' : undefined}
167
- $radius={useArrayProp(radius)}
166
+ $radius={radius}
168
167
  $tone={tone}
169
168
  onClick={handleClick}
170
169
  onKeyDown={handleKeyDown}
@@ -8,7 +8,7 @@ import React, {
8
8
  useState,
9
9
  } from 'react'
10
10
  import {isValidElementType} from 'react-is'
11
- import {useArrayProp, useForwardedRef} from '../../hooks'
11
+ import {useForwardedRef} from '../../hooks'
12
12
  import {Box, Flex, Text} from '../../primitives'
13
13
  import {Selectable} from '../../primitives/_selectable'
14
14
  import {ResponsivePaddingProps, ResponsiveRadiusProps} from '../../primitives/types'
@@ -118,13 +118,13 @@ export const MenuItem = forwardRef(function MenuItem(
118
118
  data-selected={active ? '' : undefined}
119
119
  data-disabled={disabled ? '' : undefined}
120
120
  forwardedAs={as}
121
- $radius={useArrayProp(radius)}
122
- $padding={useArrayProp(0)}
121
+ $radius={radius}
123
122
  $tone={tone}
124
123
  disabled={disabled}
125
124
  onClick={handleClick}
126
125
  onMouseEnter={onItemMouseEnter}
127
126
  onMouseLeave={onItemMouseLeave}
127
+ padding={0}
128
128
  ref={setRef}
129
129
  role="menuitem"
130
130
  tabIndex={-1}
@@ -1,6 +1,5 @@
1
1
  import React, {forwardRef, useEffect, useState} from 'react'
2
2
  import styled from 'styled-components'
3
- import {useArrayProp} from '../../hooks'
4
3
  import {Box} from '../../primitives'
5
4
  import {BoxProps, ResponsiveRadiusProps} from '../../primitives'
6
5
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
@@ -45,13 +44,5 @@ export const Skeleton = forwardRef(function Skeleton(
45
44
  }
46
45
  }, [delay])
47
46
 
48
- return (
49
- <Root
50
- {...restProps}
51
- $animated={animated}
52
- $radius={useArrayProp(radius)}
53
- $visible={visible}
54
- ref={ref}
55
- />
56
- )
47
+ return <Root {...restProps} $animated={animated} $radius={radius} $visible={visible} ref={ref} />
57
48
  })
@@ -1,7 +1,7 @@
1
1
  import React, {forwardRef} from 'react'
2
2
  import styled from 'styled-components'
3
- import {useArrayProp} from '../../hooks'
4
- import {_responsive} from '../../styles'
3
+ import {useResponsiveProp} from '../../hooks'
4
+ import {responsive} from '../../styles'
5
5
  import {Theme, ThemeFontKey} from '../../theme'
6
6
  import {Skeleton, SkeletonProps} from './skeleton'
7
7
 
@@ -10,7 +10,7 @@ const Root = styled(Skeleton)<{$size: number[]; $style: ThemeFontKey}>(
10
10
  const {media} = theme.sanity
11
11
  const font = theme.sanity.fonts[$style]
12
12
 
13
- const styles = _responsive(media, $size, (sizeIndex) => {
13
+ const styles = responsive(media, $size, (sizeIndex) => {
14
14
  const fontSize = font.sizes[sizeIndex]
15
15
  const capHeight = fontSize.lineHeight - fontSize.ascenderHeight - fontSize.descenderHeight
16
16
 
@@ -63,7 +63,7 @@ export const TextSkeleton = forwardRef(function TextSkeleton(
63
63
  ref: React.Ref<HTMLDivElement>
64
64
  ) {
65
65
  const {size = 2, ...restProps} = props
66
- const $size = useArrayProp(size)
66
+ const $size = useResponsiveProp(size)
67
67
 
68
68
  return <Root {...restProps} $size={$size} ref={ref} $style="text" />
69
69
  })
@@ -78,7 +78,7 @@ export const LabelSkeleton = forwardRef(function TextSkeleton(
78
78
  ref: React.Ref<HTMLDivElement>
79
79
  ) {
80
80
  const {size = 2, ...restProps} = props
81
- const $size = useArrayProp(size)
81
+ const $size = useResponsiveProp(size)
82
82
 
83
83
  return <Root {...restProps} $size={$size} ref={ref} $style="label" />
84
84
  })
@@ -93,7 +93,7 @@ export const HeadingSkeleton = forwardRef(function TextSkeleton(
93
93
  ref: React.Ref<HTMLDivElement>
94
94
  ) {
95
95
  const {size = 2, ...restProps} = props
96
- const $size = useArrayProp(size)
96
+ const $size = useResponsiveProp(size)
97
97
 
98
98
  return <Root {...restProps} $size={$size} ref={ref} $style="heading" />
99
99
  })
@@ -108,7 +108,7 @@ export const CodeSkeleton = forwardRef(function TextSkeleton(
108
108
  ref: React.Ref<HTMLDivElement>
109
109
  ) {
110
110
  const {size = 2, ...restProps} = props
111
- const $size = useArrayProp(size)
111
+ const $size = useResponsiveProp(size)
112
112
 
113
113
  return <Root {...restProps} $size={$size} ref={ref} $style="code" />
114
114
  })
@@ -1,9 +1,8 @@
1
- export * from './useArrayProp'
2
1
  export * from './useClickOutside'
3
2
  export * from './useElementRect'
4
- export * from './useElementSize'
5
3
  export * from './useGlobalKeyDown'
6
4
  export * from './useMediaIndex'
7
5
  export * from './usePrefersDark'
8
6
  export * from './useForwardedRef'
9
7
  export * from './useCustomValidity'
8
+ export * from './useResponsiveProp'
@@ -1,11 +1,23 @@
1
- import {useElementSize} from '../useElementSize'
1
+ import {useEffect, useState} from 'react'
2
2
 
3
3
  /**
4
4
  * Subscribe to the rect of a DOM element.
5
- * @deprecated Use `useElementSize` instead
5
+ * @beta
6
6
  */
7
7
  export function useElementRect(element: HTMLElement | null): DOMRectReadOnly | null {
8
- const elementSize = useElementSize(element)
8
+ const [rect, setRect] = useState<DOMRectReadOnly | null>(null)
9
9
 
10
- return elementSize?._contentRect || null
10
+ useEffect(() => {
11
+ if (!element) return undefined
12
+
13
+ const ro = new ResizeObserver((entries) => {
14
+ setRect(entries[0].contentRect)
15
+ })
16
+
17
+ ro.observe(element)
18
+
19
+ return () => ro.disconnect()
20
+ }, [element])
21
+
22
+ return rect
11
23
  }
@@ -0,0 +1,10 @@
1
+ import {useMemo} from 'react'
2
+ import {getResponsiveProp} from '../styles'
3
+
4
+ /**
5
+ * This API might change. DO NOT USE IN PRODUCTION.
6
+ * @beta
7
+ */
8
+ export function useResponsiveProp<T = number>(val: T | T[] | undefined, defaultVal?: T[]): T[] {
9
+ return useMemo(() => getResponsiveProp(val, defaultVal), [defaultVal, val])
10
+ }
package/src/index.ts CHANGED
@@ -2,7 +2,6 @@ export * from './primitives'
2
2
  export * from './components'
3
3
  export * from './helpers'
4
4
  export * from './hooks'
5
- export * from './observers'
6
5
  export * from './styles'
7
6
  export * from './theme'
8
7
  export * from './types'
@@ -1,4 +1,5 @@
1
1
  import styled from 'styled-components'
2
+ import {responsiveBorderStyle, ResponsiveBorderStyleProps} from '../../styles/border'
2
3
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/radius'
3
4
  import {Box} from '../box'
4
5
  import {selectableBaseStyle, selectableColorStyle, SelectableStyleProps} from './style'
@@ -6,8 +7,6 @@ import {selectableBaseStyle, selectableColorStyle, SelectableStyleProps} from '.
6
7
  /**
7
8
  * @internal
8
9
  */
9
- export const Selectable = styled(Box)<SelectableStyleProps & ResponsiveRadiusStyleProps>(
10
- responsiveRadiusStyle,
11
- selectableBaseStyle,
12
- selectableColorStyle
13
- )
10
+ export const Selectable = styled(Box)<
11
+ SelectableStyleProps & ResponsiveRadiusStyleProps & ResponsiveBorderStyleProps
12
+ >(responsiveBorderStyle, responsiveRadiusStyle, selectableBaseStyle, selectableColorStyle)