@sanity/ui 3.0.0-static.11 → 3.0.0-static.13
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/_chunks-cjs/_visual-editing.js +1293 -1215
- package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
- package/dist/_chunks-cjs/buildCommand.js +28 -10
- package/dist/_chunks-cjs/buildCommand.js.map +1 -1
- package/dist/_chunks-es/_visual-editing.mjs +1284 -1202
- package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
- package/dist/_visual-editing.d.mts +528 -358
- package/dist/_visual-editing.d.ts +528 -358
- package/dist/cli.js +1 -1
- package/dist/css.d.mts +143 -73
- package/dist/css.d.ts +143 -73
- package/dist/css.js +329 -472
- package/dist/css.js.map +1 -1
- package/dist/css.mjs +330 -473
- package/dist/css.mjs.map +1 -1
- package/dist/index.d.mts +1362 -869
- package/dist/index.d.ts +1362 -869
- package/dist/index.js +383 -308
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +387 -312
- package/dist/index.mjs.map +1 -1
- package/dist/sanity-palette.css +105 -1
- package/dist/sanity-palette.min.css +1 -0
- package/dist/sanity-theme.css +4571 -1
- package/dist/sanity-theme.min.css +1 -0
- package/dist/system.css +22053 -21946
- package/dist/system.min.css +1 -0
- package/dist/theme.d.mts +51 -106
- package/dist/theme.d.ts +51 -106
- package/dist/theme.js +9 -9
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +9 -9
- package/dist/theme.mjs.map +1 -1
- package/package.json +10 -5
- package/src/cli/buildCommand.ts +46 -19
- package/src/css/_comp.ts +2 -2
- package/src/css/{compile/compileStyle.ts → _compileStyle.ts} +7 -7
- package/src/css/{system.style.ts → _system.style.ts} +3 -2
- package/src/css/aspects/display/display.ts +1 -0
- package/src/css/aspects/display/types.ts +2 -3
- package/src/css/aspects/flex/types.ts +4 -12
- package/src/css/aspects/flexItem/types.ts +1 -3
- package/src/css/aspects/font/types.ts +1 -3
- package/src/css/aspects/grid/grid.ts +1 -0
- package/src/css/aspects/grid/types.ts +5 -9
- package/src/css/aspects/gridItem/gridItem.ts +1 -1
- package/src/css/aspects/gridItem/types.ts +7 -18
- package/src/css/aspects/height/height.ts +3 -4
- package/src/css/aspects/inset/inset.ts +1 -0
- package/src/css/aspects/margin/margin.ts +1 -0
- package/src/css/aspects/margin/types.ts +1 -0
- package/src/css/aspects/maxWidth/maxWidth.ts +1 -0
- package/src/css/aspects/maxWidth/types.ts +1 -0
- package/src/css/aspects/minWidth/minWidth.ts +1 -0
- package/src/css/aspects/minWidth/types.ts +2 -0
- package/src/css/aspects/overflow/overflow.ts +1 -0
- package/src/css/aspects/padding/padding.ts +1 -0
- package/src/css/aspects/pointerEvents/pointerEvents.ts +1 -0
- package/src/css/aspects/position/position.ts +1 -0
- package/src/css/aspects/shadow/shadow.ts +1 -0
- package/src/css/aspects/textOverflow/textOverflow.ts +1 -0
- package/src/css/aspects/textOverflow/types.ts +1 -0
- package/src/css/aspects/width/types.ts +2 -0
- package/src/css/aspects/width/width.ts +1 -0
- package/src/css/{compile/compilePalette.ts → compilePalette.ts} +14 -10
- package/src/css/compileSystem.ts +7 -0
- package/src/css/{compile/compileTheme.ts → compileTheme.ts} +1 -0
- package/src/css/{compile/compileTheme_v3.ts → compileTheme_v3.ts} +123 -104
- package/src/css/components/breadcrumbs/breadcrumbs.ts +1 -0
- package/src/css/components/dialog/dialog.ts +7 -0
- package/src/css/components/menu/menu.ts +2 -0
- package/src/css/components/skeleton/skeleton.ts +4 -0
- package/src/css/components/skeleton/types.ts +4 -0
- package/src/css/components/toast/toast.ts +5 -0
- package/src/css/components/tree/tree.ts +1 -0
- package/src/css/composeClassNames.ts +4 -2
- package/src/css/constants.ts +2 -0
- package/src/css/index.ts +3 -3
- package/src/css/primitives/_arrow/_arrow.ts +3 -0
- package/src/css/primitives/_input/input.ts +2 -0
- package/src/css/primitives/_selectable/_selectable.style.ts +1 -2
- package/src/css/primitives/_selectable/selectable.ts +1 -2
- package/src/css/primitives/avatar/avatar.style.ts +5 -8
- package/src/css/primitives/avatar/avatar.ts +6 -0
- package/src/css/primitives/avatar/types.ts +1 -0
- package/src/css/primitives/box/types.ts +1 -3
- package/src/css/primitives/button/button.ts +4 -21
- package/src/css/primitives/button/index.ts +1 -0
- package/src/css/primitives/button/types.ts +18 -0
- package/src/css/primitives/card/card.style.ts +3 -6
- package/src/css/primitives/card/card.ts +2 -2
- package/src/css/primitives/card/types.ts +2 -2
- package/src/css/primitives/checkbox/checkbox.ts +2 -0
- package/src/css/primitives/container/container.ts +1 -0
- package/src/css/primitives/container/types.ts +1 -0
- package/src/css/primitives/kbd/kbd.ts +1 -0
- package/src/css/primitives/label/types.ts +7 -2
- package/src/css/primitives/popover/popover.ts +2 -0
- package/src/css/primitives/radio/radio.ts +1 -0
- package/src/css/primitives/select/select.ts +2 -0
- package/src/css/primitives/spinner/spinner.ts +2 -0
- package/src/css/primitives/switch/switch.ts +5 -0
- package/src/css/primitives/text/types.ts +4 -0
- package/src/css/primitives/textArea/textArea.ts +1 -0
- package/src/css/primitives/textInput/textInput.ts +1 -0
- package/src/css/primitives/tooltip/tooltip.ts +2 -0
- package/src/css/scopeClassName.ts +1 -0
- package/src/css/types.ts +9 -12
- package/src/css/util.ts +5 -0
- package/src/css/utils/srOnly/srOnly.ts +3 -1
- package/src/css/varNames.ts +131 -141
- package/src/css/vars.ts +1 -6
- package/src/theme/palette/constants.ts +2 -0
- package/src/theme/palette/types.ts +3 -0
- package/src/theme/types.ts +2 -6
- package/src/theme/v0/focusRing.ts +1 -3
- package/src/theme/v0/font.ts +6 -18
- package/src/theme/v0/layer.ts +1 -3
- package/src/theme/v0/shadow.ts +2 -6
- package/src/theme/v2/avatar.ts +1 -3
- package/src/theme/v2/color/_system.ts +1 -3
- package/src/theme/v2/color/avatar.ts +2 -6
- package/src/theme/v2/color/badge.ts +2 -6
- package/src/theme/v2/color/button.ts +3 -9
- package/src/theme/v2/color/color.ts +3 -9
- package/src/theme/v2/color/input.ts +3 -9
- package/src/theme/v2/color/kbd.ts +1 -3
- package/src/theme/v2/color/selectable.ts +2 -6
- package/src/theme/v2/color/state.ts +1 -3
- package/src/theme/v2/color/syntax.ts +1 -3
- package/src/theme/v2/input.ts +1 -3
- package/src/theme/v2/theme.ts +2 -6
- package/src/theme/v3/buildTheme_v3.ts +1 -0
- package/src/theme/v3/color/color.ts +6 -4
- package/src/theme/v3/color/renderColor.ts +4 -1
- package/src/theme/v3/defaultTokens.ts +1 -0
- package/src/theme/v3/resolveTokens.ts +9 -9
- package/src/ui/RootClassNames.tsx +3 -0
- package/src/ui/StyleTags.tsx +3 -1
- package/src/ui/_compat/theme/themeColorProvider.tsx +2 -6
- package/src/ui/_compat/theme/themeProvider.tsx +2 -6
- package/src/ui/_compat/theme/types.ts +1 -3
- package/src/ui/_compat/theme/useRootTheme.ts +1 -3
- package/src/ui/_compat/theme/useTheme.ts +2 -6
- package/src/ui/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
- package/src/ui/components/autocomplete/autocomplete.tsx +86 -114
- package/src/ui/components/autocomplete/autocompleteOption.tsx +2 -0
- package/src/ui/components/autocomplete/types.ts +3 -8
- package/src/ui/components/breadcrumbs/breadcrumbs.tsx +27 -21
- package/src/ui/components/dialog/dialog.tsx +89 -291
- package/src/ui/components/dialog/dialogCard.tsx +183 -0
- package/src/ui/components/dialog/isTargetWithinScope.ts +14 -0
- package/src/ui/components/hotkeys/hotkeys.tsx +33 -15
- package/src/ui/components/menu/__workshop__/asComponent.tsx +6 -6
- package/src/ui/components/menu/menu.tsx +27 -33
- package/src/ui/components/menu/menuButton.tsx +10 -14
- package/src/ui/components/menu/menuDivider.tsx +25 -13
- package/src/ui/components/menu/menuGroup.tsx +34 -26
- package/src/ui/components/menu/menuItem.tsx +51 -40
- package/src/ui/components/skeleton/codeSkeleton.tsx +53 -0
- package/src/ui/components/skeleton/headingSkeleton.tsx +52 -0
- package/src/ui/components/skeleton/index.ts +3 -0
- package/src/ui/components/skeleton/labelSkeleton.tsx +51 -0
- package/src/ui/components/skeleton/skeleton.tsx +39 -16
- package/src/ui/components/skeleton/textSkeleton.tsx +31 -110
- package/src/ui/components/tab/tab.tsx +23 -19
- package/src/ui/components/tab/tabList.tsx +34 -33
- package/src/ui/components/tab/tabPanel.tsx +25 -19
- package/src/ui/components/toast/toast.tsx +21 -16
- package/src/ui/components/toast/toastLayer.tsx +28 -10
- package/src/ui/components/toast/toastProvider.tsx +2 -6
- package/src/ui/components/toast/types.ts +2 -6
- package/src/ui/components/toast/useToast.ts +1 -3
- package/src/ui/components/tree/tree.tsx +194 -187
- package/src/ui/components/tree/treeGroup.tsx +25 -5
- package/src/ui/components/tree/treeItem.tsx +35 -23
- package/src/ui/hooks/useClickOutside.ts +2 -6
- package/src/ui/hooks/useClickOutsideEvent.ts +3 -9
- package/src/ui/primitives/_selectable/selectable.tsx +33 -20
- package/src/ui/primitives/avatar/avatar.tsx +28 -31
- package/src/ui/primitives/avatar/avatarCounter.tsx +33 -25
- package/src/ui/primitives/avatar/avatarStack.tsx +31 -24
- package/src/ui/primitives/avatar/types.ts +2 -0
- package/src/ui/primitives/badge/__workshop__/props.tsx +1 -9
- package/src/ui/primitives/badge/__workshop__/tones.tsx +1 -6
- package/src/ui/primitives/badge/badge.tsx +33 -32
- package/src/ui/primitives/badge/types.ts +2 -1
- package/src/ui/primitives/box/box.tsx +59 -29
- package/src/ui/primitives/button/__workshop__/sanityUploadButton.tsx +3 -3
- package/src/ui/primitives/button/__workshop__/uploadButton.tsx +2 -1
- package/src/ui/primitives/button/button.test.tsx +1 -15
- package/src/ui/primitives/button/button.tsx +64 -70
- package/src/ui/primitives/card/__workshop__/asComponent.tsx +3 -3
- package/src/ui/primitives/card/card.tsx +22 -22
- package/src/ui/primitives/card/cardProvider.tsx +2 -0
- package/src/ui/primitives/checkbox/checkbox.tsx +26 -15
- package/src/ui/primitives/code/code.tsx +24 -22
- package/src/ui/primitives/container/container.tsx +26 -15
- package/src/ui/primitives/flex/flex.tsx +21 -19
- package/src/ui/primitives/grid/grid.tsx +21 -16
- package/src/ui/primitives/heading/heading.tsx +42 -19
- package/src/ui/primitives/inline/inline.tsx +26 -23
- package/src/ui/primitives/kbd/kbd.tsx +25 -23
- package/src/ui/primitives/label/label.tsx +41 -26
- package/src/ui/primitives/popover/popover.tsx +281 -277
- package/src/ui/primitives/popover/popoverCard.tsx +119 -118
- package/src/ui/primitives/radio/radio.tsx +30 -14
- package/src/ui/primitives/select/select.tsx +24 -16
- package/src/ui/primitives/spinner/animatedSpinnerIcon.tsx +4 -2
- package/src/ui/primitives/spinner/spinner.tsx +24 -12
- package/src/ui/primitives/stack/stack.tsx +27 -18
- package/src/ui/primitives/switch/switch.tsx +31 -14
- package/src/ui/primitives/text/text.tsx +42 -24
- package/src/ui/primitives/textArea/textArea.tsx +33 -18
- package/src/ui/primitives/textInput/textInput.tsx +28 -40
- package/src/ui/primitives/tooltip/constants.ts +1 -1
- package/src/ui/primitives/tooltip/tooltip.tsx +76 -59
- package/src/ui/primitives/tooltip/tooltipCard.tsx +89 -82
- package/src/ui/primitives/types.ts +1 -3
- package/src/ui/types/avatar.ts +3 -6
- package/src/ui/types/badge.ts +1 -3
- package/src/ui/types/button.ts +1 -3
- package/src/ui/types/card.ts +1 -3
- package/src/ui/types/dialog.ts +1 -3
- package/src/ui/types/props.ts +20 -10
- package/src/ui/utils/arrow/arrow.tsx +40 -14
- package/src/ui/utils/boundaryElement/boundaryElementProvider.tsx +2 -6
- package/src/ui/utils/boundaryElement/types.ts +1 -3
- package/src/ui/utils/boundaryElement/useBoundaryElement.ts +1 -3
- package/src/ui/utils/elementQuery/elementQuery.tsx +36 -14
- package/src/ui/utils/errorBoundary.tsx +2 -0
- package/src/ui/utils/index.ts +0 -1
- package/src/ui/utils/layer/layer.tsx +23 -93
- package/src/ui/utils/layer/layerCard.tsx +92 -0
- package/src/ui/utils/layer/layerProvider.tsx +2 -6
- package/src/ui/utils/layer/useLayer.ts +1 -3
- package/src/ui/utils/portal/portal.ts +2 -6
- package/src/ui/utils/portal/portalProvider.tsx +2 -6
- package/src/ui/utils/portal/types.ts +1 -3
- package/src/ui/utils/portal/usePortal.ts +1 -3
- package/src/ui/utils/srOnly/srOnly.tsx +25 -20
- package/src/ui/utils/virtualList/virtualList.tsx +36 -24
- package/src/css/compile/compileRule.ts +0 -97
- package/src/css/compile/compileRules.test.ts +0 -36
- package/src/css/compile/compileRules.ts +0 -43
- package/src/css/compile/compileSystem.ts +0 -7
- package/src/css/compile/types.ts +0 -6
- package/src/css/primitives/_selectable/_contants.ts +0 -11
- package/src/css/primitives/card/_constants.ts +0 -13
- package/src/ui/utils/conditionalWrapper/conditionalWrapper.tsx +0 -23
- package/src/ui/utils/conditionalWrapper/index.ts +0 -1
|
@@ -5,45 +5,57 @@ import {
|
|
|
5
5
|
TextOverflowStyleProps,
|
|
6
6
|
TextStyleProps,
|
|
7
7
|
} from '@sanity/ui/css'
|
|
8
|
-
import {ForwardedRef, forwardRef} from 'react'
|
|
9
8
|
|
|
10
|
-
import {Props} from '../../types'
|
|
9
|
+
import {ComponentType, Props} from '../../types'
|
|
11
10
|
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
/** @public */
|
|
12
|
+
export const DEFAULT_TEXT_ELEMENT = 'div'
|
|
13
|
+
|
|
14
|
+
/** @public */
|
|
15
|
+
export type TextOwnProps = TextStyleProps & TextOverflowStyleProps
|
|
16
|
+
|
|
17
|
+
/** @public */
|
|
18
|
+
export type TextElementType =
|
|
19
|
+
| 'div'
|
|
20
|
+
| 'h1'
|
|
21
|
+
| 'h2'
|
|
22
|
+
| 'h3'
|
|
23
|
+
| 'h4'
|
|
24
|
+
| 'h5'
|
|
25
|
+
| 'h6'
|
|
26
|
+
| 'label'
|
|
27
|
+
| 'li'
|
|
28
|
+
| 'p'
|
|
29
|
+
| 'span'
|
|
30
|
+
| ComponentType
|
|
31
|
+
|
|
32
|
+
/** @public */
|
|
33
|
+
export type TextProps<E extends TextElementType = TextElementType> = Props<TextOwnProps, E>
|
|
18
34
|
|
|
19
35
|
/**
|
|
20
36
|
* The `Text` component is an agile, themed typographic element.
|
|
21
37
|
*
|
|
22
38
|
* @public
|
|
23
39
|
*/
|
|
24
|
-
export
|
|
25
|
-
props: Props<TextProps, 'div'>,
|
|
26
|
-
ref: ForwardedRef<HTMLDivElement>,
|
|
27
|
-
) {
|
|
40
|
+
export function Text<E extends TextElementType = typeof DEFAULT_TEXT_ELEMENT>(props: TextProps<E>) {
|
|
28
41
|
const {
|
|
29
|
-
accent
|
|
42
|
+
accent,
|
|
30
43
|
align,
|
|
31
|
-
as:
|
|
44
|
+
as: Element = DEFAULT_TEXT_ELEMENT,
|
|
32
45
|
children,
|
|
33
46
|
className,
|
|
34
47
|
flex,
|
|
35
|
-
muted
|
|
48
|
+
muted,
|
|
36
49
|
size = 2,
|
|
37
50
|
textOverflow: textOverflowProp,
|
|
38
51
|
weight,
|
|
39
|
-
...
|
|
40
|
-
} = props
|
|
52
|
+
...rest
|
|
53
|
+
} = props as TextProps<typeof DEFAULT_TEXT_ELEMENT>
|
|
41
54
|
|
|
42
55
|
return (
|
|
43
|
-
<
|
|
56
|
+
<Element
|
|
44
57
|
data-ui="Text"
|
|
45
|
-
{...
|
|
46
|
-
ref={ref}
|
|
58
|
+
{...rest}
|
|
47
59
|
className={composeClassNames(
|
|
48
60
|
className,
|
|
49
61
|
text({
|
|
@@ -56,9 +68,15 @@ export const Text = forwardRef(function Text(
|
|
|
56
68
|
}),
|
|
57
69
|
)}
|
|
58
70
|
>
|
|
59
|
-
<span
|
|
60
|
-
|
|
71
|
+
<span
|
|
72
|
+
className={textOverflow({
|
|
73
|
+
textOverflow: textOverflowProp,
|
|
74
|
+
})}
|
|
75
|
+
>
|
|
76
|
+
{children}
|
|
77
|
+
</span>
|
|
78
|
+
</Element>
|
|
61
79
|
)
|
|
62
|
-
}
|
|
80
|
+
}
|
|
63
81
|
|
|
64
|
-
Text.displayName = '
|
|
82
|
+
Text.displayName = 'Text'
|
|
@@ -3,18 +3,19 @@ import {
|
|
|
3
3
|
_inputPresentation,
|
|
4
4
|
ResponsiveProp,
|
|
5
5
|
textArea,
|
|
6
|
-
TextAreaStyleProps,
|
|
6
|
+
type TextAreaStyleProps,
|
|
7
7
|
} from '@sanity/ui/css'
|
|
8
|
-
import {Space, ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
9
|
-
import {
|
|
8
|
+
import type {Space, ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
9
|
+
import {useImperativeHandle, useRef} from 'react'
|
|
10
10
|
|
|
11
11
|
import {useCustomValidity} from '../../hooks'
|
|
12
|
-
import {Props} from '../../types'
|
|
12
|
+
import type {ComponentType, Props} from '../../types'
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
/** @public */
|
|
15
|
+
export const DEFAULT_TEXT_AREA_ELEMENT = 'textarea'
|
|
16
|
+
|
|
17
|
+
/** @public */
|
|
18
|
+
export type TextAreaOwnProps = TextAreaStyleProps & {
|
|
18
19
|
/**
|
|
19
20
|
* @beta
|
|
20
21
|
*/
|
|
@@ -25,16 +26,25 @@ export interface TextAreaProps extends TextAreaStyleProps {
|
|
|
25
26
|
weight?: ThemeFontWeightKey
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
/** @public */
|
|
30
|
+
export type TextAreaElementType = 'textarea' | ComponentType
|
|
31
|
+
|
|
32
|
+
/** @public */
|
|
33
|
+
export type TextAreaProps<E extends TextAreaElementType = TextAreaElementType> = Props<
|
|
34
|
+
TextAreaOwnProps,
|
|
35
|
+
E
|
|
36
|
+
>
|
|
37
|
+
|
|
28
38
|
/**
|
|
29
39
|
* A multiline text input.
|
|
30
40
|
*
|
|
31
41
|
* @public
|
|
32
42
|
*/
|
|
33
|
-
export
|
|
34
|
-
props:
|
|
35
|
-
forwardedRef: ForwardedRef<HTMLTextAreaElement>,
|
|
43
|
+
export function TextArea<E extends TextAreaElementType = typeof DEFAULT_TEXT_AREA_ELEMENT>(
|
|
44
|
+
props: TextAreaProps<E>,
|
|
36
45
|
) {
|
|
37
46
|
const {
|
|
47
|
+
as: Element = DEFAULT_TEXT_AREA_ELEMENT,
|
|
38
48
|
border = true,
|
|
39
49
|
customValidity,
|
|
40
50
|
disabled = false,
|
|
@@ -42,11 +52,16 @@ export const TextArea = forwardRef(function TextArea(
|
|
|
42
52
|
gap,
|
|
43
53
|
padding = 3,
|
|
44
54
|
radius = 2,
|
|
55
|
+
ref: forwardedRef,
|
|
45
56
|
space = 3,
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
// TODO: fix this
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59
|
+
weight,
|
|
60
|
+
// TODO: fix this
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
62
|
+
__unstable_disableFocusRing,
|
|
63
|
+
...rest
|
|
64
|
+
} = props as TextAreaProps<typeof DEFAULT_TEXT_AREA_ELEMENT>
|
|
50
65
|
|
|
51
66
|
const ref = useRef<HTMLTextAreaElement | null>(null)
|
|
52
67
|
|
|
@@ -62,10 +77,10 @@ export const TextArea = forwardRef(function TextArea(
|
|
|
62
77
|
className={textArea({border, fontSize, padding, radius, gap: gap ?? space})}
|
|
63
78
|
data-ui="TextArea"
|
|
64
79
|
>
|
|
65
|
-
<
|
|
80
|
+
<Element {...rest} className={_inputElement()} disabled={disabled} ref={ref} />
|
|
66
81
|
<span className={_inputPresentation()} />
|
|
67
82
|
</span>
|
|
68
83
|
)
|
|
69
|
-
}
|
|
84
|
+
}
|
|
70
85
|
|
|
71
|
-
TextArea.displayName = '
|
|
86
|
+
TextArea.displayName = 'TextArea'
|
|
@@ -11,8 +11,6 @@ import {Space, ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
|
11
11
|
import {
|
|
12
12
|
CSSProperties,
|
|
13
13
|
ElementType,
|
|
14
|
-
ForwardedRef,
|
|
15
|
-
forwardRef,
|
|
16
14
|
isValidElement,
|
|
17
15
|
MouseEvent,
|
|
18
16
|
ReactNode,
|
|
@@ -26,41 +24,22 @@ import {isValidElementType} from 'react-is'
|
|
|
26
24
|
import {EMPTY_RECORD} from '../../constants'
|
|
27
25
|
import {useArrayProp, useCustomValidity} from '../../hooks'
|
|
28
26
|
import {isRecord} from '../../lib/isRecord'
|
|
29
|
-
import {Props} from '../../types'
|
|
27
|
+
import {ComponentType, Props} from '../../types'
|
|
30
28
|
import {Box} from '../box'
|
|
31
29
|
import {Button, ButtonProps} from '../button'
|
|
32
30
|
import {Text} from '../text'
|
|
33
31
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
/** @public */
|
|
33
|
+
export const DEFAULT_TEXT_INPUT_ELEMENT = 'input'
|
|
34
|
+
|
|
35
|
+
/** @public */
|
|
37
36
|
export type TextInputClearButtonProps = Omit<
|
|
38
|
-
|
|
37
|
+
ButtonProps<'button'>,
|
|
39
38
|
'as' | 'onClick' | 'onMouseDown'
|
|
40
39
|
>
|
|
41
40
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
*/
|
|
45
|
-
export type TextInputType =
|
|
46
|
-
| 'search'
|
|
47
|
-
| 'date'
|
|
48
|
-
| 'datetime-local'
|
|
49
|
-
| 'email'
|
|
50
|
-
| 'url'
|
|
51
|
-
| 'month'
|
|
52
|
-
| 'number'
|
|
53
|
-
| 'password'
|
|
54
|
-
| 'tel'
|
|
55
|
-
| 'time'
|
|
56
|
-
| 'text'
|
|
57
|
-
| 'week'
|
|
58
|
-
| 'color'
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @public
|
|
62
|
-
*/
|
|
63
|
-
export interface TextInputProps extends InputStyleProps {
|
|
41
|
+
/** @public */
|
|
42
|
+
export type TextInputOwnProps = InputStyleProps & {
|
|
64
43
|
/**
|
|
65
44
|
* @beta
|
|
66
45
|
*/
|
|
@@ -80,10 +59,18 @@ export interface TextInputProps extends InputStyleProps {
|
|
|
80
59
|
/** @deprecated Use `gap` instead. */
|
|
81
60
|
space?: ResponsiveProp<Space>
|
|
82
61
|
suffix?: ReactNode
|
|
83
|
-
type?: TextInputType
|
|
84
62
|
weight?: ThemeFontWeightKey
|
|
85
63
|
}
|
|
86
64
|
|
|
65
|
+
/** @public */
|
|
66
|
+
export type TextInputElementType = 'input' | ComponentType
|
|
67
|
+
|
|
68
|
+
/** @public */
|
|
69
|
+
export type TextInputProps<E extends TextInputElementType = TextInputElementType> = Props<
|
|
70
|
+
TextInputOwnProps,
|
|
71
|
+
E
|
|
72
|
+
>
|
|
73
|
+
|
|
87
74
|
const CLEAR_BUTTON_BOX_STYLE: CSSProperties = {
|
|
88
75
|
backgroundColor: 'transparent',
|
|
89
76
|
top: 0,
|
|
@@ -96,12 +83,12 @@ const CLEAR_BUTTON_BOX_STYLE: CSSProperties = {
|
|
|
96
83
|
*
|
|
97
84
|
* @public
|
|
98
85
|
*/
|
|
99
|
-
export
|
|
100
|
-
props:
|
|
101
|
-
forwardedRef: ForwardedRef<HTMLInputElement>,
|
|
86
|
+
export function TextInput<E extends TextInputElementType = typeof DEFAULT_TEXT_INPUT_ELEMENT>(
|
|
87
|
+
props: TextInputProps<E>,
|
|
102
88
|
) {
|
|
103
89
|
const {
|
|
104
90
|
__unstable_disableFocusRing,
|
|
91
|
+
as: Element = DEFAULT_TEXT_INPUT_ELEMENT,
|
|
105
92
|
border = true,
|
|
106
93
|
className,
|
|
107
94
|
clearButton,
|
|
@@ -115,14 +102,16 @@ export const TextInput = forwardRef(function TextInput(
|
|
|
115
102
|
prefix,
|
|
116
103
|
radius = 2,
|
|
117
104
|
readOnly,
|
|
105
|
+
ref: forwardedRef,
|
|
118
106
|
space = 3,
|
|
119
107
|
suffix,
|
|
120
108
|
customValidity,
|
|
121
109
|
type = 'text',
|
|
122
110
|
weight: _width, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
123
111
|
width,
|
|
124
|
-
...
|
|
125
|
-
} = props
|
|
112
|
+
...rest
|
|
113
|
+
} = props as TextInputProps<typeof DEFAULT_TEXT_INPUT_ELEMENT>
|
|
114
|
+
|
|
126
115
|
const ref = useRef<HTMLInputElement | null>(null)
|
|
127
116
|
|
|
128
117
|
const paddingArray = useArrayProp(padding)
|
|
@@ -213,9 +202,8 @@ export const TextInput = forwardRef(function TextInput(
|
|
|
213
202
|
)}
|
|
214
203
|
|
|
215
204
|
<Box as="span" flex={1} position="relative">
|
|
216
|
-
<
|
|
217
|
-
|
|
218
|
-
{...restProps}
|
|
205
|
+
<Element
|
|
206
|
+
{...rest}
|
|
219
207
|
className={_inputElement()}
|
|
220
208
|
disabled={disabled}
|
|
221
209
|
readOnly={readOnly}
|
|
@@ -281,6 +269,6 @@ export const TextInput = forwardRef(function TextInput(
|
|
|
281
269
|
)}
|
|
282
270
|
</Box>
|
|
283
271
|
)
|
|
284
|
-
}
|
|
272
|
+
}
|
|
285
273
|
|
|
286
|
-
TextInput.displayName = '
|
|
274
|
+
TextInput.displayName = 'TextInput'
|
|
@@ -13,10 +13,12 @@ import type {ThemeColorCardToneKey, ThemeColorSchemeKey} from '@sanity/ui/theme'
|
|
|
13
13
|
import {AnimatePresence} from 'framer-motion'
|
|
14
14
|
import {
|
|
15
15
|
cloneElement,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
type FocusEvent,
|
|
17
|
+
HTMLAttributes,
|
|
18
|
+
type MouseEvent as ReactMouseEvent,
|
|
19
|
+
type ReactElement,
|
|
20
|
+
type ReactNode,
|
|
21
|
+
RefAttributes,
|
|
20
22
|
useCallback,
|
|
21
23
|
useEffect,
|
|
22
24
|
useId,
|
|
@@ -32,11 +34,11 @@ import {Z_OFFSETS} from '../../constants'
|
|
|
32
34
|
import {useArrayProp, usePrefersReducedMotion} from '../../hooks'
|
|
33
35
|
import {useDelayedState} from '../../hooks/useDelayedState'
|
|
34
36
|
import {origin} from '../../middleware/origin'
|
|
35
|
-
import type {Placement, Props} from '../../types'
|
|
36
|
-
import {Layer, type
|
|
37
|
+
import type {ComponentType, Placement, Props} from '../../types'
|
|
38
|
+
import {Layer, type LayerOwnProps, Portal, useBoundaryElement, usePortal} from '../../utils'
|
|
37
39
|
import {getElementRef} from '../../utils/getElementRef'
|
|
38
40
|
import {CardProvider, useCard} from '../card'
|
|
39
|
-
import
|
|
41
|
+
import {Delay} from '../types'
|
|
40
42
|
import {
|
|
41
43
|
DEFAULT_FALLBACK_PLACEMENTS,
|
|
42
44
|
DEFAULT_TOOLTIP_DISTANCE,
|
|
@@ -45,56 +47,69 @@ import {
|
|
|
45
47
|
import {TooltipCard} from './tooltipCard'
|
|
46
48
|
import {useTooltipDelayGroup} from './tooltipDelayGroup'
|
|
47
49
|
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
50
|
+
/** @public */
|
|
51
|
+
export const DEFAULT_TOOLTIP_ELEMENT = 'div'
|
|
52
|
+
|
|
53
|
+
/** @public */
|
|
54
|
+
export type TooltipOwnProps = LayerOwnProps &
|
|
55
|
+
RadiusStyleProps &
|
|
56
|
+
ShadowStyleProps & {
|
|
57
|
+
/** @deprecated Use `fallbackPlacements` instead. */
|
|
58
|
+
allowedAutoPlacements?: Placement[]
|
|
59
|
+
/**
|
|
60
|
+
* Whether the tooltip should animate in and out.
|
|
61
|
+
*
|
|
62
|
+
* @beta
|
|
63
|
+
* @defaultValue false
|
|
64
|
+
*/
|
|
65
|
+
animate?: boolean
|
|
66
|
+
arrow?: boolean
|
|
67
|
+
boundaryElement?: HTMLElement | null
|
|
68
|
+
children?: ReactElement<HTMLAttributes<HTMLElement> & RefAttributes<HTMLElement>>
|
|
69
|
+
content?: ReactNode
|
|
70
|
+
/**
|
|
71
|
+
* Adds a delay to open or close the tooltip.
|
|
72
|
+
*
|
|
73
|
+
* If only a `number` is passed, it will be used for both opening and closing.
|
|
74
|
+
*
|
|
75
|
+
* If an object `{open: number; close:number}` is passed, it can be used to set different delays for each action.
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
* @defaultValue 0
|
|
79
|
+
*/
|
|
80
|
+
delay?: Delay
|
|
81
|
+
disabled?: boolean
|
|
82
|
+
fallbackPlacements?: Placement[]
|
|
83
|
+
placement?: Placement
|
|
84
|
+
/** Whether or not to render the tooltip in a portal element. */
|
|
85
|
+
portal?: boolean | string
|
|
86
|
+
scheme?: ThemeColorSchemeKey
|
|
87
|
+
tone?: ThemeColorCardToneKey
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** @public */
|
|
91
|
+
export type TooltipElementType = 'div' | 'span' | ComponentType
|
|
92
|
+
|
|
93
|
+
/** @public */
|
|
94
|
+
export type TooltipProps<E extends TooltipElementType = TooltipElementType> = Props<
|
|
95
|
+
TooltipOwnProps,
|
|
96
|
+
E
|
|
97
|
+
>
|
|
84
98
|
|
|
85
99
|
/**
|
|
86
100
|
* Tooltips display information when hovering, focusing or tapping.
|
|
87
101
|
*
|
|
88
102
|
* @public
|
|
89
103
|
*/
|
|
90
|
-
export
|
|
91
|
-
props:
|
|
92
|
-
forwardedRef: ForwardedRef<HTMLDivElement>,
|
|
104
|
+
export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_ELEMENT>(
|
|
105
|
+
props: TooltipProps<E>,
|
|
93
106
|
) {
|
|
94
107
|
const boundaryElementContext = useBoundaryElement()
|
|
108
|
+
|
|
95
109
|
const {
|
|
96
110
|
animate: _animate = false,
|
|
97
111
|
arrow: arrowProp = false,
|
|
112
|
+
as = DEFAULT_TOOLTIP_ELEMENT,
|
|
98
113
|
boundaryElement = boundaryElementContext?.element,
|
|
99
114
|
children: childProp,
|
|
100
115
|
className,
|
|
@@ -107,12 +122,14 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
107
122
|
placement: placementProp = 'bottom',
|
|
108
123
|
portal: portalProp,
|
|
109
124
|
radius = 3,
|
|
125
|
+
ref: forwardedRef,
|
|
110
126
|
scheme,
|
|
111
127
|
shadow = 2,
|
|
112
128
|
zOffset = Z_OFFSETS.tooltip,
|
|
113
129
|
tone = 'inherit',
|
|
114
|
-
...
|
|
115
|
-
} = props
|
|
130
|
+
...rest
|
|
131
|
+
} = props as TooltipProps<typeof DEFAULT_TOOLTIP_ELEMENT>
|
|
132
|
+
|
|
116
133
|
const card = useCard()
|
|
117
134
|
const prefersReducedMotion = usePrefersReducedMotion()
|
|
118
135
|
const animate = prefersReducedMotion ? false : _animate
|
|
@@ -230,42 +247,42 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
230
247
|
)
|
|
231
248
|
|
|
232
249
|
const handleBlur = useCallback(
|
|
233
|
-
(e: FocusEvent) => {
|
|
250
|
+
(e: FocusEvent<HTMLElement>) => {
|
|
234
251
|
handleIsOpenChange(false)
|
|
235
252
|
childProp?.props?.onBlur?.(e)
|
|
236
253
|
},
|
|
237
254
|
[childProp?.props, handleIsOpenChange],
|
|
238
255
|
)
|
|
239
256
|
const handleClick = useCallback(
|
|
240
|
-
(e:
|
|
257
|
+
(e: ReactMouseEvent<HTMLElement>) => {
|
|
241
258
|
handleIsOpenChange(false, true)
|
|
242
259
|
childProp?.props.onClick?.(e)
|
|
243
260
|
},
|
|
244
261
|
[childProp?.props, handleIsOpenChange],
|
|
245
262
|
)
|
|
246
263
|
const handleContextMenu = useCallback(
|
|
247
|
-
(e:
|
|
264
|
+
(e: ReactMouseEvent<HTMLElement>) => {
|
|
248
265
|
handleIsOpenChange(false, true)
|
|
249
266
|
childProp?.props.onContextMenu?.(e)
|
|
250
267
|
},
|
|
251
268
|
[childProp?.props, handleIsOpenChange],
|
|
252
269
|
)
|
|
253
270
|
const handleFocus = useCallback(
|
|
254
|
-
(e: FocusEvent) => {
|
|
271
|
+
(e: FocusEvent<HTMLElement>) => {
|
|
255
272
|
handleIsOpenChange(true)
|
|
256
273
|
childProp?.props?.onFocus?.(e)
|
|
257
274
|
},
|
|
258
275
|
[childProp?.props, handleIsOpenChange],
|
|
259
276
|
)
|
|
260
277
|
const handleMouseEnter = useCallback(
|
|
261
|
-
(e:
|
|
278
|
+
(e: ReactMouseEvent<HTMLElement>) => {
|
|
262
279
|
handleIsOpenChange(true)
|
|
263
280
|
childProp?.props?.onMouseEnter?.(e)
|
|
264
281
|
},
|
|
265
282
|
[childProp?.props, handleIsOpenChange],
|
|
266
283
|
)
|
|
267
284
|
const handleMouseLeave = useCallback(
|
|
268
|
-
(e:
|
|
285
|
+
(e: ReactMouseEvent<HTMLElement>) => {
|
|
269
286
|
handleIsOpenChange(false)
|
|
270
287
|
childProp?.props?.onMouseLeave?.(e)
|
|
271
288
|
},
|
|
@@ -366,7 +383,6 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
366
383
|
const node = (
|
|
367
384
|
<Layer
|
|
368
385
|
data-ui="Tooltip"
|
|
369
|
-
// {...restProps}
|
|
370
386
|
className={composeClassNames(className, tooltip())}
|
|
371
387
|
ref={setFloating}
|
|
372
388
|
style={{
|
|
@@ -376,12 +392,13 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
376
392
|
zOffset={zOffset}
|
|
377
393
|
>
|
|
378
394
|
<TooltipCard
|
|
379
|
-
{...
|
|
395
|
+
{...rest}
|
|
380
396
|
animate={animate}
|
|
381
397
|
arrow={arrowProp}
|
|
382
398
|
arrowRef={setArrow}
|
|
383
399
|
arrowX={arrowX}
|
|
384
400
|
arrowY={arrowY}
|
|
401
|
+
as={as}
|
|
385
402
|
originX={originX}
|
|
386
403
|
originY={originY}
|
|
387
404
|
padding={padding}
|
|
@@ -421,9 +438,7 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
421
438
|
{child}
|
|
422
439
|
</>
|
|
423
440
|
)
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
Tooltip.displayName = 'ForwardRef(Tooltip)'
|
|
441
|
+
}
|
|
427
442
|
|
|
428
443
|
/**
|
|
429
444
|
* As `useEffectEvent` should never be passed to other components or hooks, this custom hook groups together the `useEffectEvent` and the `useEffect` hook using it.
|
|
@@ -471,3 +486,5 @@ function useCloseOnMouseLeave({
|
|
|
471
486
|
return () => window.removeEventListener('mousemove', handleMouseMove)
|
|
472
487
|
}, [isInsideGroup, showTooltip])
|
|
473
488
|
}
|
|
489
|
+
|
|
490
|
+
Tooltip.displayName = 'Tooltip'
|