@sanity/ui 4.0.0-static.32 → 4.0.0-static.34
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.d.ts +0 -14
- package/dist/index.js +229 -198
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/components/dialog/Dialog.tsx +13 -5
- package/src/core/components/dialog/DialogProvider.tsx +1 -1
- package/src/core/components/menu/Menu.test.tsx +6 -6
- package/src/core/components/menu/Menu.tsx +2 -2
- package/src/core/components/toast/Toast.test.tsx +6 -6
- package/src/core/components/toast/ToastProvider.tsx +2 -2
- package/src/core/components/tree/Tree.tsx +2 -2
- package/src/core/components/tree/TreeItem.tsx +4 -4
- package/src/core/helpers/props.ts +0 -9
- package/src/core/hooks/useResponsiveProp.ts +4 -17
- package/src/core/index.ts +0 -1
- package/src/core/lib/createGlobalScopedContext.ts +3 -1
- package/src/core/primitives/avatar/Avatar.tsx +2 -2
- package/src/core/primitives/card/CardProvider.tsx +2 -11
- package/src/core/primitives/layer/Layer.test.tsx +6 -6
- package/src/core/primitives/layer/LayerProvider.tsx +3 -3
- package/src/core/primitives/popover/Popover.tsx +2 -2
- package/src/core/primitives/textInput/TextInput.tsx +73 -53
- package/src/core/primitives/tooltip/tooltipDelayGroup/TooltipDelayGroupProvider.tsx +1 -3
- package/src/core/utils/boundaryElement/BoundaryElement.test.tsx +6 -6
- package/src/core/utils/boundaryElement/BoundaryElementProvider.tsx +1 -1
package/package.json
CHANGED
|
@@ -5,13 +5,20 @@ import {
|
|
|
5
5
|
type ResponsiveProp,
|
|
6
6
|
} from '@sanity/ui/css'
|
|
7
7
|
import type {CardTone, ColorScheme, Radius} from '@sanity/ui/theme'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type FocusEvent,
|
|
10
|
+
type ForwardedRef,
|
|
11
|
+
type ReactNode,
|
|
12
|
+
useCallback,
|
|
13
|
+
useMemo,
|
|
14
|
+
useRef,
|
|
15
|
+
} from 'react'
|
|
9
16
|
|
|
10
17
|
import {Z_OFFSETS} from '../../constants'
|
|
11
18
|
import {isHTMLElement} from '../../helpers/element'
|
|
12
19
|
import {focusFirstDescendant, focusLastDescendant} from '../../helpers/focus'
|
|
20
|
+
import {_getResponsiveProp} from '../../helpers/props'
|
|
13
21
|
import {usePrefersReducedMotion} from '../../hooks/usePrefersReducedMotion'
|
|
14
|
-
import {useResponsiveProp} from '../../hooks/useResponsiveProp'
|
|
15
22
|
import {Container} from '../../primitives/container/Container'
|
|
16
23
|
import {Layer, type LayerOwnProps, type LayerProps} from '../../primitives/layer/Layer'
|
|
17
24
|
import type {ComponentType, Props} from '../../types'
|
|
@@ -109,9 +116,10 @@ export function Dialog<E extends DialogElementType = typeof DEFAULT_DIALOG_ELEME
|
|
|
109
116
|
const portal = usePortal()
|
|
110
117
|
const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
|
|
111
118
|
const boundaryElement = useBoundaryElement().element
|
|
112
|
-
const cardRadius =
|
|
113
|
-
const position =
|
|
114
|
-
const zOffset =
|
|
119
|
+
const cardRadius = useMemo(() => _getResponsiveProp(cardRadiusProp), [cardRadiusProp])
|
|
120
|
+
const position = useMemo(() => _getResponsiveProp(positionProp), [positionProp])
|
|
121
|
+
const zOffset = useMemo(() => _getResponsiveProp(zOffsetProp), [zOffsetProp])
|
|
122
|
+
|
|
115
123
|
const preDivRef = useRef<HTMLDivElement | null>(null)
|
|
116
124
|
const postDivRef = useRef<HTMLDivElement | null>(null)
|
|
117
125
|
const cardRef = useRef<HTMLDivElement | null>(null)
|
|
@@ -30,5 +30,5 @@ export function DialogProvider(props: DialogProviderProps): React.JSX.Element {
|
|
|
30
30
|
[position, zOffset],
|
|
31
31
|
)
|
|
32
32
|
|
|
33
|
-
return <DialogContext
|
|
33
|
+
return <DialogContext value={contextValue}>{children}</DialogContext>
|
|
34
34
|
}
|
|
@@ -45,9 +45,9 @@ describe('components/menu', () => {
|
|
|
45
45
|
)
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
|
-
<MenuContext
|
|
48
|
+
<MenuContext value={value}>
|
|
49
49
|
<Debug />
|
|
50
|
-
</MenuContext
|
|
50
|
+
</MenuContext>
|
|
51
51
|
)
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -77,12 +77,12 @@ describe('components/menu', () => {
|
|
|
77
77
|
|
|
78
78
|
function Root() {
|
|
79
79
|
return (
|
|
80
|
-
<MenuContext
|
|
80
|
+
<MenuContext
|
|
81
81
|
// @ts-expect-error - we want to test the error case
|
|
82
82
|
value={undefined}
|
|
83
83
|
>
|
|
84
84
|
<Debug />
|
|
85
|
-
</MenuContext
|
|
85
|
+
</MenuContext>
|
|
86
86
|
)
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -108,12 +108,12 @@ describe('components/menu', () => {
|
|
|
108
108
|
// NOTE: we’re testing this because the context value may be a function in the future
|
|
109
109
|
|
|
110
110
|
return (
|
|
111
|
-
<MenuContext
|
|
111
|
+
<MenuContext
|
|
112
112
|
// @ts-expect-error - we want to test the error case
|
|
113
113
|
value={() => ({version: 1})}
|
|
114
114
|
>
|
|
115
115
|
<Debug />
|
|
116
|
-
</MenuContext
|
|
116
|
+
</MenuContext>
|
|
117
117
|
)
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -153,7 +153,7 @@ export function Menu<E extends MenuElementType = typeof DEFAULT_MENU_ELEMENT>(
|
|
|
153
153
|
)
|
|
154
154
|
|
|
155
155
|
return (
|
|
156
|
-
<MenuContext
|
|
156
|
+
<MenuContext value={value}>
|
|
157
157
|
<Box
|
|
158
158
|
data-ui="Menu"
|
|
159
159
|
{...rest}
|
|
@@ -169,6 +169,6 @@ export function Menu<E extends MenuElementType = typeof DEFAULT_MENU_ELEMENT>(
|
|
|
169
169
|
>
|
|
170
170
|
<Stack gap={gap}>{children}</Stack>
|
|
171
171
|
</Box>
|
|
172
|
-
</MenuContext
|
|
172
|
+
</MenuContext>
|
|
173
173
|
)
|
|
174
174
|
}
|
|
@@ -26,9 +26,9 @@ describe('components/toast', () => {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
return (
|
|
29
|
-
<ToastContext
|
|
29
|
+
<ToastContext value={value}>
|
|
30
30
|
<Debug />
|
|
31
|
-
</ToastContext
|
|
31
|
+
</ToastContext>
|
|
32
32
|
)
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -53,12 +53,12 @@ describe('components/toast', () => {
|
|
|
53
53
|
|
|
54
54
|
function Root() {
|
|
55
55
|
return (
|
|
56
|
-
<ToastContext
|
|
56
|
+
<ToastContext
|
|
57
57
|
// @ts-expect-error - we want to test the error case
|
|
58
58
|
value={undefined}
|
|
59
59
|
>
|
|
60
60
|
<Debug />
|
|
61
|
-
</ToastContext
|
|
61
|
+
</ToastContext>
|
|
62
62
|
)
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -84,12 +84,12 @@ describe('components/toast', () => {
|
|
|
84
84
|
// NOTE: we’re testing this because the context value may be a function in the future
|
|
85
85
|
|
|
86
86
|
return (
|
|
87
|
-
<ToastContext
|
|
87
|
+
<ToastContext
|
|
88
88
|
// @ts-expect-error - we want to test the error case
|
|
89
89
|
value={() => ({version: 1})}
|
|
90
90
|
>
|
|
91
91
|
<Debug />
|
|
92
|
-
</ToastContext
|
|
92
|
+
</ToastContext>
|
|
93
93
|
)
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -86,7 +86,7 @@ export function ToastProvider(props: ToastProviderProps): React.JSX.Element {
|
|
|
86
86
|
}, [])
|
|
87
87
|
|
|
88
88
|
return (
|
|
89
|
-
<ToastContext
|
|
89
|
+
<ToastContext value={value}>
|
|
90
90
|
{children}
|
|
91
91
|
{mounted && (
|
|
92
92
|
<LayerProvider zOffset={zOffset}>
|
|
@@ -107,6 +107,6 @@ export function ToastProvider(props: ToastProviderProps): React.JSX.Element {
|
|
|
107
107
|
</ToastLayer>
|
|
108
108
|
</LayerProvider>
|
|
109
109
|
)}
|
|
110
|
-
</ToastContext
|
|
110
|
+
</ToastContext>
|
|
111
111
|
)
|
|
112
112
|
}
|
|
@@ -231,7 +231,7 @@ export function Tree<E extends TreeElementType = typeof DEFAULT_TREE_ELEMENT>(
|
|
|
231
231
|
}, [children])
|
|
232
232
|
|
|
233
233
|
return (
|
|
234
|
-
<TreeContext
|
|
234
|
+
<TreeContext value={contextValue}>
|
|
235
235
|
<Stack
|
|
236
236
|
as="ul"
|
|
237
237
|
data-ui="Tree"
|
|
@@ -244,6 +244,6 @@ export function Tree<E extends TreeElementType = typeof DEFAULT_TREE_ELEMENT>(
|
|
|
244
244
|
>
|
|
245
245
|
{children}
|
|
246
246
|
</Stack>
|
|
247
|
-
</TreeContext
|
|
247
|
+
</TreeContext>
|
|
248
248
|
)
|
|
249
249
|
}
|
|
@@ -195,9 +195,9 @@ export function TreeItem<E extends TreeItemElementType = typeof DEFAULT_TREE_ITE
|
|
|
195
195
|
{content}
|
|
196
196
|
</Selectable>
|
|
197
197
|
|
|
198
|
-
<TreeContext
|
|
198
|
+
<TreeContext value={contextValue}>
|
|
199
199
|
{children && <TreeGroup hidden={!expanded}>{children}</TreeGroup>}
|
|
200
|
-
</TreeContext
|
|
200
|
+
</TreeContext>
|
|
201
201
|
</Box>
|
|
202
202
|
)
|
|
203
203
|
}
|
|
@@ -232,9 +232,9 @@ export function TreeItem<E extends TreeItemElementType = typeof DEFAULT_TREE_ITE
|
|
|
232
232
|
{content}
|
|
233
233
|
</Selectable>
|
|
234
234
|
|
|
235
|
-
<TreeContext
|
|
235
|
+
<TreeContext value={contextValue}>
|
|
236
236
|
{children && <TreeGroup expanded={expanded}>{children}</TreeGroup>}
|
|
237
|
-
</TreeContext
|
|
237
|
+
</TreeContext>
|
|
238
238
|
</Box>
|
|
239
239
|
)
|
|
240
240
|
}
|
|
@@ -4,15 +4,6 @@ import {EMPTY_ARRAY} from '../constants'
|
|
|
4
4
|
import {isArray} from '../lib/isArray'
|
|
5
5
|
import {isRecord} from '../lib/isRecord'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export function _getArrayProp<T>(val: T | T[] | undefined, defaultVal?: T[]): T[] {
|
|
11
|
-
if (val === undefined) return defaultVal || EMPTY_ARRAY
|
|
12
|
-
|
|
13
|
-
return Array.isArray(val) ? val : [val]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
7
|
/**
|
|
17
8
|
* @internal
|
|
18
9
|
*/
|
|
@@ -1,28 +1,15 @@
|
|
|
1
1
|
import type {Breakpoint, ResponsiveProp} from '@sanity/ui/css'
|
|
2
|
-
import {
|
|
2
|
+
import {useMemo} from 'react'
|
|
3
3
|
|
|
4
4
|
import {_getResponsiveProp} from '../helpers/props'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
7
|
+
* @internal
|
|
8
|
+
* @deprecated use `_getResponsiveProp` directly instead, if necessary
|
|
9
9
|
*/
|
|
10
10
|
export function useResponsiveProp<T>(
|
|
11
11
|
val: ResponsiveProp<T> | undefined,
|
|
12
12
|
defaultVal?: Partial<Record<Breakpoint, T>>,
|
|
13
13
|
): Partial<Record<Breakpoint, T>> {
|
|
14
|
-
|
|
15
|
-
() => [_getResponsiveProp(val, defaultVal), JSON.stringify(val ?? defaultVal)],
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
const hash = JSON.stringify(val ?? defaultVal)
|
|
19
|
-
|
|
20
|
-
if (hash !== cachedHash) {
|
|
21
|
-
// If the cached hash has changed, update the cache right away.
|
|
22
|
-
// Calling setState during render is fine in this case, and preferred over a useEffect loop
|
|
23
|
-
// https://19.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
|
|
24
|
-
setCache([_getResponsiveProp(val, defaultVal), hash])
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return cachedVal
|
|
14
|
+
return useMemo(() => _getResponsiveProp(val, defaultVal), [defaultVal, val])
|
|
28
15
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -42,7 +42,6 @@ export * from './hooks/useMatchMedia'
|
|
|
42
42
|
export * from './hooks/useMediaIndex/useMediaIndex'
|
|
43
43
|
export * from './hooks/usePrefersDark'
|
|
44
44
|
export * from './hooks/usePrefersReducedMotion'
|
|
45
|
-
export * from './hooks/useResponsiveProp'
|
|
46
45
|
|
|
47
46
|
// observers
|
|
48
47
|
export * from './observers/elementSize'
|
|
@@ -25,7 +25,9 @@ export function createGlobalScopedContext<ContextType, const T extends ContextTy
|
|
|
25
25
|
* Prevent errors about re-renders on React SSR on Next.js App Router
|
|
26
26
|
*/
|
|
27
27
|
if (typeof document === 'undefined') {
|
|
28
|
-
|
|
28
|
+
const context = createContext<ContextType>(defaultValue)
|
|
29
|
+
context.displayName = key
|
|
30
|
+
return context
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
// Use the global scope as a map of symbols to contexts
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import type {AvatarColor, AvatarSize, FontLabelSize} from '@sanity/ui/theme'
|
|
10
10
|
import {useCallback, useEffect, useMemo, useState} from 'react'
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import {_getResponsiveProp} from '../../helpers/props'
|
|
13
13
|
import type {ComponentType, Props} from '../../types'
|
|
14
14
|
import {Box} from '../box/Box'
|
|
15
15
|
import {Label} from '../label/Label'
|
|
@@ -61,7 +61,7 @@ export function Avatar<E extends AvatarElementType = typeof DEFAULT_AVATAR_ELEME
|
|
|
61
61
|
...rest
|
|
62
62
|
} = props as AvatarProps<typeof DEFAULT_AVATAR_ELEMENT>
|
|
63
63
|
|
|
64
|
-
const size =
|
|
64
|
+
const size = useMemo(() => _getResponsiveProp(sizeProp), [sizeProp])
|
|
65
65
|
|
|
66
66
|
const [arrowPosition, setArrowPosition] = useState<AvatarPosition | undefined>(
|
|
67
67
|
animateArrowFrom || arrowPositionProp || 'inside',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {CardTone, ColorScheme} from '@sanity/ui/theme'
|
|
2
|
-
import {type ReactNode
|
|
2
|
+
import {type ReactNode} from 'react'
|
|
3
3
|
|
|
4
4
|
import {CardContext} from './CardContext'
|
|
5
5
|
import type {_CardCompatProviderComponent} from './types'
|
|
@@ -14,14 +14,5 @@ export function CardProvider(props: {
|
|
|
14
14
|
}): React.JSX.Element {
|
|
15
15
|
const {children, tone, scheme, unstable_CompatProvider} = props
|
|
16
16
|
|
|
17
|
-
return
|
|
18
|
-
<CardContext.Provider
|
|
19
|
-
value={useMemo(
|
|
20
|
-
() => ({tone, scheme, unstable_CompatProvider}),
|
|
21
|
-
[tone, scheme, unstable_CompatProvider],
|
|
22
|
-
)}
|
|
23
|
-
>
|
|
24
|
-
{children}
|
|
25
|
-
</CardContext.Provider>
|
|
26
|
-
)
|
|
17
|
+
return <CardContext value={{tone, scheme, unstable_CompatProvider}}>{children}</CardContext>
|
|
27
18
|
}
|
|
@@ -30,9 +30,9 @@ describe('primitives/layer', () => {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
return (
|
|
33
|
-
<LayerContext
|
|
33
|
+
<LayerContext value={value}>
|
|
34
34
|
<Debug />
|
|
35
|
-
</LayerContext
|
|
35
|
+
</LayerContext>
|
|
36
36
|
)
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -60,12 +60,12 @@ describe('primitives/layer', () => {
|
|
|
60
60
|
|
|
61
61
|
function Root() {
|
|
62
62
|
return (
|
|
63
|
-
<LayerContext
|
|
63
|
+
<LayerContext
|
|
64
64
|
// @ts-expect-error - we want to test the error case
|
|
65
65
|
value={undefined}
|
|
66
66
|
>
|
|
67
67
|
<Debug />
|
|
68
|
-
</LayerContext
|
|
68
|
+
</LayerContext>
|
|
69
69
|
)
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -91,12 +91,12 @@ describe('primitives/layer', () => {
|
|
|
91
91
|
// NOTE: we’re testing this because the context value may be a function in the future
|
|
92
92
|
|
|
93
93
|
return (
|
|
94
|
-
<LayerContext
|
|
94
|
+
<LayerContext
|
|
95
95
|
// @ts-expect-error - we want to test the error case
|
|
96
96
|
value={() => ({version: 1})}
|
|
97
97
|
>
|
|
98
98
|
<Debug />
|
|
99
|
-
</LayerContext
|
|
99
|
+
</LayerContext>
|
|
100
100
|
)
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type {Breakpoint, ResponsiveProp} from '@sanity/ui/css'
|
|
2
2
|
import {type ReactNode, use, useCallback, useEffect, useMemo, useState} from 'react'
|
|
3
3
|
|
|
4
|
+
import {_getResponsiveProp} from '../../helpers/props'
|
|
4
5
|
import {useMediaIndex} from '../../hooks/useMediaIndex/useMediaIndex'
|
|
5
|
-
import {useResponsiveProp} from '../../hooks/useResponsiveProp'
|
|
6
6
|
import {getLayerContext} from './getLayerContext'
|
|
7
7
|
import {LayerContext} from './LayerContext'
|
|
8
8
|
import type {LayerContextValue} from './types'
|
|
@@ -27,7 +27,7 @@ export function LayerProvider(props: LayerProviderProps): React.JSX.Element {
|
|
|
27
27
|
const level = parentLevel + 1
|
|
28
28
|
|
|
29
29
|
// Get z-index offset
|
|
30
|
-
const zOffset =
|
|
30
|
+
const zOffset = useMemo(() => _getResponsiveProp(zOffsetProp), [zOffsetProp])
|
|
31
31
|
|
|
32
32
|
// Get responsive z-index value
|
|
33
33
|
const maxMediaIndex = Object.values(zOffset).length - 1
|
|
@@ -102,5 +102,5 @@ export function LayerProvider(props: LayerProviderProps): React.JSX.Element {
|
|
|
102
102
|
[isTopLayer, level, registerChild, size, zIndex],
|
|
103
103
|
)
|
|
104
104
|
|
|
105
|
-
return <LayerContext
|
|
105
|
+
return <LayerContext value={value}>{children}</LayerContext>
|
|
106
106
|
}
|
|
@@ -25,8 +25,8 @@ import {
|
|
|
25
25
|
} from 'react'
|
|
26
26
|
|
|
27
27
|
import {Z_OFFSETS} from '../../constants'
|
|
28
|
+
import {_getResponsiveProp} from '../../helpers/props'
|
|
28
29
|
import {usePrefersReducedMotion} from '../../hooks/usePrefersReducedMotion'
|
|
29
|
-
import {useResponsiveProp} from '../../hooks/useResponsiveProp'
|
|
30
30
|
import {origin} from '../../middleware/origin'
|
|
31
31
|
import type {ComponentType, Placement, Props} from '../../types'
|
|
32
32
|
import {useBoundaryElement} from '../../utils/boundaryElement/useBoundaryElement'
|
|
@@ -198,7 +198,7 @@ export function Popover<E extends PopoverElementType = typeof DEFAULT_POPOVER_EL
|
|
|
198
198
|
|
|
199
199
|
const prefersReducedMotion = usePrefersReducedMotion()
|
|
200
200
|
const animate = prefersReducedMotion ? false : _animate
|
|
201
|
-
const zOffset =
|
|
201
|
+
const zOffset = useMemo(() => _getResponsiveProp(zOffsetProp), [zOffsetProp])
|
|
202
202
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
203
203
|
const arrowRef = useRef<HTMLDivElement | null>(null)
|
|
204
204
|
const rootBoundary: RootBoundary = 'viewport'
|
|
@@ -23,8 +23,8 @@ import {
|
|
|
23
23
|
import {isValidElementType} from 'react-is'
|
|
24
24
|
|
|
25
25
|
import {EMPTY_RECORD} from '../../constants'
|
|
26
|
+
import {_getResponsiveProp} from '../../helpers/props'
|
|
26
27
|
import {useCustomValidity} from '../../hooks/useCustomValidity'
|
|
27
|
-
import {useResponsiveProp} from '../../hooks/useResponsiveProp'
|
|
28
28
|
import {isRecord} from '../../lib/isRecord'
|
|
29
29
|
import type {ComponentType, Props} from '../../types'
|
|
30
30
|
import {Box} from '../box/Box'
|
|
@@ -107,7 +107,7 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
|
|
|
107
107
|
|
|
108
108
|
const ref = useRef<HTMLInputElement | null>(null)
|
|
109
109
|
|
|
110
|
-
const responsivePadding =
|
|
110
|
+
const responsivePadding = useMemo(() => _getResponsiveProp(padding), [padding])
|
|
111
111
|
|
|
112
112
|
const withClearButton = Boolean(clearButton)
|
|
113
113
|
|
|
@@ -137,35 +137,6 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
|
|
|
137
137
|
[onClear, ref],
|
|
138
138
|
)
|
|
139
139
|
|
|
140
|
-
const clearButtonBoxPadding = useMemo(() => {
|
|
141
|
-
return Object.fromEntries(
|
|
142
|
-
Object.entries(responsivePadding).map(([key, value]) => {
|
|
143
|
-
if (value === 0) return [key, 0]
|
|
144
|
-
if (value === 1) return [key, 1]
|
|
145
|
-
if (value === 2) return [key, 1]
|
|
146
|
-
|
|
147
|
-
return [key, typeof value === 'number' ? value - 2 : 0]
|
|
148
|
-
}),
|
|
149
|
-
) as ResponsiveProp<Space>
|
|
150
|
-
}, [responsivePadding])
|
|
151
|
-
|
|
152
|
-
const clearButtonPadding = useMemo(() => {
|
|
153
|
-
return Object.fromEntries(
|
|
154
|
-
Object.entries(responsivePadding).map(([key, value]) => {
|
|
155
|
-
if (value === 0) return [key, 0]
|
|
156
|
-
if (value === 1) return [key, 0]
|
|
157
|
-
if (value === 2) return [key, 1]
|
|
158
|
-
|
|
159
|
-
return [key, typeof value === 'number' ? value - 1 : 0]
|
|
160
|
-
}),
|
|
161
|
-
) as ResponsiveProp<Space>
|
|
162
|
-
}, [responsivePadding])
|
|
163
|
-
|
|
164
|
-
const clearButtonProps: TextInputClearButtonProps = useMemo(
|
|
165
|
-
() => (isRecord(clearButton) ? clearButton : EMPTY_RECORD),
|
|
166
|
-
[clearButton],
|
|
167
|
-
)
|
|
168
|
-
|
|
169
140
|
return (
|
|
170
141
|
<span
|
|
171
142
|
className={textInput({
|
|
@@ -224,28 +195,14 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
|
|
|
224
195
|
</span>
|
|
225
196
|
|
|
226
197
|
{!disabled && !readOnly && clearButton && (
|
|
227
|
-
<
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
<Button
|
|
236
|
-
aria-label="Clear"
|
|
237
|
-
data-qa="clear-button"
|
|
238
|
-
display="block"
|
|
239
|
-
fontSize={fontSize}
|
|
240
|
-
icon={CloseIcon}
|
|
241
|
-
mode="bleed"
|
|
242
|
-
padding={clearButtonPadding}
|
|
243
|
-
radius={radius}
|
|
244
|
-
{...clearButtonProps}
|
|
245
|
-
onClick={handleClearClick}
|
|
246
|
-
onMouseDown={handleClearMouseDown}
|
|
247
|
-
/>
|
|
248
|
-
</Box>
|
|
198
|
+
<ClearButton
|
|
199
|
+
fontSize={fontSize}
|
|
200
|
+
radius={radius}
|
|
201
|
+
clearButtonProps={isRecord(clearButton) ? clearButton : EMPTY_RECORD}
|
|
202
|
+
handleClearClick={handleClearClick}
|
|
203
|
+
handleClearMouseDown={handleClearMouseDown}
|
|
204
|
+
padding={responsivePadding}
|
|
205
|
+
/>
|
|
249
206
|
)}
|
|
250
207
|
</span>
|
|
251
208
|
|
|
@@ -257,3 +214,66 @@ export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_I
|
|
|
257
214
|
</span>
|
|
258
215
|
)
|
|
259
216
|
}
|
|
217
|
+
|
|
218
|
+
function ClearButton({
|
|
219
|
+
fontSize,
|
|
220
|
+
radius,
|
|
221
|
+
clearButtonProps,
|
|
222
|
+
handleClearClick,
|
|
223
|
+
handleClearMouseDown,
|
|
224
|
+
padding,
|
|
225
|
+
}: {
|
|
226
|
+
clearButtonProps: TextInputClearButtonProps
|
|
227
|
+
handleClearClick: (event: MouseEvent<HTMLButtonElement>) => void
|
|
228
|
+
handleClearMouseDown: (event: MouseEvent<HTMLButtonElement>) => void
|
|
229
|
+
padding: ResponsiveProp<Space>
|
|
230
|
+
} & Pick<TextInputOwnProps, 'fontSize' | 'radius'>) {
|
|
231
|
+
const clearButtonBoxPadding = useMemo(() => {
|
|
232
|
+
return Object.fromEntries(
|
|
233
|
+
Object.entries(padding).map(([key, value]) => {
|
|
234
|
+
if (value === 0) return [key, 0]
|
|
235
|
+
if (value === 1) return [key, 1]
|
|
236
|
+
if (value === 2) return [key, 1]
|
|
237
|
+
|
|
238
|
+
return [key, typeof value === 'number' ? value - 2 : 0]
|
|
239
|
+
}),
|
|
240
|
+
) as ResponsiveProp<Space>
|
|
241
|
+
}, [padding])
|
|
242
|
+
|
|
243
|
+
const clearButtonPadding = useMemo(() => {
|
|
244
|
+
return Object.fromEntries(
|
|
245
|
+
Object.entries(padding).map(([key, value]) => {
|
|
246
|
+
if (value === 0) return [key, 0]
|
|
247
|
+
if (value === 1) return [key, 0]
|
|
248
|
+
if (value === 2) return [key, 1]
|
|
249
|
+
|
|
250
|
+
return [key, typeof value === 'number' ? value - 1 : 0]
|
|
251
|
+
}),
|
|
252
|
+
) as ResponsiveProp<Space>
|
|
253
|
+
}, [padding])
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<Box
|
|
257
|
+
as="span"
|
|
258
|
+
insetTop={0}
|
|
259
|
+
insetRight={0}
|
|
260
|
+
padding={clearButtonBoxPadding}
|
|
261
|
+
position="absolute"
|
|
262
|
+
style={{zIndex: 2}}
|
|
263
|
+
>
|
|
264
|
+
<Button
|
|
265
|
+
aria-label="Clear"
|
|
266
|
+
data-qa="clear-button"
|
|
267
|
+
display="block"
|
|
268
|
+
fontSize={fontSize}
|
|
269
|
+
icon={CloseIcon}
|
|
270
|
+
mode="bleed"
|
|
271
|
+
padding={clearButtonPadding}
|
|
272
|
+
radius={radius}
|
|
273
|
+
{...clearButtonProps}
|
|
274
|
+
onClick={handleClearClick}
|
|
275
|
+
onMouseDown={handleClearMouseDown}
|
|
276
|
+
/>
|
|
277
|
+
</Box>
|
|
278
|
+
)
|
|
279
|
+
}
|
|
@@ -49,7 +49,5 @@ export function TooltipDelayGroupProvider(
|
|
|
49
49
|
[closeDelay, isGroupActive, openDelay, openTooltipId, setIsGroupActive, setOpenTooltipId],
|
|
50
50
|
)
|
|
51
51
|
|
|
52
|
-
return
|
|
53
|
-
<TooltipDelayGroupContext.Provider value={value}>{children}</TooltipDelayGroupContext.Provider>
|
|
54
|
-
)
|
|
52
|
+
return <TooltipDelayGroupContext value={value}>{children}</TooltipDelayGroupContext>
|
|
55
53
|
}
|
|
@@ -26,9 +26,9 @@ describe('utils/boundaryElement', () => {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
return (
|
|
29
|
-
<BoundaryElementContext
|
|
29
|
+
<BoundaryElementContext value={value}>
|
|
30
30
|
<Debug />
|
|
31
|
-
</BoundaryElementContext
|
|
31
|
+
</BoundaryElementContext>
|
|
32
32
|
)
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -51,12 +51,12 @@ describe('utils/boundaryElement', () => {
|
|
|
51
51
|
|
|
52
52
|
function Root() {
|
|
53
53
|
return (
|
|
54
|
-
<BoundaryElementContext
|
|
54
|
+
<BoundaryElementContext
|
|
55
55
|
// @ts-expect-error - we want to test the error case
|
|
56
56
|
value={undefined}
|
|
57
57
|
>
|
|
58
58
|
<Debug />
|
|
59
|
-
</BoundaryElementContext
|
|
59
|
+
</BoundaryElementContext>
|
|
60
60
|
)
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -83,12 +83,12 @@ describe('utils/boundaryElement', () => {
|
|
|
83
83
|
// NOTE: we’re testing this because the context value may be a function in the future
|
|
84
84
|
|
|
85
85
|
return (
|
|
86
|
-
<BoundaryElementContext
|
|
86
|
+
<BoundaryElementContext
|
|
87
87
|
// @ts-expect-error - we want to test the error case
|
|
88
88
|
value={() => ({version: 1})}
|
|
89
89
|
>
|
|
90
90
|
<Debug />
|
|
91
|
-
</BoundaryElementContext
|
|
91
|
+
</BoundaryElementContext>
|
|
92
92
|
)
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -14,5 +14,5 @@ export function BoundaryElementProvider(props: BoundaryElementProviderProps): Re
|
|
|
14
14
|
const {children, element} = props
|
|
15
15
|
const value: BoundaryElementContextValue = useMemo(() => ({version: 0.0, element}), [element])
|
|
16
16
|
|
|
17
|
-
return <BoundaryElementContext
|
|
17
|
+
return <BoundaryElementContext value={value}>{children}</BoundaryElementContext>
|
|
18
18
|
}
|