@sanity/ui 1.0.0-next.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -2
  3. package/dist/{types/src/index.d.ts → index.d.ts} +4450 -4398
  4. package/dist/{sanity-ui.esm.js → index.esm.js} +888 -2678
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/{sanity-ui.js → index.js} +882 -2688
  7. package/dist/index.js.map +1 -0
  8. package/package.json +112 -23
  9. package/src/components/autocomplete/__workshop__/example.tsx +1 -1
  10. package/src/components/autocomplete/__workshop__/index.ts +36 -32
  11. package/src/components/autocomplete/autocomplete.styles.tsx +22 -28
  12. package/src/components/autocomplete/autocomplete.tsx +1 -2
  13. package/src/components/autocomplete/constants.ts +3 -8
  14. package/src/components/breadcrumbs/__workshop__/index.ts +11 -7
  15. package/src/components/breadcrumbs/breadcrumbs.styles.ts +13 -18
  16. package/src/components/dialog/__workshop__/index.ts +13 -9
  17. package/src/components/dialog/dialog.tsx +53 -67
  18. package/src/components/hotkeys/__workshop__/index.ts +11 -3
  19. package/src/components/hotkeys/hotkeys.tsx +12 -16
  20. package/src/components/menu/__workshop__/index.ts +71 -67
  21. package/src/components/menu/menu.tsx +5 -7
  22. package/src/components/menu/menuButton.tsx +16 -14
  23. package/src/components/menu/menuDivider.ts +8 -10
  24. package/src/components/skeleton/__workshop__/index.ts +8 -4
  25. package/src/components/skeleton/skeleton.tsx +4 -6
  26. package/src/components/skeleton/styles.ts +13 -9
  27. package/src/components/skeleton/textSkeleton.tsx +12 -14
  28. package/src/components/tab/__workshop__/index.ts +11 -3
  29. package/src/components/toast/__workshop__/index.ts +16 -4
  30. package/src/components/toast/toast.tsx +6 -11
  31. package/src/components/toast/toastProvider.tsx +18 -22
  32. package/src/components/tree/__workshop__/basic.perf.ts +1 -14
  33. package/src/components/tree/__workshop__/basic.tsx +1 -1
  34. package/src/components/tree/__workshop__/index.ts +12 -8
  35. package/src/components/tree/style.ts +78 -76
  36. package/src/components/tree/treeItem.tsx +7 -12
  37. package/src/hooks/useElementRect/__workshop__/index.ts +11 -3
  38. package/src/hooks/useMediaIndex/__workshop__/index.ts +11 -3
  39. package/src/primitives/_selectable/selectable.tsx +4 -7
  40. package/src/primitives/_selectable/style.ts +85 -82
  41. package/src/primitives/avatar/__workshop__/index.ts +16 -12
  42. package/src/primitives/avatar/avatar.tsx +9 -12
  43. package/src/primitives/avatar/avatarCounter.tsx +22 -24
  44. package/src/primitives/avatar/avatarStack.tsx +16 -14
  45. package/src/primitives/avatar/styles.ts +1 -1
  46. package/src/primitives/badge/__workshop__/index.ts +16 -12
  47. package/src/primitives/badge/__workshop__/tones.tsx +1 -1
  48. package/src/primitives/badge/badge.tsx +6 -5
  49. package/src/primitives/box/__workshop__/index.ts +16 -4
  50. package/src/primitives/box/box.tsx +21 -49
  51. package/src/primitives/button/__workshop__/index.ts +51 -47
  52. package/src/primitives/button/__workshop__/sanityUploadButton.tsx +19 -20
  53. package/src/primitives/button/__workshop__/styled1.tsx +6 -6
  54. package/src/primitives/button/button.tsx +20 -26
  55. package/src/primitives/button/styles.ts +30 -29
  56. package/src/primitives/card/__workshop__/index.ts +15 -11
  57. package/src/primitives/card/card.tsx +9 -25
  58. package/src/primitives/card/styles.ts +119 -114
  59. package/src/primitives/checkbox/__workshop__/index.ts +10 -6
  60. package/src/primitives/checkbox/checkbox.tsx +4 -4
  61. package/src/primitives/checkbox/styles.ts +71 -69
  62. package/src/primitives/code/__workshop__/index.ts +16 -12
  63. package/src/primitives/code/code.tsx +3 -5
  64. package/src/primitives/code/styles.ts +20 -18
  65. package/src/primitives/container/__workshop__/index.ts +5 -3
  66. package/src/primitives/container/container.tsx +5 -4
  67. package/src/primitives/flex/__workshop__/index.ts +8 -4
  68. package/src/primitives/flex/flex.tsx +7 -23
  69. package/src/primitives/grid/__workshop__/index.ts +7 -3
  70. package/src/primitives/grid/grid.tsx +4 -27
  71. package/src/primitives/heading/__workshop__/index.ts +16 -12
  72. package/src/primitives/heading/heading.tsx +10 -17
  73. package/src/primitives/heading/styles.ts +45 -36
  74. package/src/primitives/inline/__workshop__/index.ts +5 -3
  75. package/src/primitives/inline/inline.tsx +3 -5
  76. package/src/primitives/kbd/__workshop__/index.ts +5 -3
  77. package/src/primitives/kbd/kbd.tsx +12 -13
  78. package/src/primitives/label/__workshop__/index.ts +16 -12
  79. package/src/primitives/label/label.tsx +13 -18
  80. package/src/primitives/label/styles.ts +24 -18
  81. package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -1
  82. package/src/primitives/popover/__workshop__/TestStory.tsx +0 -1
  83. package/src/primitives/popover/__workshop__/index.ts +36 -32
  84. package/src/primitives/popover/constants.ts +0 -3
  85. package/src/primitives/popover/floating-ui/size.ts +40 -25
  86. package/src/primitives/popover/popover.tsx +220 -196
  87. package/src/primitives/popover/popoverArrow.tsx +42 -48
  88. package/src/primitives/popover/popoverCard.tsx +12 -22
  89. package/src/primitives/radio/__workshop__/index.ts +8 -4
  90. package/src/primitives/radio/radio.tsx +3 -3
  91. package/src/primitives/radio/styles.ts +73 -73
  92. package/src/primitives/select/__workshop__/index.ts +8 -4
  93. package/src/primitives/select/select.tsx +9 -11
  94. package/src/primitives/select/styles.ts +77 -77
  95. package/src/primitives/spinner/__workshop__/index.ts +11 -7
  96. package/src/primitives/spinner/spinner.tsx +2 -5
  97. package/src/primitives/stack/__workshop__/index.ts +11 -7
  98. package/src/primitives/stack/stack.tsx +3 -5
  99. package/src/primitives/switch/__workshop__/index.ts +8 -4
  100. package/src/primitives/switch/styles.ts +119 -112
  101. package/src/primitives/switch/switch.tsx +6 -6
  102. package/src/primitives/text/__workshop__/index.ts +21 -17
  103. package/src/primitives/text/styles.ts +51 -45
  104. package/src/primitives/text/text.tsx +11 -16
  105. package/src/primitives/textArea/__workshop__/index.ts +11 -7
  106. package/src/primitives/textArea/textArea.tsx +15 -22
  107. package/src/primitives/textInput/__workshop__/index.ts +46 -42
  108. package/src/primitives/textInput/__workshop__/plain.tsx +2 -1
  109. package/src/primitives/textInput/textInput.tsx +49 -69
  110. package/src/primitives/tooltip/__workshop__/index.ts +11 -7
  111. package/src/primitives/tooltip/tooltip.tsx +3 -6
  112. package/src/primitives/tooltip/tooltipArrow.tsx +69 -59
  113. package/src/styles/border/borderStyle.ts +10 -18
  114. package/src/styles/box/boxStyle.ts +14 -18
  115. package/src/styles/flex/flexItemStyle.ts +7 -1
  116. package/src/styles/flex/flexStyle.ts +14 -9
  117. package/src/styles/grid/gridItemStyle.ts +18 -30
  118. package/src/styles/grid/gridStyle.ts +25 -33
  119. package/src/styles/helpers.ts +2 -2
  120. package/src/styles/index.ts +0 -1
  121. package/src/styles/input/textInputStyle.ts +127 -123
  122. package/src/styles/margin/marginStyle.ts +11 -10
  123. package/src/styles/margin/marginsStyle.test.ts +12 -10
  124. package/src/styles/padding/paddingStyle.test.ts +12 -10
  125. package/src/styles/padding/paddingStyle.ts +9 -10
  126. package/src/theme/__workshop__/index.ts +26 -22
  127. package/src/theme/{ThemeContext.ts → themeContext.ts} +0 -0
  128. package/src/utils/boundaryElement/__workshop__/index.ts +11 -7
  129. package/src/utils/elementQuery/__workshop__/index.ts +11 -7
  130. package/src/utils/layer/__workshop__/index.ts +21 -17
  131. package/src/utils/layer/layer.tsx +4 -6
  132. package/src/utils/portal/__workshop__/index.ts +11 -7
  133. package/src/utils/srOnly/srOnly.tsx +8 -10
  134. package/src/utils/virtualList/__workshop__/index.ts +26 -22
  135. package/src/utils/virtualList/virtualList.tsx +10 -14
  136. package/dist/sanity-ui.esm.js.map +0 -1
  137. package/dist/sanity-ui.js.map +0 -1
  138. package/src/__workshop__/color/overview.tsx +0 -101
  139. package/src/__workshop__/index.ts +0 -10
  140. package/src/icons/__workshop__/.eslintrc +0 -5
  141. package/src/icons/__workshop__/index.tsx +0 -6
  142. package/src/icons/__workshop__/overview.tsx +0 -76
  143. package/src/styles/compose.ts +0 -35
  144. package/src/utils/srOnly/__workshop__/.eslintrc +0 -5
@@ -1,25 +1,32 @@
1
- import {Middleware, detectOverflow} from '@floating-ui/react-dom'
1
+ import {Elements, Middleware, detectOverflow} from '@floating-ui/react-dom'
2
+ import {PopoverMargins} from '../../../types'
2
3
 
3
- export function size(scope: {
4
- boundaryElement: HTMLElement | null
4
+ export interface SizeMiddlewareApplyOptions {
5
+ availableWidth: number
6
+ availableHeight: number
7
+ elements: Elements
8
+ referenceWidth: number
9
+ }
10
+
11
+ export function size(options: {
12
+ apply: (args: SizeMiddlewareApplyOptions) => void
13
+ boundaryElement?: HTMLElement | null
5
14
  constrainSize: boolean
15
+ margins: PopoverMargins
6
16
  matchReferenceWidth?: boolean
7
17
  padding?: number
8
- setAvailableWidth: (v: number) => void
9
- setAvailableHeight: (v: number) => void
10
- setReferenceWidth: (v: number) => void
11
18
  }): Middleware {
12
- const {padding = 0} = scope
19
+ const {apply, margins, padding = 0} = options
13
20
 
14
21
  return {
15
22
  name: '@sanity/ui/size',
16
23
  async fn(args) {
17
- const {placement, rects} = args
24
+ const {elements, placement, platform, rects} = args
18
25
  const {floating, reference} = rects
19
26
 
20
27
  const overflow = await detectOverflow(args, {
21
28
  altBoundary: true,
22
- boundary: scope.boundaryElement || undefined,
29
+ boundary: options.boundaryElement || undefined,
23
30
  elementContext: 'floating',
24
31
  padding,
25
32
  rootBoundary: 'viewport',
@@ -28,36 +35,44 @@ export function size(scope: {
28
35
  let maxWidth = Infinity
29
36
  let maxHeight = Infinity
30
37
 
38
+ const floatingW = floating.width
39
+ const floatingH = floating.height
40
+
31
41
  if (placement.includes('top')) {
32
- maxWidth = floating.width - (overflow.left + overflow.right)
33
- maxHeight = floating.height - overflow.top - padding
42
+ maxWidth = floatingW - (overflow.left + overflow.right)
43
+ maxHeight = floatingH - overflow.top
34
44
  }
35
45
 
36
46
  if (placement.includes('right')) {
37
- maxWidth = floating.width - overflow.right - padding
38
- maxHeight = floating.height - (overflow.top + overflow.bottom)
47
+ maxWidth = floatingW - overflow.right
48
+ maxHeight = floatingH - (overflow.top + overflow.bottom)
39
49
  }
40
50
 
41
51
  if (placement.includes('bottom')) {
42
- maxWidth = floating.width - (overflow.left + overflow.right)
43
- maxHeight = floating.height - overflow.bottom - padding
52
+ maxWidth = floatingW - (overflow.left + overflow.right)
53
+ maxHeight = floatingH - overflow.bottom
44
54
  }
45
55
 
46
56
  if (placement.includes('left')) {
47
- maxWidth = floating.width - overflow.left - padding
48
- maxHeight = floating.height - (overflow.top + overflow.bottom)
57
+ maxWidth = floatingW - overflow.left
58
+ maxHeight = floatingH - (overflow.top + overflow.bottom)
49
59
  }
50
60
 
51
- if (scope.constrainSize) {
52
- scope.setAvailableWidth(maxWidth)
53
- scope.setAvailableHeight(maxHeight)
54
- }
61
+ // IMPORTANT – APPLY ELEMENT STYLES HERE
62
+ // Elements need to be resized BEFORE the `platform.getDimensions` call below
63
+ apply({
64
+ availableWidth: maxWidth - margins[1] - margins[3],
65
+ availableHeight: maxHeight - margins[0] - margins[2],
66
+ elements,
67
+ referenceWidth: reference.width - margins[1] - margins[3],
68
+ })
55
69
 
56
- if (scope.matchReferenceWidth) {
57
- scope.setReferenceWidth(reference.width)
58
- }
70
+ const nextDimensions = await platform.getDimensions(elements.floating)
71
+
72
+ const targetH = nextDimensions.height
73
+ const targetW = nextDimensions.width
59
74
 
60
- if (!floating.width || !floating.height) {
75
+ if (floatingW !== targetW || floatingH !== targetH) {
61
76
  return {reset: {rects: true}}
62
77
  }
63
78
 
@@ -8,14 +8,19 @@ import {
8
8
  offset,
9
9
  shift,
10
10
  useFloating,
11
+ UseFloatingProps,
11
12
  } from '@floating-ui/react-dom'
12
- import {cloneElement, forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react'
13
+ import {cloneElement, forwardRef, memo, useCallback, useEffect, useMemo, useRef} from 'react'
13
14
  import {useForwardedRef, useArrayProp, useElementSize} from '../../hooks'
14
15
  import {ThemeColorSchemeKey, useTheme} from '../../theme'
15
16
  import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
16
17
  import {LayerProps, LayerProvider, Portal, useBoundaryElement} from '../../utils'
17
18
  import {ResponsiveRadiusProps, ResponsiveShadowProps, ResponsiveWidthProps} from '../types'
18
- import {DEFAULT_POPOVER_DISTANCE, DEFAULT_POPOVER_PADDING} from './constants'
19
+ import {
20
+ DEFAULT_POPOVER_DISTANCE,
21
+ DEFAULT_POPOVER_MARGINS,
22
+ DEFAULT_POPOVER_PADDING,
23
+ } from './constants'
19
24
  import {size} from './floating-ui/size'
20
25
  import {PopoverCard} from './popoverCard'
21
26
 
@@ -51,231 +56,250 @@ export interface PopoverProps
51
56
  }
52
57
 
53
58
  /** @public */
54
- export const Popover = forwardRef(function Popover(
55
- props: PopoverProps &
56
- Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'children' | 'content' | 'width'>,
57
- ref: React.ForwardedRef<HTMLDivElement>
58
- ): React.ReactElement {
59
- const theme = useTheme()
60
- const boundaryElementContext = useBoundaryElement()
59
+ export const Popover = memo(
60
+ forwardRef(function Popover(
61
+ props: PopoverProps &
62
+ Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'children' | 'content' | 'width'>,
63
+ ref: React.ForwardedRef<HTMLDivElement>
64
+ ): React.ReactElement {
65
+ const theme = useTheme()
66
+ const boundaryElementContext = useBoundaryElement()
61
67
 
62
- const {
63
- __unstable_margins: margins,
64
- arrow: arrowProp = true,
65
- boundaryElement = boundaryElementContext.element,
66
- children: childProp,
67
- constrainSize = false,
68
- content,
69
- disabled,
70
- fallbackPlacements,
71
- matchReferenceWidth: matchReferenceWidthProp,
72
- open,
73
- overflow = props.constrainSize ? 'auto' : 'hidden',
74
- padding: paddingProp,
75
- placement: placementProp = 'bottom',
76
- portal,
77
- preventOverflow = true,
78
- radius: radiusProp = 3,
79
- referenceElement,
80
- scheme,
81
- shadow: shadowProp = 3,
82
- tone = 'inherit',
83
- width: widthProp = 'auto',
84
- zOffset: zOffsetProp = theme.sanity.layer?.popover.zOffset,
85
- ...restProps
86
- } = props
87
- const boundarySize = useElementSize(boundaryElement)?.border
88
- const padding = useArrayProp(paddingProp)
89
- const radius = useArrayProp(radiusProp)
90
- const shadow = useArrayProp(shadowProp)
91
- const width = useArrayProp(widthProp)
92
- const zOffset = useArrayProp(zOffsetProp)
93
- const [availableWidth, setAvailableWidth] = useState<number | undefined>(undefined)
94
- const [availableHeight, setAvailableHeight] = useState<number | undefined>(undefined)
95
- const [referenceWidth, setReferenceWidth] = useState<number | undefined>(undefined)
96
- const forwardedRef = useForwardedRef(ref)
97
- const arrowRef = useRef<HTMLDivElement | null>(null)
98
- const rootBoundary: RootBoundary = 'viewport'
68
+ const {
69
+ __unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
70
+ arrow: arrowProp = true,
71
+ boundaryElement = boundaryElementContext.element,
72
+ children: childProp,
73
+ constrainSize = false,
74
+ content,
75
+ disabled,
76
+ fallbackPlacements,
77
+ matchReferenceWidth: matchReferenceWidthProp,
78
+ open,
79
+ overflow = 'hidden',
80
+ padding: paddingProp,
81
+ placement: placementProp = 'bottom',
82
+ portal,
83
+ preventOverflow = true,
84
+ radius: radiusProp = 3,
85
+ referenceElement,
86
+ scheme,
87
+ shadow: shadowProp = 3,
88
+ tone = 'inherit',
89
+ width: widthProp = 'auto',
90
+ zOffset: zOffsetProp = theme.sanity.layer?.popover.zOffset,
91
+ ...restProps
92
+ } = props
93
+ const boundarySize = useElementSize(boundaryElement)?.border
94
+ const padding = useArrayProp(paddingProp)
95
+ const radius = useArrayProp(radiusProp)
96
+ const shadow = useArrayProp(shadowProp)
97
+ const width = useArrayProp(widthProp)
98
+ const zOffset = useArrayProp(zOffsetProp)
99
+ const forwardedRef = useForwardedRef(ref)
100
+ const arrowRef = useRef<HTMLDivElement | null>(null)
101
+ const rootBoundary: RootBoundary = 'viewport'
99
102
 
100
- const middleware = useMemo(() => {
101
- const ret: Middleware[] = []
103
+ const middleware = useMemo(() => {
104
+ const ret: Middleware[] = []
102
105
 
103
- // Flip the floating element when leaving the boundary box
104
- if (constrainSize || preventOverflow) {
105
- ret.push(
106
- flip({
107
- boundary: boundaryElement || undefined,
108
- fallbackPlacements,
109
- padding: DEFAULT_POPOVER_PADDING,
110
- rootBoundary,
111
- })
112
- )
113
- }
106
+ // Flip the floating element when leaving the boundary box
107
+ if (constrainSize || preventOverflow) {
108
+ ret.push(
109
+ flip({
110
+ boundary: boundaryElement || undefined,
111
+ fallbackPlacements,
112
+ padding: DEFAULT_POPOVER_PADDING,
113
+ rootBoundary,
114
+ })
115
+ )
116
+ }
114
117
 
115
- // Track sizes
116
- if (constrainSize || matchReferenceWidthProp) {
118
+ // Define distance between reference and floating element
117
119
  ret.push(
118
- size({
119
- boundaryElement,
120
- constrainSize,
121
- matchReferenceWidth: matchReferenceWidthProp,
122
- padding: DEFAULT_POPOVER_PADDING,
123
- setAvailableHeight,
124
- setAvailableWidth,
125
- setReferenceWidth,
120
+ offset({
121
+ mainAxis: arrowProp ? DEFAULT_POPOVER_DISTANCE : 0,
126
122
  })
127
123
  )
128
- }
129
124
 
130
- // Define distance between reference and floating element
131
- ret.push(
132
- offset({
133
- mainAxis: arrowProp ? DEFAULT_POPOVER_DISTANCE : 0,
134
- })
135
- )
125
+ // Track sizes
126
+ if (constrainSize || matchReferenceWidthProp) {
127
+ ret.push(
128
+ size({
129
+ apply({availableWidth, availableHeight, elements, referenceWidth}) {
130
+ if (matchReferenceWidthProp) {
131
+ elements.floating.style.width = `${referenceWidth}px`
132
+ }
133
+
134
+ if (constrainSize) {
135
+ elements.floating.style.maxWidth = `${availableWidth}px`
136
+ elements.floating.style.maxHeight = `${availableHeight}px`
137
+ }
138
+ },
139
+ boundaryElement,
140
+ constrainSize,
141
+ margins,
142
+ matchReferenceWidth: matchReferenceWidthProp,
143
+ padding: DEFAULT_POPOVER_PADDING,
144
+ })
145
+ )
146
+ }
147
+
148
+ // Shift the popover so its sits within the boundary eleement
149
+ if (preventOverflow) {
150
+ ret.push(
151
+ shift({
152
+ boundary: boundaryElement || undefined,
153
+ rootBoundary,
154
+ padding: DEFAULT_POPOVER_PADDING,
155
+ })
156
+ )
157
+ }
158
+
159
+ // Place arrow
160
+ if (arrowProp) {
161
+ ret.push(
162
+ arrow({
163
+ element: arrowRef,
164
+ padding: DEFAULT_POPOVER_PADDING,
165
+ })
166
+ )
167
+ }
136
168
 
137
- // Shift the popover so its sits with the boundary eleement
138
- if (preventOverflow) {
139
169
  ret.push(
140
- shift({
170
+ hide({
141
171
  boundary: boundaryElement || undefined,
142
- rootBoundary,
143
172
  padding: DEFAULT_POPOVER_PADDING,
173
+ strategy: 'referenceHidden',
144
174
  })
145
175
  )
146
- }
147
176
 
148
- // Place arrow
149
- if (arrowProp) {
150
- ret.push(
151
- arrow({
152
- element: arrowRef,
153
- padding: DEFAULT_POPOVER_PADDING,
154
- })
155
- )
156
- }
177
+ return ret
178
+ }, [
179
+ arrowProp,
180
+ boundaryElement,
181
+ constrainSize,
182
+ fallbackPlacements,
183
+ margins,
184
+ matchReferenceWidthProp,
185
+ preventOverflow,
186
+ ])
157
187
 
158
- ret.push(
159
- hide({
160
- boundary: boundaryElement || undefined,
161
- padding: DEFAULT_POPOVER_PADDING,
162
- strategy: 'referenceHidden',
163
- })
188
+ const floatingProps: UseFloatingProps = useMemo(
189
+ () => ({
190
+ middleware,
191
+ placement: placementProp,
192
+ whileElementsMounted: autoUpdate,
193
+ }),
194
+ [middleware, placementProp]
164
195
  )
165
196
 
166
- return ret
167
- }, [
168
- arrowProp,
169
- boundaryElement,
170
- constrainSize,
171
- fallbackPlacements,
172
- matchReferenceWidthProp,
173
- preventOverflow,
174
- ])
175
-
176
- const {x, y, placement, reference, floating, middlewareData, strategy} = useFloating({
177
- middleware,
178
- placement: placementProp,
179
- whileElementsMounted: autoUpdate,
180
- })
197
+ const {
198
+ x,
199
+ y,
200
+ placement,
201
+ reference: referenceRef,
202
+ floating: floatingRef,
203
+ middlewareData,
204
+ strategy,
205
+ } = useFloating(floatingProps)
181
206
 
182
- const referenceHidden = middlewareData.hide?.referenceHidden
207
+ const referenceHidden = middlewareData.hide?.referenceHidden
183
208
 
184
- const arrowX = middlewareData.arrow?.x
185
- const arrowY = middlewareData.arrow?.y
209
+ const arrowX = middlewareData.arrow?.x
210
+ const arrowY = middlewareData.arrow?.y
186
211
 
187
- const setArrow = useCallback((arrowEl: HTMLDivElement | null) => {
188
- arrowRef.current = arrowEl
189
- }, [])
212
+ const setArrow = useCallback((arrowEl: HTMLDivElement | null) => {
213
+ arrowRef.current = arrowEl
214
+ }, [])
190
215
 
191
- const setFloating = useCallback(
192
- (node: HTMLDivElement | null) => {
193
- forwardedRef.current = node
194
- floating(node)
195
- },
196
- [floating, forwardedRef]
197
- )
216
+ const setFloating = useCallback(
217
+ (node: HTMLDivElement | null) => {
218
+ forwardedRef.current = node
219
+ floatingRef(node)
220
+ },
221
+ [floatingRef, forwardedRef]
222
+ )
198
223
 
199
- const setReference = useCallback(
200
- (node: HTMLElement | null) => {
201
- reference(node)
224
+ const setReference = useCallback(
225
+ (node: HTMLElement | null) => {
226
+ referenceRef(node)
202
227
 
203
- const childRef = (childProp as any)?.ref
228
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
+ const childRef = (childProp as any)?.ref
204
230
 
205
- if (typeof childRef === 'function') {
206
- childRef(node)
207
- } else if (childRef) {
208
- childRef.current = node
209
- }
210
- },
211
- [childProp, reference]
212
- )
231
+ if (typeof childRef === 'function') {
232
+ childRef(node)
233
+ } else if (childRef) {
234
+ childRef.current = node
235
+ }
236
+ },
237
+ [childProp, referenceRef]
238
+ )
213
239
 
214
- const child = useMemo(() => {
215
- if (!childProp || referenceElement) return null
240
+ const child = useMemo(() => {
241
+ if (!childProp || referenceElement) return null
216
242
 
217
- return cloneElement(childProp, {ref: setReference})
218
- }, [childProp, referenceElement, setReference])
243
+ return cloneElement(childProp, {ref: setReference})
244
+ }, [childProp, referenceElement, setReference])
219
245
 
220
- useEffect(() => {
221
- if (referenceElement) reference(referenceElement)
222
- }, [reference, referenceElement])
246
+ useEffect(() => {
247
+ referenceRef(referenceElement || null)
248
+ }, [referenceRef, referenceElement])
223
249
 
224
- if (disabled) {
225
- return childProp || <></>
226
- }
250
+ if (disabled) {
251
+ return childProp || <></>
252
+ }
227
253
 
228
- const popover = (
229
- <LayerProvider zOffset={zOffset}>
230
- <PopoverCard
231
- {...restProps}
232
- __unstable_margins={margins}
233
- arrow={arrowProp}
234
- arrowRef={setArrow}
235
- arrowX={arrowX}
236
- arrowY={arrowY}
237
- availableWidth={constrainSize ? availableWidth : undefined}
238
- availableHeight={constrainSize ? availableHeight : undefined}
239
- boundaryWidth={preventOverflow ? boundarySize?.width : undefined}
240
- hidden={referenceHidden}
241
- overflow={overflow}
242
- padding={padding}
243
- placement={placement}
244
- radius={radius}
245
- ref={setFloating}
246
- referenceWidth={matchReferenceWidthProp ? referenceWidth : undefined}
247
- scheme={scheme}
248
- shadow={shadow}
249
- strategy={strategy}
250
- tone={tone}
251
- x={x}
252
- y={y}
253
- width={width}
254
- >
255
- {content}
256
- </PopoverCard>
257
- </LayerProvider>
258
- )
254
+ const popover = (
255
+ <LayerProvider zOffset={zOffset}>
256
+ <PopoverCard
257
+ {...restProps}
258
+ __unstable_margins={margins}
259
+ arrow={arrowProp}
260
+ arrowRef={setArrow}
261
+ arrowX={arrowX}
262
+ arrowY={arrowY}
263
+ boundaryWidth={preventOverflow ? boundarySize?.width : undefined}
264
+ hidden={referenceHidden}
265
+ overflow={overflow}
266
+ padding={padding}
267
+ placement={placement}
268
+ radius={radius}
269
+ ref={setFloating}
270
+ scheme={scheme}
271
+ shadow={shadow}
272
+ strategy={strategy}
273
+ tone={tone}
274
+ x={x}
275
+ y={y}
276
+ width={width}
277
+ >
278
+ {content}
279
+ </PopoverCard>
280
+ </LayerProvider>
281
+ )
259
282
 
260
- return (
261
- <>
262
- {/* the popover */}
263
- {open && (
264
- <>
265
- {portal ? (
266
- <Portal __unstable_name={typeof portal === 'string' ? portal : undefined}>
267
- {popover}
268
- </Portal>
269
- ) : (
270
- popover
271
- )}
272
- </>
273
- )}
283
+ return (
284
+ <>
285
+ {/* the popover */}
286
+ {open && (
287
+ <>
288
+ {portal ? (
289
+ <Portal __unstable_name={typeof portal === 'string' ? portal : undefined}>
290
+ {popover}
291
+ </Portal>
292
+ ) : (
293
+ popover
294
+ )}
295
+ </>
296
+ )}
274
297
 
275
- {/* the referred element */}
276
- {child}
277
- </>
278
- )
279
- })
298
+ {/* the referred element */}
299
+ {child}
300
+ </>
301
+ )
302
+ })
303
+ )
280
304
 
281
305
  Popover.displayName = 'Popover'