@sanity/ui 1.5.0 → 1.7.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.
@@ -1,45 +1,23 @@
1
1
  import {Strategy} from '@floating-ui/react-dom'
2
2
  import React, {CSSProperties, forwardRef, memo, useMemo} from 'react'
3
- import styled, {CSSObject} from 'styled-components'
3
+ import styled from 'styled-components'
4
4
  import {FLOATING_STATIC_SIDES} from '../../constants'
5
- import {ThemeProps} from '../../styles'
6
5
  import {ThemeColorSchemeKey} from '../../theme'
7
6
  import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
8
7
  import {useLayer} from '../../utils'
9
8
  import {Card} from '../card'
10
- import {Container} from '../container'
11
- import {
12
- DEFAULT_POPOVER_ARROW_WIDTH,
13
- DEFAULT_POPOVER_MARGINS,
14
- DEFAULT_POPOVER_PADDING,
15
- } from './constants'
9
+ import {Flex} from '../flex'
10
+ import {DEFAULT_POPOVER_ARROW_WIDTH, DEFAULT_POPOVER_MARGINS} from './constants'
16
11
  import {PopoverArrow} from './popoverArrow'
17
12
 
18
- function popoverCardStyle(props: {$boundaryWidth?: number} & ThemeProps): CSSObject {
19
- const {$boundaryWidth} = props
20
-
21
- return {
22
- '&:not([hidden])': {
23
- display: 'flex',
24
- },
25
-
26
- flexDirection: 'column',
27
-
28
- width: 'max-content',
29
- minWidth: 'min-content',
30
- maxWidth:
31
- typeof $boundaryWidth === 'number'
32
- ? `${$boundaryWidth - DEFAULT_POPOVER_PADDING * 2}px`
33
- : undefined,
34
- }
35
- }
36
-
37
- const Root = memo(styled(Card)(popoverCardStyle))
38
-
39
- const PopoverContainer = memo(styled(Container)`
40
- max-height: inherit;
41
- max-width: inherit;
42
- `)
13
+ const Root = styled(Card)({
14
+ '&:not([hidden])': {
15
+ display: 'flex',
16
+ },
17
+ flexDirection: 'column',
18
+ width: 'max-content',
19
+ minWidth: 'min-content',
20
+ })
43
21
 
44
22
  /**
45
23
  * @internal
@@ -53,7 +31,6 @@ export const PopoverCard = memo(
53
31
  arrowRef: React.Ref<HTMLDivElement>
54
32
  arrowX?: number
55
33
  arrowY?: number
56
- boundaryWidth?: number
57
34
  overflow?: BoxOverflow
58
35
  padding?: number | number[]
59
36
  placement?: Placement
@@ -62,7 +39,7 @@ export const PopoverCard = memo(
62
39
  shadow?: number | number[]
63
40
  strategy: Strategy
64
41
  tone: CardTone
65
- width?: number | 'auto' | (number | 'auto')[]
42
+ width: number | undefined
66
43
  x: number | null
67
44
  y: number | null
68
45
  } & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'height' | 'width'>,
@@ -74,7 +51,6 @@ export const PopoverCard = memo(
74
51
  arrowRef,
75
52
  arrowX,
76
53
  arrowY,
77
- boundaryWidth,
78
54
  children,
79
55
  padding,
80
56
  placement,
@@ -85,7 +61,7 @@ export const PopoverCard = memo(
85
61
  strategy,
86
62
  style,
87
63
  tone,
88
- width = 'auto',
64
+ width,
89
65
  x: xProp,
90
66
  y: yProp,
91
67
  ...restProps
@@ -108,10 +84,11 @@ export const PopoverCard = memo(
108
84
  position: strategy,
109
85
  top: y,
110
86
  left: x,
87
+ width,
111
88
  zIndex,
112
89
  ...style,
113
90
  }),
114
- [strategy, style, x, y, zIndex]
91
+ [strategy, style, width, x, y, zIndex]
115
92
  )
116
93
 
117
94
  const staticSide = placement && FLOATING_STATIC_SIDES[placement.split('-')[0]]
@@ -131,10 +108,9 @@ export const PopoverCard = memo(
131
108
 
132
109
  return (
133
110
  <Root
111
+ data-ui="Popover"
134
112
  {...restProps}
135
- $boundaryWidth={boundaryWidth}
136
113
  data-placement={placement}
137
- data-ui="Popover"
138
114
  radius={radius}
139
115
  ref={ref}
140
116
  scheme={scheme}
@@ -143,16 +119,11 @@ export const PopoverCard = memo(
143
119
  style={rootStyle}
144
120
  tone={tone}
145
121
  >
146
- <PopoverContainer
147
- data-ui="Popover__wrapper"
148
- flex={1}
149
- overflow={overflow}
150
- padding={padding}
151
- sizing="border"
152
- width={width}
153
- >
154
- {children}
155
- </PopoverContainer>
122
+ <Flex data-ui="Popover__wrapper" direction="column" flex={1} overflow={overflow}>
123
+ <Flex direction="column" flex={1} padding={padding}>
124
+ {children}
125
+ </Flex>
126
+ </Flex>
156
127
 
157
128
  {arrow && <PopoverArrow ref={arrowRef} style={arrowStyle} />}
158
129
  </Root>
@@ -0,0 +1,6 @@
1
+ /** @beta */
2
+ export type PopoverUpdateCallback = () => void
3
+
4
+ /** @public */
5
+ // TODO: remove `auto` from PopoverWidth
6
+ export type PopoverWidth = number | 'auto'
@@ -110,7 +110,7 @@ export const Tooltip = forwardRef(function Tooltip(
110
110
  return ret
111
111
  }, [boundaryElement, fallbackPlacements])
112
112
 
113
- const {x, y, placement, reference, floating, middlewareData, update, strategy} = useFloating({
113
+ const {x, y, placement, middlewareData, refs, update, strategy} = useFloating({
114
114
  middleware,
115
115
  placement: placementProp,
116
116
  whileElementsMounted: autoUpdate,
@@ -186,7 +186,7 @@ export const Tooltip = forwardRef(function Tooltip(
186
186
  }, [content])
187
187
 
188
188
  // Update reference
189
- useEffect(() => reference(referenceElement), [reference, referenceElement])
189
+ useEffect(() => refs.setReference(referenceElement), [referenceElement, refs])
190
190
 
191
191
  const setArrow = useCallback(
192
192
  (arrowEl: HTMLDivElement | null) => {
@@ -199,9 +199,9 @@ export const Tooltip = forwardRef(function Tooltip(
199
199
  const setFloating = useCallback(
200
200
  (node: HTMLDivElement | null) => {
201
201
  forwardedRef.current = node
202
- floating(node)
202
+ refs.setFloating(node)
203
203
  },
204
- [floating, forwardedRef]
204
+ [forwardedRef, refs]
205
205
  )
206
206
 
207
207
  const childRef: ForwardedRef<HTMLElement | null> = (childProp as any)?.ref