@sanity/ui 0.37.13 → 0.37.14-next.5
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.
- package/lib/dts/src/components/autocomplete/autocomplete.styles.d.ts +1 -1
- package/lib/dts/src/components/autocomplete/autocomplete.styles.d.ts.map +1 -1
- package/lib/dts/src/components/autocomplete/constants.d.ts.map +1 -1
- package/lib/dts/src/constants.d.ts +10 -0
- package/lib/dts/src/constants.d.ts.map +1 -1
- package/lib/dts/src/primitives/popover/popover.d.ts +6 -5
- package/lib/dts/src/primitives/popover/popover.d.ts.map +1 -1
- package/lib/dts/src/primitives/popover/{arrow.d.ts → popoverArrow.d.ts} +1 -1
- package/lib/dts/src/primitives/popover/popoverArrow.d.ts.map +1 -0
- package/lib/dts/src/primitives/popover/popoverCard.d.ts +33 -0
- package/lib/dts/src/primitives/popover/popoverCard.d.ts.map +1 -0
- package/lib/dts/src/primitives/tooltip/tooltip.d.ts +2 -0
- package/lib/dts/src/primitives/tooltip/tooltip.d.ts.map +1 -1
- package/lib/dts/src/primitives/tooltip/tooltipArrow.d.ts.map +1 -1
- package/lib/sanity-ui.js +488 -439
- package/lib/sanity-ui.js.map +1 -1
- package/lib/sanity-ui.modern.mjs +561 -555
- package/lib/sanity-ui.modern.mjs.map +1 -1
- package/lib/sanity-ui.module.js +489 -439
- package/lib/sanity-ui.module.js.map +1 -1
- package/package.json +5 -6
- package/src/components/autocomplete/autocomplete.styles.tsx +0 -5
- package/src/components/autocomplete/constants.ts +3 -3
- package/src/constants.ts +17 -0
- package/src/primitives/popover/__workshop__/PlainStory.tsx +1 -0
- package/src/primitives/popover/__workshop__/RightAlignedStory.tsx +1 -0
- package/src/primitives/popover/__workshop__/TestStory.tsx +1 -0
- package/src/primitives/popover/popover.tsx +245 -195
- package/src/primitives/popover/{arrow.tsx → popoverArrow.tsx} +5 -5
- package/src/primitives/popover/popoverCard.tsx +160 -0
- package/src/primitives/tooltip/__workshop__/props.tsx +3 -1
- package/src/primitives/tooltip/tooltip.tsx +159 -83
- package/src/primitives/tooltip/tooltipArrow.tsx +25 -10
- package/lib/dts/src/primitives/popover/arrow.d.ts.map +0 -1
- package/lib/dts/src/primitives/popover/modifiers/getPopoverModifiers.d.ts +0 -4
- package/lib/dts/src/primitives/popover/modifiers/getPopoverModifiers.d.ts.map +0 -1
- package/lib/dts/src/primitives/popover/modifiers/index.d.ts +0 -2
- package/lib/dts/src/primitives/popover/modifiers/index.d.ts.map +0 -1
- package/lib/dts/src/primitives/popover/modifiers/types.d.ts +0 -18
- package/lib/dts/src/primitives/popover/modifiers/types.d.ts.map +0 -1
- package/lib/dts/src/primitives/popover/modifiers/usePopoverModifiers.d.ts +0 -4
- package/lib/dts/src/primitives/popover/modifiers/usePopoverModifiers.d.ts.map +0 -1
- package/src/primitives/popover/modifiers/getPopoverModifiers.ts +0 -137
- package/src/primitives/popover/modifiers/index.ts +0 -1
- package/src/primitives/popover/modifiers/types.ts +0 -18
- package/src/primitives/popover/modifiers/usePopoverModifiers.ts +0 -58
|
@@ -0,0 +1,160 @@
|
|
|
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'
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {Box, Button, Card, Flex, Text, Tooltip} from '@sanity/ui'
|
|
2
2
|
import {useSelect} from '@sanity/ui-workshop'
|
|
3
3
|
import React from 'react'
|
|
4
|
-
import {WORKSHOP_PLACEMENT_OPTIONS} from '../../../__workshop__/constants'
|
|
4
|
+
import {WORKSHOP_PLACEMENT_OPTIONS, WORKSHOP_SHADOW_OPTIONS} from '../../../__workshop__/constants'
|
|
5
5
|
|
|
6
6
|
export default function PropsStory() {
|
|
7
7
|
const placement = useSelect('Placement', WORKSHOP_PLACEMENT_OPTIONS, 'top')
|
|
8
|
+
const shadow = useSelect('Shadow', WORKSHOP_SHADOW_OPTIONS, 2)
|
|
8
9
|
|
|
9
10
|
return (
|
|
10
11
|
<Card height="fill">
|
|
@@ -17,6 +18,7 @@ export default function PropsStory() {
|
|
|
17
18
|
}
|
|
18
19
|
placement={placement}
|
|
19
20
|
portal
|
|
21
|
+
shadow={shadow}
|
|
20
22
|
>
|
|
21
23
|
<Button mode="bleed" text="Hover me" />
|
|
22
24
|
</Tooltip>
|
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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'
|
|
3
22
|
import styled from 'styled-components'
|
|
23
|
+
import {FLOATING_STATIC_SIDES} from '../../constants'
|
|
4
24
|
import {useArrayProp, useForwardedRef} from '../../hooks'
|
|
5
25
|
import {ThemeColorSchemeKey, useTheme} from '../../theme'
|
|
6
26
|
import {Placement} from '../../types'
|
|
@@ -12,6 +32,7 @@ import {TooltipArrow} from './tooltipArrow'
|
|
|
12
32
|
* @public
|
|
13
33
|
*/
|
|
14
34
|
export interface TooltipProps extends Omit<LayerProps, 'as'> {
|
|
35
|
+
/** @deprecated Use `fallbackPlacements` instead. */
|
|
15
36
|
allowedAutoPlacements?: Placement[]
|
|
16
37
|
boundaryElement?: HTMLElement | null
|
|
17
38
|
children?: React.ReactElement
|
|
@@ -21,6 +42,7 @@ export interface TooltipProps extends Omit<LayerProps, 'as'> {
|
|
|
21
42
|
placement?: Placement
|
|
22
43
|
portal?: boolean | string
|
|
23
44
|
scheme?: ThemeColorSchemeKey
|
|
45
|
+
shadow?: number | number[]
|
|
24
46
|
}
|
|
25
47
|
|
|
26
48
|
const Root = styled(Layer)`
|
|
@@ -37,55 +59,88 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
37
59
|
const boundaryElementContext = useBoundaryElement()
|
|
38
60
|
const theme = useTheme()
|
|
39
61
|
const {
|
|
40
|
-
allowedAutoPlacements,
|
|
41
62
|
boundaryElement = boundaryElementContext?.element,
|
|
42
|
-
children,
|
|
63
|
+
children: childProp,
|
|
43
64
|
content,
|
|
44
65
|
disabled,
|
|
45
66
|
fallbackPlacements: fallbackPlacementsProp,
|
|
46
|
-
placement = 'bottom',
|
|
67
|
+
placement: placementProp = 'bottom',
|
|
47
68
|
portal,
|
|
48
69
|
scheme,
|
|
70
|
+
shadow = 2,
|
|
49
71
|
zOffset = theme.sanity.layer?.tooltip.zOffset,
|
|
50
72
|
...restProps
|
|
51
73
|
} = props
|
|
52
74
|
const fallbackPlacements = useArrayProp(fallbackPlacementsProp)
|
|
53
75
|
const forwardedRef = useForwardedRef(ref)
|
|
54
76
|
const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null)
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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,
|
|
87
115
|
})
|
|
88
|
-
|
|
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
|
+
|
|
89
144
|
const [isOpen, setIsOpen] = useState(false)
|
|
90
145
|
const handleBlur = useCallback(() => setIsOpen(false), [])
|
|
91
146
|
const handleFocus = useCallback(() => setIsOpen(true), [])
|
|
@@ -118,16 +173,6 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
118
173
|
}
|
|
119
174
|
}, [isOpen, referenceElement])
|
|
120
175
|
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
if (forceUpdate) {
|
|
123
|
-
try {
|
|
124
|
-
forceUpdate()
|
|
125
|
-
} catch (_) {
|
|
126
|
-
// ignore caught error
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}, [forceUpdate, content])
|
|
130
|
-
|
|
131
176
|
// Close when `disabled` changes to `true`
|
|
132
177
|
useEffect(() => {
|
|
133
178
|
if (disabled) setIsOpen(false)
|
|
@@ -138,54 +183,85 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
138
183
|
if (!content) setIsOpen(false)
|
|
139
184
|
}, [content])
|
|
140
185
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
{
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
+
>
|
|
170
246
|
{content}
|
|
171
|
-
<TooltipArrow ref={
|
|
247
|
+
<TooltipArrow ref={setArrow} style={arrowStyle} />
|
|
172
248
|
</Card>
|
|
173
249
|
</Root>
|
|
174
250
|
)
|
|
175
251
|
|
|
176
252
|
return (
|
|
177
253
|
<>
|
|
178
|
-
{
|
|
254
|
+
{child}
|
|
179
255
|
|
|
180
256
|
{isOpen && (
|
|
181
257
|
<>
|
|
182
|
-
{portal
|
|
258
|
+
{portal ? (
|
|
183
259
|
<Portal __unstable_name={typeof portal === 'string' ? portal : undefined}>
|
|
184
|
-
{
|
|
260
|
+
{root}
|
|
185
261
|
</Portal>
|
|
262
|
+
) : (
|
|
263
|
+
root
|
|
186
264
|
)}
|
|
187
|
-
|
|
188
|
-
{!portal && popperNode}
|
|
189
265
|
</>
|
|
190
266
|
)}
|
|
191
267
|
</>
|
|
@@ -3,6 +3,21 @@ 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;
|
|
6
21
|
width: 15px;
|
|
7
22
|
height: 15px;
|
|
8
23
|
fill: none;
|
|
@@ -16,30 +31,30 @@ const Root = styled.div`
|
|
|
16
31
|
display: block;
|
|
17
32
|
}
|
|
18
33
|
transform-origin: 7.5px 7.5px;
|
|
19
|
-
}
|
|
34
|
+
} */
|
|
20
35
|
|
|
21
|
-
[data-
|
|
22
|
-
bottom: -
|
|
36
|
+
[data-placement^='top'] > & {
|
|
37
|
+
bottom: -27px;
|
|
23
38
|
}
|
|
24
39
|
|
|
25
|
-
[data-
|
|
26
|
-
left: -
|
|
40
|
+
[data-placement^='right'] > & {
|
|
41
|
+
left: -27px;
|
|
27
42
|
|
|
28
43
|
& > svg {
|
|
29
44
|
transform: rotate(90deg);
|
|
30
45
|
}
|
|
31
46
|
}
|
|
32
47
|
|
|
33
|
-
[data-
|
|
34
|
-
right: -
|
|
48
|
+
[data-placement^='left'] > & {
|
|
49
|
+
right: -27px;
|
|
35
50
|
|
|
36
51
|
& > svg {
|
|
37
52
|
transform: rotate(-90deg);
|
|
38
53
|
}
|
|
39
54
|
}
|
|
40
55
|
|
|
41
|
-
[data-
|
|
42
|
-
top: -
|
|
56
|
+
[data-placement^='bottom'] > & {
|
|
57
|
+
top: -27px;
|
|
43
58
|
|
|
44
59
|
& > svg {
|
|
45
60
|
transform: rotate(180deg);
|
|
@@ -64,7 +79,7 @@ export const TooltipArrow = forwardRef(function TooltipArrow(
|
|
|
64
79
|
const {...restProps} = props
|
|
65
80
|
|
|
66
81
|
return (
|
|
67
|
-
<Root {...restProps} ref={ref}>
|
|
82
|
+
<Root data-ui="Tooltip__arrow" {...restProps} ref={ref}>
|
|
68
83
|
<svg width="15" height="15" viewBox="0 0 15 15">
|
|
69
84
|
<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" />
|
|
70
85
|
<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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"arrow.d.ts","sourceRoot":"","sources":["../../../../../src/primitives/popover/arrow.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAwDvC,eAAO,MAAM,YAAY,i1LAkBvB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPopoverModifiers.d.ts","sourceRoot":"","sources":["../../../../../../src/primitives/popover/modifiers/getPopoverModifiers.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAA;AACrC,OAAO,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAA;AAkB7C,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,qBAAqB,GAAG,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAoHtF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/primitives/popover/modifiers/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Placement } from '../../../types';
|
|
2
|
-
export interface PopoverModifiersProps {
|
|
3
|
-
allowedAutoPlacements?: Placement[];
|
|
4
|
-
arrow?: boolean;
|
|
5
|
-
arrowElement?: HTMLElement | null;
|
|
6
|
-
boundaryElement?: HTMLElement | null;
|
|
7
|
-
constrainSize?: boolean;
|
|
8
|
-
distance: number;
|
|
9
|
-
fallbackPlacements?: Placement[];
|
|
10
|
-
margins?: [number, number, number, number];
|
|
11
|
-
matchReferenceWidth?: boolean;
|
|
12
|
-
open: boolean;
|
|
13
|
-
preventOverflow?: boolean;
|
|
14
|
-
skidding: number;
|
|
15
|
-
tether?: boolean;
|
|
16
|
-
tetherOffset?: number | ((...args: any[]) => number);
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/primitives/popover/modifiers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAA;AAExC,MAAM,WAAW,qBAAqB;IACpC,qBAAqB,CAAC,EAAE,SAAS,EAAE,CAAA;IACnC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,YAAY,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IACjC,eAAe,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IACpC,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,kBAAkB,CAAC,EAAE,SAAS,EAAE,CAAA;IAChC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,IAAI,EAAE,OAAO,CAAA;IACb,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,CAAA;CACrD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePopoverModifiers.d.ts","sourceRoot":"","sources":["../../../../../../src/primitives/popover/modifiers/usePopoverModifiers.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAA;AAGrC,OAAO,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAA;AAE7C,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,qBAAqB,GAAG,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAmDtF"}
|