@sanity/ui 2.0.0-alpha.23 → 2.0.0-alpha.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.
- package/dist/index.esm.js +18 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +18 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/primitives/tooltip/constants.ts +12 -12
- package/src/primitives/tooltip/tooltip.test.tsx +0 -20
- package/src/primitives/tooltip/tooltip.tsx +6 -6
- package/src/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +1 -9
package/package.json
CHANGED
|
@@ -3,16 +3,16 @@ import {Placement} from '@floating-ui/react-dom'
|
|
|
3
3
|
export const DEFAULT_TOOLTIP_DISTANCE = 4
|
|
4
4
|
export const DEFAULT_TOOLTIP_PADDING = 4
|
|
5
5
|
export const DEFAULT_FALLBACK_PLACEMENTS: Record<Placement, Placement[]> = {
|
|
6
|
-
top: ['bottom', 'left', 'right'],
|
|
7
|
-
'top-start': ['bottom-start', 'left-start', 'right-start'],
|
|
8
|
-
'top-end': ['bottom-end', 'left-end', 'right-end'],
|
|
9
|
-
bottom: ['top', 'left', 'right'],
|
|
10
|
-
'bottom-start': ['top-start', 'left-start', 'right-start'],
|
|
11
|
-
'bottom-end': ['top-end', 'left-end', 'right-end'],
|
|
12
|
-
left: ['right', 'top', 'bottom'],
|
|
13
|
-
'left-start': ['right-start', 'top-start', 'bottom-start'],
|
|
14
|
-
'left-end': ['right-end', 'top-end', 'bottom-end'],
|
|
15
|
-
right: ['left', 'top', 'bottom'],
|
|
16
|
-
'right-start': ['left-start', 'top-start', 'bottom-start'],
|
|
17
|
-
'right-end': ['left-end', 'top-end', 'bottom-end'],
|
|
6
|
+
top: ['top-end', 'top-start', 'bottom', 'left', 'right'],
|
|
7
|
+
'top-start': ['top', 'top-end', 'bottom-start', 'left-start', 'right-start'],
|
|
8
|
+
'top-end': ['top', 'top-start', 'bottom-end', 'left-end', 'right-end'],
|
|
9
|
+
bottom: ['bottom-end', 'bottom-start', 'top', 'left', 'right'],
|
|
10
|
+
'bottom-start': ['bottom', 'bottom-end', 'top-start', 'left-start', 'right-start'],
|
|
11
|
+
'bottom-end': ['bottom', 'bottom-start', 'top-end', 'left-end', 'right-end'],
|
|
12
|
+
left: ['left-end', 'left-start', 'right', 'top', 'bottom'],
|
|
13
|
+
'left-start': ['left', 'left-end', 'right-start', 'top-start', 'bottom-start'],
|
|
14
|
+
'left-end': ['left', 'left-start', 'right-end', 'top-end', 'bottom-end'],
|
|
15
|
+
right: ['right-end', 'right-start', 'left', 'top', 'bottom'],
|
|
16
|
+
'right-start': ['right', 'right-end', 'left-start', 'top-start', 'bottom-start'],
|
|
17
|
+
'right-end': ['right', 'right-start', 'left-end', 'top-end', 'bottom-end'],
|
|
18
18
|
}
|
|
@@ -265,26 +265,6 @@ describe('Tooltip', () => {
|
|
|
265
265
|
act(() => jest.advanceTimersByTime(openDelay / 2))
|
|
266
266
|
screen.getByText('Tooltip 2')
|
|
267
267
|
})
|
|
268
|
-
it("should throw an error if it's nested inside another <TooltipDelayGroupProvider />", () => {
|
|
269
|
-
// eslint-disable-next-line no-console
|
|
270
|
-
console.error = jest.fn() // Silence console.error as we are actually expecting an error in this test.
|
|
271
|
-
expect(() => {
|
|
272
|
-
render(
|
|
273
|
-
<TooltipDelayGroupProvider delay={100}>
|
|
274
|
-
<TooltipDelayGroupProvider delay={100}>
|
|
275
|
-
<Tooltip content={<Text size={1}>{'Tooltip 1'}</Text>} placement={'top'} delay={400}>
|
|
276
|
-
<Button mode="bleed" text="Button 1" />
|
|
277
|
-
</Tooltip>
|
|
278
|
-
</TooltipDelayGroupProvider>
|
|
279
|
-
</TooltipDelayGroupProvider>,
|
|
280
|
-
)
|
|
281
|
-
}).toThrow(
|
|
282
|
-
'TooltipDelayGroupProvider cannot be nested inside another TooltipDelayGroupProvider',
|
|
283
|
-
)
|
|
284
|
-
|
|
285
|
-
// Clean up the console.error mock
|
|
286
|
-
jest.clearAllMocks()
|
|
287
|
-
})
|
|
288
268
|
})
|
|
289
269
|
|
|
290
270
|
describe('Closing the <Tooltip /> with the Escape key', () => {
|
|
@@ -264,7 +264,7 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
264
264
|
// necessary, because the tooltip might not always close as it should (e.g. when clicking
|
|
265
265
|
// the reference element triggers a CPU-heavy operation.)
|
|
266
266
|
useEffect(() => {
|
|
267
|
-
if (!
|
|
267
|
+
if (!showTooltip) return
|
|
268
268
|
|
|
269
269
|
function handleWindowMouseMove(event: MouseEvent) {
|
|
270
270
|
if (!referenceElement) return
|
|
@@ -284,17 +284,17 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
284
284
|
return () => {
|
|
285
285
|
window.removeEventListener('mousemove', handleWindowMouseMove)
|
|
286
286
|
}
|
|
287
|
-
}, [
|
|
287
|
+
}, [showTooltip, referenceElement, handleIsOpenChange])
|
|
288
288
|
|
|
289
289
|
// Close when `disabled` changes to `true`
|
|
290
290
|
useEffect(() => {
|
|
291
|
-
if (disabled) handleIsOpenChange(false)
|
|
292
|
-
}, [disabled, handleIsOpenChange])
|
|
291
|
+
if (disabled && showTooltip) handleIsOpenChange(false)
|
|
292
|
+
}, [disabled, handleIsOpenChange, showTooltip])
|
|
293
293
|
|
|
294
294
|
// Close when `content` changes to falsy
|
|
295
295
|
useEffect(() => {
|
|
296
|
-
if (!content) handleIsOpenChange(false)
|
|
297
|
-
}, [content, handleIsOpenChange])
|
|
296
|
+
if (!content && showTooltip) handleIsOpenChange(false)
|
|
297
|
+
}, [content, handleIsOpenChange, showTooltip])
|
|
298
298
|
|
|
299
299
|
// Update reference
|
|
300
300
|
useEffect(() => refs.setReference(referenceElement), [referenceElement, refs])
|
|
@@ -3,7 +3,7 @@ import {useDelayedState} from '../../../hooks/useDelayedState'
|
|
|
3
3
|
import {Delay} from '../../types'
|
|
4
4
|
import {TooltipDelayGroupContext} from './tooltipDelayGroupContext'
|
|
5
5
|
import {TooltipDelayGroupContextValue} from './types'
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
9
9
|
* */
|
|
@@ -31,14 +31,6 @@ export function TooltipDelayGroupProvider(
|
|
|
31
31
|
const [isGroupActive, setIsGroupActive] = useDelayedState(false)
|
|
32
32
|
const [openTooltipId, setOpenTooltipId] = useDelayedState<string | null>(null)
|
|
33
33
|
|
|
34
|
-
const isInsideContext = useTooltipDelayGroup()
|
|
35
|
-
|
|
36
|
-
if (isInsideContext) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
'TooltipDelayGroupProvider cannot be nested inside another TooltipDelayGroupProvider',
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
34
|
const openDelay = typeof delay === 'number' ? delay : delay?.open || 0
|
|
43
35
|
const closeDelay = typeof delay === 'number' ? delay : delay?.close || 0
|
|
44
36
|
|