@sanity/ui 0.37.14 → 0.37.15
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/primitives/popover/popover.d.ts.map +1 -1
- package/lib/dts/src/primitives/tooltip/tooltip.d.ts.map +1 -1
- package/lib/sanity-ui.js +27 -11
- package/lib/sanity-ui.js.map +1 -1
- package/lib/sanity-ui.modern.mjs +27 -11
- package/lib/sanity-ui.modern.mjs.map +1 -1
- package/lib/sanity-ui.module.js +27 -11
- package/lib/sanity-ui.module.js.map +1 -1
- package/package.json +2 -2
- package/src/primitives/popover/popover.tsx +25 -8
- package/src/primitives/tooltip/__workshop__/props.tsx +3 -2
- package/src/primitives/tooltip/tooltip.tsx +16 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.15",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"publishConfig": {
|
|
73
73
|
"access": "public"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "73cdaa54f6eca0236e1386751edf038d41181dd5"
|
|
76
76
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
cloneElement,
|
|
3
|
+
forwardRef,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react'
|
|
2
10
|
import {usePopper} from 'react-popper'
|
|
3
11
|
import styled, {css} from 'styled-components'
|
|
4
12
|
import {EMPTY_RECORD} from '../../constants'
|
|
@@ -137,7 +145,7 @@ export const Popover = forwardRef(function Popover(
|
|
|
137
145
|
const [popperElement, setPopperElement] = useState<HTMLElement | null>(null)
|
|
138
146
|
const [arrowElement, setArrowElement] = useState<HTMLElement | null>(null)
|
|
139
147
|
const popperReferenceElement = referenceElementProp || referenceElement
|
|
140
|
-
const width = useArrayProp(widthProp)
|
|
148
|
+
const width = useArrayProp(matchReferenceWidth ? 'auto' : widthProp)
|
|
141
149
|
|
|
142
150
|
const modifiers = usePopoverModifiers({
|
|
143
151
|
allowedAutoPlacements,
|
|
@@ -188,14 +196,23 @@ export const Popover = forwardRef(function Popover(
|
|
|
188
196
|
|
|
189
197
|
const popoverStyle = useMemo(() => ({...style, ...styles.popper}), [style, styles])
|
|
190
198
|
|
|
199
|
+
const updateTimeoutRef = useRef<NodeJS.Timeout | null>(null)
|
|
200
|
+
|
|
191
201
|
useEffect(() => {
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
} catch (_) {
|
|
196
|
-
// ignore caught error
|
|
197
|
-
}
|
|
202
|
+
if (updateTimeoutRef.current) {
|
|
203
|
+
clearTimeout(updateTimeoutRef.current)
|
|
204
|
+
updateTimeoutRef.current = null
|
|
198
205
|
}
|
|
206
|
+
|
|
207
|
+
updateTimeoutRef.current = setTimeout(() => {
|
|
208
|
+
if (forceUpdate) {
|
|
209
|
+
try {
|
|
210
|
+
forceUpdate()
|
|
211
|
+
} catch (_) {
|
|
212
|
+
// ignore caught error
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}, 0)
|
|
199
216
|
}, [content, forceUpdate, open, popperReferenceElement])
|
|
200
217
|
|
|
201
218
|
if (disabled) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {Box, Button, Card, Flex, Text, Tooltip} from '@sanity/ui'
|
|
2
|
-
import {useSelect} from '@sanity/ui-workshop'
|
|
2
|
+
import {useSelect, useText} from '@sanity/ui-workshop'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import {WORKSHOP_PLACEMENT_OPTIONS} from '../../../__workshop__/constants'
|
|
5
5
|
|
|
6
6
|
export default function PropsStory() {
|
|
7
|
+
const content = useText('Content', 'Tooltip content')
|
|
7
8
|
const placement = useSelect('Placement', WORKSHOP_PLACEMENT_OPTIONS, 'top')
|
|
8
9
|
|
|
9
10
|
return (
|
|
@@ -12,7 +13,7 @@ export default function PropsStory() {
|
|
|
12
13
|
<Tooltip
|
|
13
14
|
content={
|
|
14
15
|
<Box padding={2}>
|
|
15
|
-
<Text size={1}>
|
|
16
|
+
<Text size={1}>{content}</Text>
|
|
16
17
|
</Box>
|
|
17
18
|
}
|
|
18
19
|
placement={placement}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {cloneElement, forwardRef, useCallback, useEffect, useState} from 'react'
|
|
1
|
+
import React, {cloneElement, forwardRef, useCallback, useEffect, useRef, useState} from 'react'
|
|
2
2
|
import {usePopper} from 'react-popper'
|
|
3
3
|
import styled from 'styled-components'
|
|
4
4
|
import {useArrayProp, useForwardedRef} from '../../hooks'
|
|
@@ -118,14 +118,23 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
118
118
|
}
|
|
119
119
|
}, [isOpen, referenceElement])
|
|
120
120
|
|
|
121
|
+
const updateTimeoutRef = useRef<NodeJS.Timeout | null>(null)
|
|
122
|
+
|
|
121
123
|
useEffect(() => {
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
} catch (_) {
|
|
126
|
-
// ignore caught error
|
|
127
|
-
}
|
|
124
|
+
if (updateTimeoutRef.current) {
|
|
125
|
+
clearTimeout(updateTimeoutRef.current)
|
|
126
|
+
updateTimeoutRef.current = null
|
|
128
127
|
}
|
|
128
|
+
|
|
129
|
+
updateTimeoutRef.current = setTimeout(() => {
|
|
130
|
+
if (forceUpdate) {
|
|
131
|
+
try {
|
|
132
|
+
forceUpdate()
|
|
133
|
+
} catch (_) {
|
|
134
|
+
// ignore caught error
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}, 0)
|
|
129
138
|
}, [forceUpdate, content])
|
|
130
139
|
|
|
131
140
|
// Close when `disabled` changes to `true`
|