@sanity/ui 0.37.14-next.6 → 0.37.16

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 (54) hide show
  1. package/lib/dts/src/components/autocomplete/autocomplete.styles.d.ts +1 -1
  2. package/lib/dts/src/components/autocomplete/autocomplete.styles.d.ts.map +1 -1
  3. package/lib/dts/src/components/autocomplete/constants.d.ts.map +1 -1
  4. package/lib/dts/src/constants.d.ts +0 -10
  5. package/lib/dts/src/constants.d.ts.map +1 -1
  6. package/lib/dts/src/primitives/popover/{popoverArrow.d.ts → arrow.d.ts} +1 -1
  7. package/lib/dts/src/primitives/popover/arrow.d.ts.map +1 -0
  8. package/lib/dts/src/primitives/popover/modifiers/getPopoverModifiers.d.ts +4 -0
  9. package/lib/dts/src/primitives/popover/modifiers/getPopoverModifiers.d.ts.map +1 -0
  10. package/lib/dts/src/primitives/popover/modifiers/index.d.ts +2 -0
  11. package/lib/dts/src/primitives/popover/modifiers/index.d.ts.map +1 -0
  12. package/lib/dts/src/primitives/popover/modifiers/types.d.ts +18 -0
  13. package/lib/dts/src/primitives/popover/modifiers/types.d.ts.map +1 -0
  14. package/lib/dts/src/primitives/popover/modifiers/usePopoverModifiers.d.ts +4 -0
  15. package/lib/dts/src/primitives/popover/modifiers/usePopoverModifiers.d.ts.map +1 -0
  16. package/lib/dts/src/primitives/popover/popover.d.ts +5 -6
  17. package/lib/dts/src/primitives/popover/popover.d.ts.map +1 -1
  18. package/lib/dts/src/primitives/textArea/textArea.d.ts.map +1 -1
  19. package/lib/dts/src/primitives/textInput/textInput.d.ts.map +1 -1
  20. package/lib/dts/src/primitives/tooltip/tooltip.d.ts +0 -2
  21. package/lib/dts/src/primitives/tooltip/tooltip.d.ts.map +1 -1
  22. package/lib/dts/src/primitives/tooltip/tooltipArrow.d.ts.map +1 -1
  23. package/lib/dts/src/styles/input/textInputStyle.d.ts +3 -1
  24. package/lib/dts/src/styles/input/textInputStyle.d.ts.map +1 -1
  25. package/lib/sanity-ui.js +465 -490
  26. package/lib/sanity-ui.js.map +1 -1
  27. package/lib/sanity-ui.modern.mjs +584 -566
  28. package/lib/sanity-ui.modern.mjs.map +1 -1
  29. package/lib/sanity-ui.module.js +465 -491
  30. package/lib/sanity-ui.module.js.map +1 -1
  31. package/package.json +6 -5
  32. package/src/components/autocomplete/autocomplete.styles.tsx +5 -0
  33. package/src/components/autocomplete/constants.ts +3 -3
  34. package/src/constants.ts +0 -17
  35. package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -1
  36. package/src/primitives/popover/__workshop__/RightAlignedStory.tsx +0 -1
  37. package/src/primitives/popover/__workshop__/TestStory.tsx +0 -1
  38. package/src/primitives/popover/{popoverArrow.tsx → arrow.tsx} +5 -5
  39. package/src/primitives/popover/modifiers/getPopoverModifiers.ts +137 -0
  40. package/src/primitives/popover/modifiers/index.ts +1 -0
  41. package/src/primitives/popover/modifiers/types.ts +18 -0
  42. package/src/primitives/popover/modifiers/usePopoverModifiers.ts +58 -0
  43. package/src/primitives/popover/popover.tsx +196 -229
  44. package/src/primitives/textArea/textArea.tsx +2 -0
  45. package/src/primitives/textInput/__workshop__/tones.tsx +222 -105
  46. package/src/primitives/textInput/textInput.tsx +5 -1
  47. package/src/primitives/tooltip/__workshop__/props.tsx +4 -5
  48. package/src/primitives/tooltip/tooltip.tsx +92 -159
  49. package/src/primitives/tooltip/tooltipArrow.tsx +10 -25
  50. package/src/styles/input/textInputStyle.ts +7 -5
  51. package/lib/dts/src/primitives/popover/popoverArrow.d.ts.map +0 -1
  52. package/lib/dts/src/primitives/popover/popoverCard.d.ts +0 -33
  53. package/lib/dts/src/primitives/popover/popoverCard.d.ts.map +0 -1
  54. package/src/primitives/popover/popoverCard.tsx +0 -160
@@ -1,26 +1,6 @@
1
- import {
2
- arrow,
3
- autoUpdate,
4
- flip,
5
- offset,
6
- shift,
7
- useFloating,
8
- Middleware,
9
- RootBoundary,
10
- } from '@floating-ui/react-dom'
11
- import React, {
12
- cloneElement,
13
- forwardRef,
14
- useCallback,
15
- useEffect,
16
- useMemo,
17
- useRef,
18
- useState,
19
- CSSProperties,
20
- ForwardedRef,
21
- } from 'react'
1
+ import React, {cloneElement, forwardRef, useCallback, useEffect, useRef, useState} from 'react'
2
+ import {usePopper} from 'react-popper'
22
3
  import styled from 'styled-components'
23
- import {FLOATING_STATIC_SIDES} from '../../constants'
24
4
  import {useArrayProp, useForwardedRef} from '../../hooks'
25
5
  import {ThemeColorSchemeKey, useTheme} from '../../theme'
26
6
  import {Placement} from '../../types'
@@ -32,7 +12,6 @@ import {TooltipArrow} from './tooltipArrow'
32
12
  * @public
33
13
  */
34
14
  export interface TooltipProps extends Omit<LayerProps, 'as'> {
35
- /** @deprecated Use `fallbackPlacements` instead. */
36
15
  allowedAutoPlacements?: Placement[]
37
16
  boundaryElement?: HTMLElement | null
38
17
  children?: React.ReactElement
@@ -42,7 +21,6 @@ export interface TooltipProps extends Omit<LayerProps, 'as'> {
42
21
  placement?: Placement
43
22
  portal?: boolean | string
44
23
  scheme?: ThemeColorSchemeKey
45
- shadow?: number | number[]
46
24
  }
47
25
 
48
26
  const Root = styled(Layer)`
@@ -59,88 +37,55 @@ export const Tooltip = forwardRef(function Tooltip(
59
37
  const boundaryElementContext = useBoundaryElement()
60
38
  const theme = useTheme()
61
39
  const {
40
+ allowedAutoPlacements,
62
41
  boundaryElement = boundaryElementContext?.element,
63
- children: childProp,
42
+ children,
64
43
  content,
65
44
  disabled,
66
45
  fallbackPlacements: fallbackPlacementsProp,
67
- placement: placementProp = 'bottom',
46
+ placement = 'bottom',
68
47
  portal,
69
48
  scheme,
70
- shadow = 2,
71
49
  zOffset = theme.sanity.layer?.tooltip.zOffset,
72
50
  ...restProps
73
51
  } = props
74
52
  const fallbackPlacements = useArrayProp(fallbackPlacementsProp)
75
53
  const forwardedRef = useForwardedRef(ref)
76
54
  const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null)
77
- const arrowRef = useRef<HTMLDivElement | null>(null)
78
- const rootBoundary: RootBoundary = 'viewport'
79
-
80
- const middleware = useMemo(() => {
81
- const ret: Middleware[] = []
82
-
83
- // Flip the floating element when leaving the boundary box
84
- ret.push(
85
- flip({
86
- boundary: boundaryElement || undefined,
87
- fallbackPlacements,
88
- padding: 4,
89
- rootBoundary,
90
- })
91
- )
92
-
93
- // Define distance between reference and floating element
94
- ret.push(offset({mainAxis: 3}))
95
-
96
- // Shift the tooltip so its sits with the boundary eleement
97
- ret.push(
98
- shift({
99
- boundary: boundaryElement || undefined,
100
- rootBoundary,
101
- padding: 4,
102
- })
103
- )
104
-
105
- // Place arrow
106
- ret.push(arrow({element: arrowRef, padding: 2}))
107
-
108
- return ret
109
- }, [boundaryElement, fallbackPlacements])
110
-
111
- const {x, y, placement, reference, floating, middlewareData, update, strategy} = useFloating({
112
- middleware,
113
- placement: placementProp,
114
- whileElementsMounted: autoUpdate,
55
+ const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null)
56
+ const [arrowElement, setArrowElement] = useState<HTMLDivElement | null>(null)
57
+ const popper = usePopper(referenceElement, popperElement, {
58
+ placement,
59
+ modifiers: [
60
+ {
61
+ name: 'arrow',
62
+ options: {
63
+ element: arrowElement,
64
+ padding: 4,
65
+ },
66
+ },
67
+ {
68
+ name: 'preventOverflow',
69
+ options: {
70
+ altAxis: true,
71
+ boundary: boundaryElement || undefined,
72
+ padding: 4,
73
+ },
74
+ },
75
+ {
76
+ name: 'offset',
77
+ options: {offset: [0, 3]},
78
+ },
79
+ {
80
+ name: 'flip',
81
+ options: {
82
+ allowedAutoPlacements,
83
+ fallbackPlacements,
84
+ },
85
+ },
86
+ ],
115
87
  })
116
-
117
- const rootStyle: CSSProperties = useMemo(
118
- () => ({
119
- position: strategy,
120
- top: y ?? 0,
121
- left: x ?? 0,
122
- }),
123
- [strategy, x, y]
124
- )
125
-
126
- const staticSide = placement && FLOATING_STATIC_SIDES[placement.split('-')[0]]
127
-
128
- const arrowX = middlewareData.arrow?.x
129
- const arrowY = middlewareData.arrow?.y
130
-
131
- const arrowStyle: CSSProperties = useMemo(() => {
132
- const style: CSSProperties = {
133
- left: arrowX !== null ? arrowX : undefined,
134
- top: arrowY !== null ? arrowY : undefined,
135
- right: undefined,
136
- bottom: undefined,
137
- }
138
-
139
- if (staticSide) style[staticSide] = -15
140
-
141
- return style
142
- }, [arrowX, arrowY, staticSide])
143
-
88
+ const {forceUpdate} = popper
144
89
  const [isOpen, setIsOpen] = useState(false)
145
90
  const handleBlur = useCallback(() => setIsOpen(false), [])
146
91
  const handleFocus = useCallback(() => setIsOpen(true), [])
@@ -173,6 +118,25 @@ export const Tooltip = forwardRef(function Tooltip(
173
118
  }
174
119
  }, [isOpen, referenceElement])
175
120
 
121
+ const updateTimeoutRef = useRef<NodeJS.Timeout | null>(null)
122
+
123
+ useEffect(() => {
124
+ if (updateTimeoutRef.current) {
125
+ clearTimeout(updateTimeoutRef.current)
126
+ updateTimeoutRef.current = null
127
+ }
128
+
129
+ updateTimeoutRef.current = setTimeout(() => {
130
+ if (forceUpdate) {
131
+ try {
132
+ forceUpdate()
133
+ } catch (_) {
134
+ // ignore caught error
135
+ }
136
+ }
137
+ }, 0)
138
+ }, [forceUpdate, content])
139
+
176
140
  // Close when `disabled` changes to `true`
177
141
  useEffect(() => {
178
142
  if (disabled) setIsOpen(false)
@@ -183,85 +147,54 @@ export const Tooltip = forwardRef(function Tooltip(
183
147
  if (!content) setIsOpen(false)
184
148
  }, [content])
185
149
 
186
- // Update reference
187
- useEffect(() => reference(referenceElement), [reference, referenceElement])
188
-
189
- const setArrow = useCallback(
190
- (arrowEl: HTMLDivElement | null) => {
191
- arrowRef.current = arrowEl
192
- update()
193
- },
194
- [update]
195
- )
196
-
197
- const setFloating = useCallback(
198
- (node: HTMLDivElement | null) => {
199
- forwardedRef.current = node
200
- floating(node)
201
- },
202
- [floating, forwardedRef]
203
- )
204
-
205
- const childRef: ForwardedRef<HTMLElement | null> = (childProp as any)?.ref
206
-
207
- const setReference = useCallback(
208
- (node: HTMLElement | null) => {
209
- if (typeof childRef === 'function') {
210
- childRef(node)
211
- } else if (childRef) {
212
- childRef.current = node
213
- }
214
-
215
- // childRef.current = node
216
- setReferenceElement(node)
217
- },
218
- [childRef]
219
- )
220
-
221
- const child = useMemo(() => {
222
- if (!childProp) return null
223
-
224
- return cloneElement(childProp, {
225
- onBlur: handleBlur,
226
- onFocus: handleFocus,
227
- onMouseEnter: handleMouseEnter,
228
- onMouseLeave: handleMouseLeave,
229
- ref: setReference,
230
- })
231
- }, [childProp, handleBlur, handleFocus, handleMouseEnter, handleMouseLeave, setReference])
232
-
233
- if (!child) return <></>
234
-
235
- if (disabled) return child
236
-
237
- const root = (
238
- <Root data-ui="Tooltip" {...restProps} ref={setFloating} style={rootStyle} zOffset={zOffset}>
239
- <Card
240
- data-ui="Tooltip__card"
241
- data-placement={placement}
242
- radius={2}
243
- scheme={scheme}
244
- shadow={shadow}
245
- >
150
+ const setRef = (el: HTMLDivElement | null) => {
151
+ setPopperElement(el)
152
+ forwardedRef.current = el
153
+ }
154
+
155
+ if (!children) return <></>
156
+
157
+ if (disabled) return children
158
+
159
+ const referenceProps = {
160
+ onBlur: handleBlur,
161
+ onFocus: handleFocus,
162
+ onMouseEnter: handleMouseEnter,
163
+ onMouseLeave: handleMouseLeave,
164
+ ref: setReferenceElement,
165
+ }
166
+
167
+ const referenceNode = cloneElement(children, referenceProps)
168
+
169
+ const popperNode = (
170
+ <Root
171
+ data-ui="Tooltip"
172
+ {...restProps}
173
+ {...popper.attributes.popper}
174
+ ref={setRef}
175
+ style={popper.styles.popper}
176
+ zOffset={zOffset}
177
+ >
178
+ <Card radius={2} scheme={scheme} shadow={3}>
246
179
  {content}
247
- <TooltipArrow ref={setArrow} style={arrowStyle} />
180
+ <TooltipArrow ref={setArrowElement} style={popper.styles.arrow} />
248
181
  </Card>
249
182
  </Root>
250
183
  )
251
184
 
252
185
  return (
253
186
  <>
254
- {child}
187
+ {referenceNode}
255
188
 
256
189
  {isOpen && (
257
190
  <>
258
- {portal ? (
191
+ {portal && (
259
192
  <Portal __unstable_name={typeof portal === 'string' ? portal : undefined}>
260
- {root}
193
+ {popperNode}
261
194
  </Portal>
262
- ) : (
263
- root
264
195
  )}
196
+
197
+ {!portal && popperNode}
265
198
  </>
266
199
  )}
267
200
  </>
@@ -3,21 +3,6 @@ import styled from 'styled-components'
3
3
 
4
4
  const Root = styled.div`
5
5
  position: absolute;
6
- pointer-events: none;
7
- width: 15px;
8
- height: 15px;
9
- fill: none;
10
-
11
- :empty + & {
12
- display: none;
13
- }
14
-
15
- & > svg {
16
- display: block;
17
- transform-origin: 7.5px 7.5px;
18
- }
19
-
20
- /* position: absolute;
21
6
  width: 15px;
22
7
  height: 15px;
23
8
  fill: none;
@@ -31,30 +16,30 @@ const Root = styled.div`
31
16
  display: block;
32
17
  }
33
18
  transform-origin: 7.5px 7.5px;
34
- } */
19
+ }
35
20
 
36
- [data-placement^='top'] > & {
37
- bottom: -27px;
21
+ [data-popper-placement^='top'] > div > & {
22
+ bottom: -15px;
38
23
  }
39
24
 
40
- [data-placement^='right'] > & {
41
- left: -27px;
25
+ [data-popper-placement^='right'] > div > & {
26
+ left: -15px;
42
27
 
43
28
  & > svg {
44
29
  transform: rotate(90deg);
45
30
  }
46
31
  }
47
32
 
48
- [data-placement^='left'] > & {
49
- right: -27px;
33
+ [data-popper-placement^='left'] > div > & {
34
+ right: -15px;
50
35
 
51
36
  & > svg {
52
37
  transform: rotate(-90deg);
53
38
  }
54
39
  }
55
40
 
56
- [data-placement^='bottom'] > & {
57
- top: -27px;
41
+ [data-popper-placement^='bottom'] > div > & {
42
+ top: -15px;
58
43
 
59
44
  & > svg {
60
45
  transform: rotate(180deg);
@@ -79,7 +64,7 @@ export const TooltipArrow = forwardRef(function TooltipArrow(
79
64
  const {...restProps} = props
80
65
 
81
66
  return (
82
- <Root data-ui="Tooltip__arrow" {...restProps} ref={ref}>
67
+ <Root {...restProps} ref={ref}>
83
68
  <svg width="15" height="15" viewBox="0 0 15 15">
84
69
  <Border d="M11.5266 1C11.032 1.32802 10.5837 1.73105 10.1995 2.20057L9.04792 3.6081C8.24771 4.58614 6.7523 4.58614 5.95209 3.6081L4.80047 2.20057C4.41632 1.73105 3.96796 1.32802 3.47341 1H0.156727C1.65639 1 3.07687 1.67313 4.02651 2.83381L5.17813 4.24134C6.37844 5.70839 8.62156 5.70839 9.82187 4.24134L10.9735 2.83381C11.9231 1.67313 13.3436 1 14.8433 1H11.5266Z" />
85
70
  <Shape d="M0.156725 0C1.95632 0 3.66089 0.80776 4.80047 2.20057L5.95209 3.6081C6.75229 4.58614 8.24771 4.58614 9.04791 3.6081L10.1995 2.20057C11.3391 0.80776 13.0437 0 14.8433 0H15H0H0.156725Z" />
@@ -1,5 +1,5 @@
1
1
  import {css, CSSObject, FlattenSimpleInterpolation} from 'styled-components'
2
- import {ThemeFontWeightKey} from '../../theme'
2
+ import {ThemeColorSchemeKey, ThemeFontWeightKey} from '../../theme'
3
3
  import {CardTone} from '../../types'
4
4
  import {focusRingBorderStyle, focusRingStyle} from '../focusRing'
5
5
  import {rem, _responsive} from '../helpers'
@@ -10,6 +10,7 @@ import {ThemeProps} from '../types'
10
10
  */
11
11
  export interface TextInputInputStyleProps {
12
12
  $fontSize: number[]
13
+ $scheme: ThemeColorSchemeKey
13
14
  $tone: CardTone
14
15
  $weight?: ThemeFontWeightKey
15
16
  }
@@ -21,6 +22,7 @@ export interface TextInputRepresentationStyleProps {
21
22
  $border?: boolean
22
23
  $hasPrefix?: boolean
23
24
  $hasSuffix?: boolean
25
+ $scheme: ThemeColorSchemeKey
24
26
  $tone: CardTone
25
27
  }
26
28
 
@@ -39,7 +41,7 @@ export function textInputRootStyle(): FlattenSimpleInterpolation {
39
41
  export function textInputBaseStyle(
40
42
  props: TextInputInputStyleProps & ThemeProps
41
43
  ): FlattenSimpleInterpolation {
42
- const {theme, $tone, $weight} = props
44
+ const {theme, $scheme, $tone, $weight} = props
43
45
  const font = theme.sanity.fonts.text
44
46
  const color = theme.sanity.color.input
45
47
 
@@ -79,7 +81,7 @@ export function textInputBaseStyle(
79
81
  color: var(--input-placeholder-color);
80
82
  }
81
83
 
82
- &[data-tone='${$tone}'] {
84
+ &[data-scheme='${$scheme}'][data-tone='${$tone}'] {
83
85
  --input-fg-color: ${color.default.enabled.fg};
84
86
  --input-placeholder-color: ${color.default.enabled.placeholder};
85
87
 
@@ -127,7 +129,7 @@ export function textInputFontSizeStyle(props: TextInputInputStyleProps & ThemePr
127
129
  export function textInputRepresentationStyle(
128
130
  props: TextInputRepresentationStyleProps & ThemeProps
129
131
  ): FlattenSimpleInterpolation {
130
- const {$border, $hasPrefix, $hasSuffix, $tone, theme} = props
132
+ const {$border, $hasPrefix, $hasSuffix, $scheme, $tone, theme} = props
131
133
  const {focusRing, input} = theme.sanity
132
134
  const color = theme.sanity.color.input
133
135
 
@@ -151,7 +153,7 @@ export function textInputRepresentationStyle(
151
153
  border-top-right-radius: ${$hasSuffix ? 0 : undefined};
152
154
  border-bottom-right-radius: ${$hasSuffix ? 0 : undefined};
153
155
 
154
- &[data-tone='${$tone}'] {
156
+ &[data-scheme='${$scheme}'][data-tone='${$tone}'] {
155
157
  --card-bg-color: ${color.default.enabled.bg};
156
158
  --card-fg-color: ${color.default.enabled.fg};
157
159
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"popoverArrow.d.ts","sourceRoot":"","sources":["../../../../../src/primitives/popover/popoverArrow.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAwDvC,eAAO,MAAM,YAAY,i1LAkBvB,CAAA"}
@@ -1,33 +0,0 @@
1
- import { Strategy } from '@floating-ui/react-dom';
2
- import React from 'react';
3
- import { ThemeColorSchemeKey } from '../../theme';
4
- import { BoxOverflow, CardTone, Placement, PopoverMargins } from '../../types';
5
- /**
6
- * @internal
7
- */
8
- export declare const PopoverCard: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<{
9
- /**
10
- * @beta
11
- */
12
- __unstable_margins?: PopoverMargins | undefined;
13
- arrow: boolean;
14
- arrowRef: React.Ref<HTMLDivElement>;
15
- arrowX?: number | undefined;
16
- arrowY?: number | undefined;
17
- availableHeight?: number | undefined;
18
- availableWidth?: number | undefined;
19
- boundaryWidth?: number | undefined;
20
- overflow?: BoxOverflow | undefined;
21
- padding?: number | number[] | undefined;
22
- placement?: Placement | undefined;
23
- radius?: number | number[] | undefined;
24
- referenceWidth?: number | undefined;
25
- scheme?: ThemeColorSchemeKey | undefined;
26
- shadow?: number | number[] | undefined;
27
- strategy: Strategy;
28
- tone: CardTone;
29
- width?: number | "auto" | (number | "auto")[] | undefined;
30
- x: number | null;
31
- y: number | null;
32
- } & Omit<React.HTMLProps<HTMLDivElement>, "as" | "height" | "width">, "cite" | "data" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "accept" | "acceptCharset" | "action" | "allowFullScreen" | "allowTransparency" | "alt" | "async" | "autoComplete" | "autoFocus" | "autoPlay" | "capture" | "cellPadding" | "cellSpacing" | "charSet" | "challenge" | "checked" | "classID" | "cols" | "colSpan" | "content" | "controls" | "coords" | "crossOrigin" | "dateTime" | "default" | "defer" | "disabled" | "download" | "encType" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "frameBorder" | "headers" | "high" | "href" | "hrefLang" | "htmlFor" | "httpEquiv" | "integrity" | "keyParams" | "keyType" | "kind" | "list" | "loop" | "low" | "manifest" | "marginHeight" | "marginWidth" | "max" | "maxLength" | "media" | "mediaGroup" | "method" | "min" | "minLength" | "multiple" | "muted" | "name" | "nonce" | "noValidate" | "open" | "optimum" | "placeholder" | "playsInline" | "poster" | "preload" | "readOnly" | "rel" | "required" | "reversed" | "rows" | "rowSpan" | "sandbox" | "scope" | "scoped" | "scrolling" | "seamless" | "selected" | "shape" | "size" | "sizes" | "src" | "srcDoc" | "srcLang" | "srcSet" | "start" | "step" | "target" | "type" | "useMap" | "value" | "width" | "wmode" | "wrap" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "scheme" | "tone" | "overflow" | "padding" | "radius" | "shadow" | "__unstable_margins" | "arrow" | "arrowRef" | "arrowX" | "arrowY" | "availableHeight" | "availableWidth" | "boundaryWidth" | "placement" | "referenceWidth" | "strategy" | "x" | "y"> & React.RefAttributes<HTMLDivElement>>>;
33
- //# sourceMappingURL=popoverCard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"popoverCard.d.ts","sourceRoot":"","sources":["../../../../../src/primitives/popover/popoverCard.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAC/C,OAAO,KAAiD,MAAM,OAAO,CAAA;AAGrE,OAAO,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAC,MAAM,aAAa,CAAA;AAgB5E;;GAEG;AACH,eAAO,MAAM,WAAW;IAGlB;;OAEG;;WAEI,OAAO;cACJ,MAAM,GAAG,CAAC,cAAc,CAAC;;;;;;;;;;;;;cAazB,QAAQ;UACZ,QAAQ;;OAEX,MAAM,GAAG,IAAI;OACb,MAAM,GAAG,IAAI;mjMA4GrB,CAAA"}
@@ -1,160 +0,0 @@
1
- import {Strategy} from '@floating-ui/react-dom'
2
- import React, {CSSProperties, forwardRef, memo, useMemo} from 'react'
3
- import styled, {CSSObject} from 'styled-components'
4
- import {FLOATING_STATIC_SIDES} from '../../constants'
5
- import {ThemeColorSchemeKey} from '../../theme'
6
- import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
7
- import {useLayer} from '../../utils'
8
- import {Box} from '../box'
9
- import {Card} from '../card'
10
- import {PopoverArrow} from './popoverArrow'
11
-
12
- function popoverCardStyle(props: {$boundaryWidth?: number}): CSSObject {
13
- const {$boundaryWidth} = props
14
-
15
- return {
16
- maxWidth: $boundaryWidth ? `${$boundaryWidth - 16}px` : 'calc(100% - 16px)',
17
- }
18
- }
19
-
20
- const Root = memo(styled(Card)(popoverCardStyle))
21
-
22
- /**
23
- * @internal
24
- */
25
- export const PopoverCard = memo(
26
- forwardRef(function PopoverCard(
27
- props: {
28
- /**
29
- * @beta
30
- */
31
- __unstable_margins?: PopoverMargins
32
- arrow: boolean
33
- arrowRef: React.Ref<HTMLDivElement>
34
- arrowX?: number
35
- arrowY?: number
36
- availableHeight?: number
37
- availableWidth?: number
38
- boundaryWidth?: number
39
- overflow?: BoxOverflow
40
- padding?: number | number[]
41
- placement?: Placement
42
- radius?: number | number[]
43
- referenceWidth?: number
44
- scheme?: ThemeColorSchemeKey
45
- shadow?: number | number[]
46
- strategy: Strategy
47
- tone: CardTone
48
- width?: number | 'auto' | (number | 'auto')[]
49
- x: number | null
50
- y: number | null
51
- } & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'height' | 'width'>,
52
- ref: React.ForwardedRef<HTMLDivElement>
53
- ) {
54
- const {
55
- __unstable_margins: marginsProp,
56
- arrow,
57
- arrowRef,
58
- arrowX,
59
- arrowY,
60
- availableHeight,
61
- availableWidth,
62
- boundaryWidth,
63
- children,
64
- padding,
65
- placement,
66
- overflow,
67
- radius,
68
- referenceWidth: referenceWidthProp,
69
- scheme,
70
- shadow,
71
- strategy,
72
- tone,
73
- width,
74
- x: xProp,
75
- y: yProp,
76
- ...restProps
77
- } = props
78
-
79
- const {zIndex} = useLayer()
80
-
81
- // top right bottom left
82
- const margins: PopoverMargins = useMemo(() => marginsProp || [0, 0, 0, 0], [marginsProp])
83
-
84
- // translate according to margins
85
- const referenceWidth = referenceWidthProp
86
- ? referenceWidthProp - margins[1] - margins[3]
87
- : undefined
88
- const x = (xProp ?? 0) + margins[3]
89
- const y = (yProp ?? 0) + margins[0]
90
-
91
- const maxWidth = availableWidth
92
- ? Math.min(availableWidth - 8, referenceWidth || Infinity)
93
- : undefined
94
-
95
- const rootStyle: CSSProperties = useMemo(
96
- () => ({
97
- position: strategy,
98
- top: y,
99
- left: x,
100
- zIndex,
101
- width: referenceWidth,
102
- maxWidth: referenceWidth ? undefined : maxWidth,
103
- }),
104
- [referenceWidth, maxWidth, strategy, x, y, zIndex]
105
- )
106
-
107
- const wrapperStyle: CSSProperties = useMemo(
108
- () => ({
109
- minHeight: 25,
110
- maxHeight: availableHeight ? availableHeight - 8 : undefined,
111
- }),
112
- [availableHeight]
113
- )
114
-
115
- const staticSide = placement && FLOATING_STATIC_SIDES[placement.split('-')[0]]
116
-
117
- const arrowStyle: CSSProperties = useMemo(() => {
118
- const style: CSSProperties = {
119
- left: arrowX !== null ? arrowX : undefined,
120
- top: arrowY !== null ? arrowY : undefined,
121
- right: undefined,
122
- bottom: undefined,
123
- }
124
-
125
- if (staticSide) style[staticSide] = -27
126
-
127
- return style
128
- }, [arrowX, arrowY, staticSide])
129
-
130
- return (
131
- <Root
132
- {...restProps}
133
- $boundaryWidth={boundaryWidth}
134
- data-placement={placement}
135
- data-ui="Popover"
136
- radius={radius}
137
- ref={ref}
138
- scheme={scheme}
139
- shadow={shadow}
140
- style={rootStyle}
141
- tone={tone}
142
- $width={width}
143
- >
144
- <Box
145
- data-ui="Popover__wrapper"
146
- overflow={overflow}
147
- padding={padding}
148
- sizing="border"
149
- style={wrapperStyle}
150
- >
151
- {children}
152
- </Box>
153
-
154
- {arrow && <PopoverArrow ref={arrowRef} style={arrowStyle} />}
155
- </Root>
156
- )
157
- })
158
- )
159
-
160
- PopoverCard.displayName = 'PopoverCard'