@sanity/ui 2.8.24-canary.2 → 2.8.25

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 (45) hide show
  1. package/dist/index.d.mts +2 -11
  2. package/dist/index.d.ts +2 -11
  3. package/dist/index.esm.js +2149 -2162
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +2148 -2161
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +2149 -2162
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +54 -46
  10. package/src/core/components/autocomplete/autocomplete.tsx +1 -1
  11. package/src/core/components/breadcrumbs/breadcrumbs.tsx +1 -2
  12. package/src/core/components/dialog/dialog.tsx +6 -2
  13. package/src/core/components/hotkeys/hotkeys.tsx +1 -1
  14. package/src/core/components/menu/menuGroup.tsx +1 -1
  15. package/src/core/components/menu/menuItem.tsx +1 -1
  16. package/src/core/components/skeleton/skeleton.tsx +1 -1
  17. package/src/core/components/skeleton/textSkeleton.tsx +1 -1
  18. package/src/core/hooks/index.ts +1 -1
  19. package/src/core/hooks/useArrayProp.ts +6 -8
  20. package/src/core/primitives/avatar/avatar.tsx +1 -1
  21. package/src/core/primitives/avatar/avatarCounter.tsx +1 -1
  22. package/src/core/primitives/avatar/avatarStack.tsx +1 -1
  23. package/src/core/primitives/badge/badge.tsx +1 -1
  24. package/src/core/primitives/box/box.tsx +1 -1
  25. package/src/core/primitives/button/button.tsx +1 -1
  26. package/src/core/primitives/card/card.tsx +1 -1
  27. package/src/core/primitives/code/code.tsx +1 -1
  28. package/src/core/primitives/container/container.tsx +1 -1
  29. package/src/core/primitives/flex/flex.tsx +1 -1
  30. package/src/core/primitives/grid/grid.tsx +1 -1
  31. package/src/core/primitives/heading/heading.tsx +1 -1
  32. package/src/core/primitives/inline/inline.tsx +1 -1
  33. package/src/core/primitives/kbd/kbd.tsx +1 -1
  34. package/src/core/primitives/label/label.tsx +1 -1
  35. package/src/core/primitives/popover/popover.tsx +1 -2
  36. package/src/core/primitives/select/select.tsx +1 -2
  37. package/src/core/primitives/stack/stack.tsx +1 -1
  38. package/src/core/primitives/text/text.tsx +1 -1
  39. package/src/core/primitives/textArea/textArea.tsx +1 -2
  40. package/src/core/primitives/textInput/textInput.tsx +1 -2
  41. package/src/core/primitives/tooltip/tooltip.tsx +1 -2
  42. package/src/core/styles/helpers.ts +2 -2
  43. package/src/core/utils/layer/layerProvider.tsx +1 -2
  44. package/src/core/utils/portal/portalProvider.tsx +8 -10
  45. package/src/core/hooks/useArrayPropLegacy.ts +0 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.8.24-canary.2",
3
+ "version": "2.8.25",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -51,6 +51,32 @@
51
51
  "src",
52
52
  "theme.js"
53
53
  ],
54
+ "scripts": {
55
+ "build": "run-s clean pkg:build pkg:check figma:pkg:build",
56
+ "clean": "rimraf .workshop dist",
57
+ "commit": "cz",
58
+ "cypress:dev": "run-p dev cypress:open",
59
+ "cypress:open": "cypress open",
60
+ "cypress:run": "cypress run",
61
+ "dev": "run-p storybook:dev workshop:dev",
62
+ "figma:pkg:build": "cd figma && pnpm build",
63
+ "format": "prettier --write --cache --ignore-unknown .",
64
+ "lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
65
+ "pkg:build": "pkg build --strict",
66
+ "pkg:check": "pkg --strict",
67
+ "prepare": "husky install",
68
+ "prepack": "pnpm build",
69
+ "release": "semantic-release",
70
+ "storybook:build": "storybook build",
71
+ "storybook:dev": "storybook dev -p 6006",
72
+ "test": "jest",
73
+ "test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
74
+ "ts:check": "tsc",
75
+ "watch": "pkg watch --strict",
76
+ "workshop:build": "workshop build",
77
+ "workshop:dev": "workshop dev",
78
+ "workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
79
+ },
54
80
  "commitlint": {
55
81
  "extends": [
56
82
  "@commitlint/config-conventional"
@@ -84,7 +110,7 @@
84
110
  "@sanity/icons": "^3.4.0",
85
111
  "csstype": "^3.1.3",
86
112
  "framer-motion": "11.0.8",
87
- "react-compiler-runtime": "19.0.0-beta-a7bf2bd-20241110",
113
+ "react-compiler-runtime": "19.0.0-beta-df7b47d-20241124",
88
114
  "react-refractor": "^2.2.0",
89
115
  "use-effect-event": "^1.0.2"
90
116
  },
@@ -96,24 +122,24 @@
96
122
  "@commitlint/cli": "^19.4.0",
97
123
  "@commitlint/config-conventional": "^19.2.2",
98
124
  "@juggle/resize-observer": "^3.4.0",
99
- "@sanity/pkg-utils": "^6.11.10",
125
+ "@sanity/pkg-utils": "^6.11.11",
100
126
  "@sanity/prettier-config": "^1.0.3",
101
127
  "@sanity/semantic-release-preset": "^5.0.0",
102
128
  "@sanity/ui-workshop": "^2.0.16",
103
- "@storybook/addon-a11y": "^8.4.2",
104
- "@storybook/addon-docs": "^8.4.2",
105
- "@storybook/addon-essentials": "^8.4.2",
106
- "@storybook/addon-interactions": "^8.4.2",
107
- "@storybook/addon-links": "^8.4.2",
108
- "@storybook/addon-mdx-gfm": "^8.4.2",
109
- "@storybook/addon-storysource": "^8.4.2",
110
- "@storybook/addon-themes": "^8.4.2",
111
- "@storybook/blocks": "^8.4.2",
112
- "@storybook/manager-api": "^8.4.2",
113
- "@storybook/react": "^8.4.2",
114
- "@storybook/react-vite": "^8.4.2",
115
- "@storybook/test": "^8.4.2",
116
- "@storybook/theming": "^8.4.2",
129
+ "@storybook/addon-a11y": "^8.4.5",
130
+ "@storybook/addon-docs": "^8.4.5",
131
+ "@storybook/addon-essentials": "^8.4.5",
132
+ "@storybook/addon-interactions": "^8.4.5",
133
+ "@storybook/addon-links": "^8.4.5",
134
+ "@storybook/addon-mdx-gfm": "^8.4.5",
135
+ "@storybook/addon-storysource": "^8.4.5",
136
+ "@storybook/addon-themes": "^8.4.5",
137
+ "@storybook/blocks": "^8.4.5",
138
+ "@storybook/manager-api": "^8.4.5",
139
+ "@storybook/react": "^8.4.5",
140
+ "@storybook/react-vite": "^8.4.5",
141
+ "@storybook/test": "^8.4.5",
142
+ "@storybook/theming": "^8.4.5",
117
143
  "@testing-library/dom": "^10.4.0",
118
144
  "@testing-library/jest-dom": "^6.6.2",
119
145
  "@testing-library/react": "^16.0.1",
@@ -128,7 +154,7 @@
128
154
  "@typescript-eslint/eslint-plugin": "^7.18.0",
129
155
  "@typescript-eslint/parser": "^7.18.0",
130
156
  "@vitejs/plugin-react": "^4.3.3",
131
- "babel-plugin-react-compiler": "19.0.0-beta-a7bf2bd-20241110",
157
+ "babel-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
132
158
  "commitizen": "^4.3.0",
133
159
  "cypress": "^13.13.2",
134
160
  "cypress-real-events": "^1.13.0",
@@ -140,7 +166,7 @@
140
166
  "eslint-plugin-jsx-a11y": "^6.10.2",
141
167
  "eslint-plugin-prettier": "^5.2.1",
142
168
  "eslint-plugin-react": "^7.37.2",
143
- "eslint-plugin-react-compiler": "19.0.0-beta-a7bf2bd-20241110",
169
+ "eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
144
170
  "eslint-plugin-react-hooks": "^5.0.0",
145
171
  "eslint-plugin-storybook": "^0.11.0",
146
172
  "http-server": "^14.1.1",
@@ -159,11 +185,11 @@
159
185
  "rimraf": "^5.0.5",
160
186
  "semantic-release": "^24.0.0",
161
187
  "start-server-and-test": "^2.0.5",
162
- "storybook": "^8.4.2",
188
+ "storybook": "^8.4.5",
163
189
  "styled-components": "^6.1.13",
164
190
  "tsconfig-paths": "^4.2.0",
165
191
  "typescript": "5.6.3",
166
- "vite": "^5.4.10",
192
+ "vite": "^5.4.11",
167
193
  "vite-tsconfig-paths": "^5.0.1"
168
194
  },
169
195
  "peerDependencies": {
@@ -172,37 +198,19 @@
172
198
  "react-is": "^18 || >=19.0.0-0",
173
199
  "styled-components": "^5.2 || ^6"
174
200
  },
201
+ "packageManager": "pnpm@9.12.3",
175
202
  "engines": {
176
203
  "node": ">=14.0.0"
177
204
  },
178
205
  "publishConfig": {
179
206
  "access": "public"
180
207
  },
208
+ "pnpm": {
209
+ "overrides": {
210
+ "conventional-changelog-conventionalcommits": ">= 8.0.0"
211
+ }
212
+ },
181
213
  "esm.sh": {
182
214
  "bundle": false
183
- },
184
- "scripts": {
185
- "build": "run-s clean pkg:build pkg:check figma:pkg:build",
186
- "clean": "rimraf .workshop dist",
187
- "commit": "cz",
188
- "cypress:dev": "run-p dev cypress:open",
189
- "cypress:open": "cypress open",
190
- "cypress:run": "cypress run",
191
- "dev": "run-p storybook:dev workshop:dev",
192
- "figma:pkg:build": "cd figma && pnpm build",
193
- "format": "prettier --write --cache --ignore-unknown .",
194
- "lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
195
- "pkg:build": "pkg build --strict",
196
- "pkg:check": "pkg --strict",
197
- "release": "semantic-release",
198
- "storybook:build": "storybook build",
199
- "storybook:dev": "storybook dev -p 6006",
200
- "test": "jest",
201
- "test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
202
- "ts:check": "tsc",
203
- "watch": "pkg watch --strict",
204
- "workshop:build": "workshop build",
205
- "workshop:dev": "workshop dev",
206
- "workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
207
215
  }
208
- }
216
+ }
@@ -20,7 +20,7 @@ import {
20
20
  } from 'react'
21
21
  import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
22
22
  import {_hasFocus, _raf, focusFirstDescendant} from '../../helpers'
23
- import {useArrayProp} from '../../hooks/useArrayProp'
23
+ import {useArrayProp} from '../../hooks'
24
24
  import {
25
25
  Box,
26
26
  BoxProps,
@@ -8,8 +8,7 @@ import {
8
8
  useRef,
9
9
  useState,
10
10
  } from 'react'
11
- import {useClickOutsideEvent} from '../../hooks'
12
- import {useArrayProp} from '../../hooks/useArrayProp'
11
+ import {useArrayProp, useClickOutsideEvent} from '../../hooks'
13
12
  import {Box, Popover, Stack, Text} from '../../primitives'
14
13
  import {ExpandButton, Root} from './breadcrumbs.styles'
15
14
 
@@ -8,8 +8,12 @@ import {
8
8
  focusLastDescendant,
9
9
  isHTMLElement,
10
10
  } from '../../helpers'
11
- import {useClickOutsideEvent, useGlobalKeyDown, usePrefersReducedMotion} from '../../hooks'
12
- import {useArrayProp} from '../../hooks/useArrayProp'
11
+ import {
12
+ useArrayProp,
13
+ useClickOutsideEvent,
14
+ useGlobalKeyDown,
15
+ usePrefersReducedMotion,
16
+ } from '../../hooks'
13
17
  import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
14
18
  import {ResponsivePaddingProps, ResponsiveWidthProps} from '../../primitives/types'
15
19
  import {responsivePaddingStyle, ResponsivePaddingStyleProps} from '../../styles/internal'
@@ -1,6 +1,6 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {Inline, KBD} from '../../primitives'
5
5
  import {Radius} from '../../types'
6
6
 
@@ -1,7 +1,7 @@
1
1
  import {ChevronRightIcon} from '@sanity/icons'
2
2
  import {isValidElement, useCallback, useEffect, useState} from 'react'
3
3
  import {isValidElementType} from 'react-is'
4
- import {useArrayProp} from '../../hooks/useArrayProp'
4
+ import {useArrayProp} from '../../hooks'
5
5
  import {Box, Flex, Popover, PopoverProps, Text} from '../../primitives'
6
6
  import {Selectable} from '../../primitives/_selectable'
7
7
  import {useRootTheme} from '../../theme'
@@ -9,7 +9,7 @@ import {
9
9
  useState,
10
10
  } from 'react'
11
11
  import {isValidElementType} from 'react-is'
12
- import {useArrayProp} from '../../hooks/useArrayProp'
12
+ import {useArrayProp} from '../../hooks'
13
13
  import {Box, Flex, Text} from '../../primitives'
14
14
  import {Selectable} from '../../primitives/_selectable'
15
15
  import {ResponsivePaddingProps, ResponsiveRadiusProps} from '../../primitives/types'
@@ -1,6 +1,6 @@
1
1
  import {forwardRef, useEffect, useState} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {Box} from '../../primitives'
5
5
  import {BoxProps, ResponsiveRadiusProps} from '../../primitives'
6
6
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
@@ -1,7 +1,7 @@
1
1
  import {ThemeFontKey, getTheme_v2} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {useArrayProp} from '../../hooks/useArrayProp'
4
+ import {useArrayProp} from '../../hooks'
5
5
  import {ThemeProps, _responsive} from '../../styles'
6
6
  import {Skeleton, SkeletonProps} from './skeleton'
7
7
 
@@ -1,4 +1,4 @@
1
- export * from './useArrayPropLegacy'
1
+ export * from './useArrayProp'
2
2
  export * from './useClickOutside'
3
3
  export * from './useClickOutsideEvent'
4
4
  export * from './useCustomValidity'
@@ -10,23 +10,21 @@ export type ArrayPropPrimitive = string | number | boolean | undefined | null
10
10
  */
11
11
  export function useArrayProp<T extends ArrayPropPrimitive = ArrayPropPrimitive>(
12
12
  val: T | T[] | undefined,
13
+ defaultVal?: T[],
13
14
  ): T[] {
14
15
  const [[cachedVal, cachedHash], setCache] = useState<[T[], string]>(() => [
15
- _getArrayProp(val),
16
- JSON.stringify(val),
16
+ _getArrayProp(val, defaultVal),
17
+ JSON.stringify(val ?? defaultVal),
17
18
  ])
18
- let result = cachedVal
19
19
 
20
- const hash = JSON.stringify(val)
20
+ const hash = JSON.stringify(val ?? defaultVal)
21
21
 
22
22
  if (hash !== cachedHash) {
23
- const current = _getArrayProp(val)
24
23
  // If the cached hash has changed, update the cache right away.
25
24
  // Calling setState during render is fine in this case, and preferred over a useEffect loop
26
25
  // https://19.react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
27
- setCache([current, hash])
28
- result = current
26
+ setCache([_getArrayProp(val, defaultVal), hash])
29
27
  }
30
28
 
31
- return result
29
+ return cachedVal
32
30
  }
@@ -2,7 +2,7 @@ import {ThemeColorAvatarColorKey} from '@sanity/ui/theme'
2
2
  import {forwardRef, useCallback, useEffect, useId, useMemo, useState} from 'react'
3
3
  import ReactIs from 'react-is'
4
4
  import {styled} from 'styled-components'
5
- import {useArrayProp} from '../../hooks/useArrayProp'
5
+ import {useArrayProp} from '../../hooks'
6
6
  import {useTheme_v2} from '../../theme'
7
7
  import {AvatarPosition, AvatarSize, AvatarStatus} from '../../types'
8
8
  import {Label} from '../label'
@@ -2,7 +2,7 @@ import {getTheme_v2} from '@sanity/ui/theme'
2
2
  import {forwardRef, useMemo} from 'react'
3
3
  import {styled, css} from 'styled-components'
4
4
  import {EMPTY_RECORD} from '../../constants'
5
- import {useArrayProp} from '../../hooks/useArrayProp'
5
+ import {useArrayProp} from '../../hooks'
6
6
  import {rem, _responsive, ThemeProps} from '../../styles'
7
7
  import {AvatarSize} from '../../types'
8
8
  import {Label} from '../label'
@@ -2,7 +2,7 @@ import {getTheme_v2} from '@sanity/ui/theme'
2
2
  import {Children, cloneElement, forwardRef, isValidElement} from 'react'
3
3
  import {styled, css} from 'styled-components'
4
4
  import {EMPTY_RECORD} from '../../constants'
5
- import {useArrayProp} from '../../hooks/useArrayProp'
5
+ import {useArrayProp} from '../../hooks'
6
6
  import {rem, _responsive, ThemeProps} from '../../styles'
7
7
  import {AvatarSize} from '../../types'
8
8
  import {AvatarCounter} from './avatarCounter'
@@ -1,6 +1,6 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
5
5
  import {BadgeMode, BadgeTone} from '../../types'
6
6
  import {Box, BoxProps} from '../box'
@@ -1,6 +1,6 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {
5
5
  boxStyle,
6
6
  flexItemStyle,
@@ -1,7 +1,7 @@
1
1
  import {forwardRef, isValidElement, useMemo} from 'react'
2
2
  import {isValidElementType} from 'react-is'
3
3
  import {styled} from 'styled-components'
4
- import {useArrayProp} from '../../hooks/useArrayProp'
4
+ import {useArrayProp} from '../../hooks'
5
5
  import {ThemeProps} from '../../styles'
6
6
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
7
7
  import {useTheme_v2} from '../../theme'
@@ -2,7 +2,7 @@ import {ThemeColorSchemeKey} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {isValidElementType} from 'react-is'
4
4
  import {styled} from 'styled-components'
5
- import {useArrayProp} from '../../hooks/useArrayProp'
5
+ import {useArrayProp} from '../../hooks'
6
6
  import {
7
7
  responsiveBorderStyle,
8
8
  ResponsiveBorderStyleProps,
@@ -2,7 +2,7 @@
2
2
  import {forwardRef} from 'react'
3
3
  import Refractor from 'react-refractor'
4
4
  import {styled} from 'styled-components'
5
- import {useArrayProp} from '../../hooks/useArrayProp'
5
+ import {useArrayProp} from '../../hooks'
6
6
  import {responsiveCodeFontStyle, ResponsiveFontStyleProps} from '../../styles/internal'
7
7
  import {codeBaseStyle} from './styles'
8
8
 
@@ -1,6 +1,6 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {Box, BoxProps} from '../box'
5
5
  import {ResponsiveWidthProps} from '../types'
6
6
  import {containerBaseStyle, responsiveContainerWidthStyle} from './styles'
@@ -1,6 +1,6 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {
5
5
  flexItemStyle,
6
6
  FlexItemStyleProps,
@@ -1,6 +1,6 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {responsiveGridStyle, ResponsiveGridStyleProps} from '../../styles/internal'
5
5
  import {Box, BoxProps} from '../box'
6
6
  import {ResponsiveGridProps} from '../types'
@@ -1,7 +1,7 @@
1
1
  import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {useArrayProp} from '../../hooks/useArrayProp'
4
+ import {useArrayProp} from '../../hooks'
5
5
  import {
6
6
  ResponsiveFontStyleProps,
7
7
  responsiveHeadingFont,
@@ -1,6 +1,6 @@
1
1
  import {forwardRef, useMemo, Children} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {Box, BoxProps} from '../box'
5
5
  import {inlineBaseStyle, inlineSpaceStyle} from './styles'
6
6
  import {ResponsiveInlineSpaceStyleProps} from './types'
@@ -1,6 +1,6 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled, css} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
5
5
  import {Radius} from '../../types'
6
6
  import {Box} from '../box'
@@ -1,7 +1,7 @@
1
1
  import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {useArrayProp} from '../../hooks/useArrayProp'
4
+ import {useArrayProp} from '../../hooks'
5
5
  import {responsiveLabelFont, responsiveTextAlignStyle} from '../../styles/internal'
6
6
  import {TextAlign} from '../../types'
7
7
  import {labelBaseStyle} from './styles'
@@ -24,8 +24,7 @@ import {
24
24
  useMemo,
25
25
  useRef,
26
26
  } from 'react'
27
- import {useElementSize, useMediaIndex, usePrefersReducedMotion} from '../../hooks'
28
- import {useArrayProp} from '../../hooks/useArrayProp'
27
+ import {useArrayProp, useElementSize, useMediaIndex, usePrefersReducedMotion} from '../../hooks'
29
28
  import {origin} from '../../middleware/origin'
30
29
  import {useTheme_v2} from '../../theme'
31
30
  import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
@@ -1,8 +1,7 @@
1
1
  import {ChevronDownIcon} from '@sanity/icons'
2
2
  import {forwardRef, useImperativeHandle, useRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {useCustomValidity} from '../../hooks'
5
- import {useArrayProp} from '../../hooks/useArrayProp'
4
+ import {useCustomValidity, useArrayProp} from '../../hooks'
6
5
  import {Radius} from '../../types'
7
6
  import {Box} from '../box'
8
7
  import {Text} from '../text'
@@ -1,6 +1,6 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
3
+ import {useArrayProp} from '../../hooks'
4
4
  import {Box, BoxProps} from '../box'
5
5
  import {stackBaseStyle, responsiveStackSpaceStyle, ResponsiveStackSpaceStyleProps} from './styles'
6
6
 
@@ -1,7 +1,7 @@
1
1
  import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {useArrayProp} from '../../hooks/useArrayProp'
4
+ import {useArrayProp} from '../../hooks'
5
5
  import {
6
6
  ResponsiveFontStyleProps,
7
7
  responsiveTextAlignStyle,
@@ -1,8 +1,7 @@
1
1
  import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef, useImperativeHandle, useRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
- import {useCustomValidity} from '../../hooks'
5
- import {useArrayProp} from '../../hooks/useArrayProp'
4
+ import {useCustomValidity, useArrayProp} from '../../hooks'
6
5
  import {
7
6
  responsiveInputPaddingStyle,
8
7
  responsiveRadiusStyle,
@@ -4,8 +4,7 @@ import {forwardRef, isValidElement, useCallback, useImperativeHandle, useMemo, u
4
4
  import {isValidElementType} from 'react-is'
5
5
  import {styled} from 'styled-components'
6
6
  import {EMPTY_RECORD} from '../../constants'
7
- import {useCustomValidity} from '../../hooks'
8
- import {useArrayProp} from '../../hooks/useArrayProp'
7
+ import {useArrayProp, useCustomValidity} from '../../hooks'
9
8
  import {
10
9
  responsiveRadiusStyle,
11
10
  ResponsiveRadiusStyleProps,
@@ -25,8 +25,7 @@ import {
25
25
  } from 'react'
26
26
  import {styled} from 'styled-components'
27
27
  import {useEffectEvent} from 'use-effect-event'
28
- import {usePrefersReducedMotion} from '../../hooks'
29
- import {useArrayProp} from '../../hooks/useArrayProp'
28
+ import {useArrayProp, usePrefersReducedMotion} from '../../hooks'
30
29
  import {useDelayedState} from '../../hooks/useDelayedState'
31
30
  import {origin} from '../../middleware/origin'
32
31
  import {useTheme_v2} from '../../theme'
@@ -42,8 +42,8 @@ export function _responsive<T>(
42
42
  /**
43
43
  * @internal
44
44
  */
45
- export function _getArrayProp<T = number>(val: T | T[] | undefined): T[] {
46
- if (val === undefined) return EMPTY_ARRAY
45
+ export function _getArrayProp<T = number>(val: T | T[] | undefined, defaultVal?: T[]): T[] {
46
+ if (val === undefined) return defaultVal || EMPTY_ARRAY
47
47
 
48
48
  return Array.isArray(val) ? val : [val]
49
49
  }
@@ -1,6 +1,5 @@
1
1
  import {useCallback, useContext, useEffect, useMemo, useState} from 'react'
2
- import {useMediaIndex} from '../../hooks'
3
- import {useArrayProp} from '../../hooks/useArrayProp'
2
+ import {useMediaIndex, useArrayProp} from '../../hooks'
4
3
  import {getLayerContext} from './getLayerContext'
5
4
  import {LayerContext} from './layerContext'
6
5
  import {LayerContextValue} from './types'
@@ -1,4 +1,4 @@
1
- import {useMemo, useState, useSyncExternalStore} from 'react'
1
+ import {useMemo, useRef, useSyncExternalStore} from 'react'
2
2
  import {PortalContext} from './portalContext'
3
3
  import {PortalContextValue} from './types'
4
4
 
@@ -22,8 +22,8 @@ export interface PortalProviderProps {
22
22
  * @public
23
23
  */
24
24
  export function PortalProvider(props: PortalProviderProps): React.ReactElement {
25
- const {boundaryElement, children, element} = props
26
- const elements = useUnique(props.__unstable_elements)
25
+ const {boundaryElement, children, element, __unstable_elements: elementsProp} = props
26
+ const elements = useUnique(elementsProp)
27
27
  const fallbackElement = useSyncExternalStore(
28
28
  emptySubscribe,
29
29
  () => document.body,
@@ -51,18 +51,16 @@ const emptySubscribe = () => () => {}
51
51
  * equality comparison (eg by identity), and only goes one level deep.
52
52
  */
53
53
  function useUnique<ValueType extends Comparable = Comparable>(value: ValueType): ValueType {
54
- const [cachedValue, setCachedValue] = useState(value)
55
- let result = cachedValue
54
+ const valueRef = useRef<ValueType>(value)
56
55
 
57
- if (!isEqual(cachedValue, value)) {
58
- setCachedValue(value)
59
- result = value
56
+ if (!_isEqual(valueRef.current, value)) {
57
+ valueRef.current = value
60
58
  }
61
59
 
62
- return result
60
+ return valueRef.current
63
61
  }
64
62
 
65
- function isEqual(objA: Comparable, objB: Comparable): boolean {
63
+ function _isEqual(objA: Comparable, objB: Comparable): boolean {
66
64
  if (!objA || !objB) {
67
65
  return objA === objB
68
66
  }
@@ -1,30 +0,0 @@
1
- import {useArrayProp as useArrayPropHook, type ArrayPropPrimitive} from './useArrayProp'
2
-
3
- export type {ArrayPropPrimitive}
4
-
5
- /**
6
- * This API might change. DO NOT USE IN PRODUCTION.
7
- * @beta
8
- */
9
- export function useArrayProp<T extends ArrayPropPrimitive = ArrayPropPrimitive>(
10
- val: T | T[] | undefined,
11
- ): T[]
12
- /**
13
- * This API might change. DO NOT USE IN PRODUCTION.
14
- * @beta
15
- * @deprecated - use `useArrayProp(value ?? defaultValue)` instead of `useArrayProp(value, defaultValue)`
16
- */
17
- export function useArrayProp<T extends ArrayPropPrimitive = ArrayPropPrimitive>(
18
- val: T | T[] | undefined,
19
- defaultVal: T[],
20
- ): T[]
21
- /**
22
- * This API might change. DO NOT USE IN PRODUCTION.
23
- * @beta
24
- */
25
- export function useArrayProp<T extends ArrayPropPrimitive = ArrayPropPrimitive>(
26
- val: T | T[] | undefined,
27
- defaultVal?: T[],
28
- ): T[] {
29
- return useArrayPropHook(val ?? defaultVal)
30
- }