@sanity/ui 3.0.0-static.10 → 3.0.0-static.12
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 +1300 -1269
- 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 +1298 -1263
- package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
- package/dist/_visual-editing.d.mts +516 -360
- package/dist/_visual-editing.d.ts +516 -360
- package/dist/cli.js +1 -1
- package/dist/css.d.mts +258 -75
- package/dist/css.d.ts +258 -75
- package/dist/css.js +746 -752
- package/dist/css.js.map +1 -1
- package/dist/css.mjs +748 -754
- package/dist/css.mjs.map +1 -1
- package/dist/index.d.mts +1342 -871
- package/dist/index.d.ts +1342 -871
- package/dist/index.js +433 -325
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +429 -321
- 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 -21710
- 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 +19 -20
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +19 -20
- 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/_resp.ts +0 -1
- 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/font.style.ts +7 -66
- 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.style.ts +16 -41
- 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/compilePalette.ts +32 -0
- package/src/css/compileSystem.ts +7 -0
- package/src/css/{compile/compileTheme.ts → compileTheme.ts} +1 -0
- package/src/css/compileTheme_v3.ts +434 -0
- 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.style.ts +8 -4
- 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 +11 -0
- package/src/css/index.ts +4 -3
- package/src/css/primitives/_arrow/_arrow.style.ts +6 -8
- package/src/css/primitives/_arrow/_arrow.ts +7 -0
- package/src/css/primitives/_input/input.ts +2 -0
- package/src/css/primitives/_selectable/_selectable.style.ts +24 -25
- 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.style.ts +48 -15
- 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 +4 -7
- 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/token/token.style.ts +37 -36
- package/src/css/primitives/tooltip/tooltip.ts +2 -0
- package/src/css/responsiveRules.ts +12 -19
- package/src/css/scopeClassName.ts +1 -0
- package/src/css/types.ts +115 -15
- package/src/css/util.ts +5 -0
- package/src/css/utils/srOnly/srOnly.ts +1 -0
- package/src/css/varNames.ts +230 -143
- package/src/css/vars.ts +53 -22
- 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 +2 -1
- package/src/theme/v3/color/color.ts +6 -4
- package/src/theme/v3/color/renderColor.ts +4 -1
- package/src/theme/v3/{defaults.ts → defaultTokens.ts} +2 -2
- package/src/theme/v3/index.ts +1 -1
- package/src/theme/v3/resolveTokens.ts +18 -18
- package/src/ui/RootClassNames.tsx +44 -0
- package/src/ui/StyleTags.tsx +3 -1
- package/src/ui/_compat/helpers.ts +72 -0
- package/src/ui/_compat/index.ts +2 -6
- package/src/ui/_compat/studioTheme.ts +7 -0
- 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/_compat/types.ts +0 -83
- 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/index.ts +1 -0
- 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 +63 -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 +29 -26
- package/src/ui/primitives/popover/popover.tsx +293 -271
- package/src/ui/primitives/popover/popoverCard.tsx +122 -120
- 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 +30 -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 +85 -61
- 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 +43 -25
- 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 +43 -19
- 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 +69 -50
- package/src/css/compile/compilePalette.ts +0 -27
- 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 -10
- package/src/css/compile/compileTheme_v3.ts +0 -401
- package/src/css/compile/types.ts +0 -6
- package/src/css/components/breadcrumbs/rules.ts +0 -25
- package/src/css/components/dialog/rules.ts +0 -78
- package/src/css/components/skeleton/rules.ts +0 -113
- package/src/css/components/toast/rules.ts +0 -18
- package/src/css/components/tree/rules.ts +0 -168
- package/src/css/primitives/_selectable/_contants.ts +0 -11
- package/src/css/primitives/card/_constants.ts +0 -13
- package/src/css/primitives/popover/rules.ts +0 -5
- package/src/css/primitives/spinner/rules.ts +0 -21
- package/src/css/primitives/token/rules.ts +0 -45
- package/src/ui/utils/conditionalWrapper/conditionalWrapper.tsx +0 -23
- package/src/ui/utils/conditionalWrapper/index.ts +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {card, scopeClassName as _} from '@sanity/ui/css'
|
|
2
|
+
import {useEffect} from 'react'
|
|
3
|
+
|
|
4
|
+
import {_raf2} from './helpers'
|
|
5
|
+
import {useCard} from './primitives'
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
export function RootClassNames(props: {element: HTMLElement}) {
|
|
9
|
+
const {element} = props
|
|
10
|
+
const {scheme, tone} = useCard() ?? {}
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const els = document.querySelectorAll(
|
|
14
|
+
[_('button'), _('card'), _('font')].map((n) => `.${n}`).join(', '),
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
// temporarily disable all transitions when the theme changes
|
|
18
|
+
for (const el of els) {
|
|
19
|
+
if (el instanceof HTMLElement) {
|
|
20
|
+
el.style.transition = 'none'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
_raf2(() => {
|
|
25
|
+
document.documentElement.className = card({scheme, tone}) ?? ''
|
|
26
|
+
|
|
27
|
+
_raf2(() => {
|
|
28
|
+
for (const el of els) {
|
|
29
|
+
if (el instanceof HTMLElement) {
|
|
30
|
+
el.style.transition = ''
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return () => {
|
|
37
|
+
document.documentElement.className = ''
|
|
38
|
+
}
|
|
39
|
+
}, [element, scheme, tone])
|
|
40
|
+
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
RootClassNames.displayName = 'RootClassNames'
|
package/src/ui/StyleTags.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import {compilePalette, compileSystem, compileTheme} from '@sanity/ui/css'
|
|
|
2
2
|
import {buildTheme_v3, RootTheme, Theme_v3} from '@sanity/ui/theme'
|
|
3
3
|
import {ReactNode} from 'react'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/** @beta */
|
|
6
6
|
export function StyleTags(props: {theme?: Theme_v3}): ReactNode {
|
|
7
7
|
const {theme: themeProp} = props
|
|
8
8
|
|
|
@@ -22,3 +22,5 @@ export function StyleTags(props: {theme?: Theme_v3}): ReactNode {
|
|
|
22
22
|
</>
|
|
23
23
|
)
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
StyleTags.displayName = 'StyleTags'
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createColorTheme as _createColorTheme,
|
|
3
|
+
hexToRgb as _hexToRgb,
|
|
4
|
+
hslToRgb as _hslToRgb,
|
|
5
|
+
multiply as _multiply,
|
|
6
|
+
parseColor as _parseColor,
|
|
7
|
+
rgba as _rgba,
|
|
8
|
+
rgbToHex as _rgbToHex,
|
|
9
|
+
rgbToHsl as _rgbToHsl,
|
|
10
|
+
screen as _screen,
|
|
11
|
+
} from '@sanity/ui/theme'
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
/** @deprecated use `px` from `@sanity/ui/css` */
|
|
15
|
+
px,
|
|
16
|
+
/** @deprecated use `rem` from `@sanity/ui/css` */
|
|
17
|
+
rem,
|
|
18
|
+
} from '@sanity/ui/css'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
* @deprecated Use `createColorTheme` from `@sanity/ui/theme` instead.
|
|
23
|
+
*/
|
|
24
|
+
export const createColorTheme = _createColorTheme
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
* @deprecated Use `hexToRgb` from `@sanity/ui/theme` instead.
|
|
29
|
+
*/
|
|
30
|
+
export const hexToRgb = _hexToRgb
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
* @deprecated Use `hslToRgb` from `@sanity/ui/theme` instead.
|
|
35
|
+
*/
|
|
36
|
+
export const hslToRgb = _hslToRgb
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
* @deprecated Use `multiply` from `@sanity/ui/theme` instead.
|
|
41
|
+
*/
|
|
42
|
+
export const multiply = _multiply
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @public
|
|
46
|
+
* @deprecated Use `parseColor` from `@sanity/ui/theme` instead.
|
|
47
|
+
*/
|
|
48
|
+
export const parseColor = _parseColor
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @public
|
|
52
|
+
* @deprecated Use `rgbToHex` from `@sanity/ui/theme` instead.
|
|
53
|
+
*/
|
|
54
|
+
export const rgbToHex = _rgbToHex
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @public
|
|
58
|
+
* @deprecated Use `rgbToHsl` from `@sanity/ui/theme` instead.
|
|
59
|
+
*/
|
|
60
|
+
export const rgbToHsl = _rgbToHsl
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @public
|
|
64
|
+
* @deprecated Use `rgba` from `@sanity/ui/theme` instead.
|
|
65
|
+
*/
|
|
66
|
+
export const rgba = _rgba
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @public
|
|
70
|
+
* @deprecated Use `screen` from `@sanity/ui/theme` instead.
|
|
71
|
+
*/
|
|
72
|
+
export const screen = _screen
|
package/src/ui/_compat/index.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
+
export * from './helpers'
|
|
2
|
+
export * from './studioTheme'
|
|
1
3
|
export * from './styles'
|
|
2
4
|
export * from './theme'
|
|
3
5
|
export * from './types'
|
|
4
|
-
export {
|
|
5
|
-
/** @deprecated use `px` from `@sanity/ui/css` */
|
|
6
|
-
px,
|
|
7
|
-
/** @deprecated use `rem` from `@sanity/ui/css` */
|
|
8
|
-
rem,
|
|
9
|
-
} from '@sanity/ui/css'
|
|
@@ -4,18 +4,14 @@ import {ReactElement, ReactNode} from 'react'
|
|
|
4
4
|
import {ThemeProvider} from './themeProvider'
|
|
5
5
|
import {useRootTheme} from './useRootTheme'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
7
|
+
/** @public */
|
|
10
8
|
export interface ThemeColorProviderProps {
|
|
11
9
|
children?: ReactNode
|
|
12
10
|
scheme?: ThemeColorSchemeKey
|
|
13
11
|
tone?: ThemeColorCardToneKey
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
/**
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
14
|
+
/** @public */
|
|
19
15
|
export function ThemeColorProvider(props: ThemeColorProviderProps): ReactElement {
|
|
20
16
|
const {children, scheme, tone} = props
|
|
21
17
|
const root = useRootTheme()
|
|
@@ -13,9 +13,7 @@ import {ThemeColorProvider} from './themeColorProvider'
|
|
|
13
13
|
import {ThemeContext} from './themeContext'
|
|
14
14
|
import {ThemeContextValue} from './types'
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
16
|
+
/** @public */
|
|
19
17
|
export interface ThemeProviderProps {
|
|
20
18
|
children?: ReactNode
|
|
21
19
|
scheme?: ThemeColorSchemeKey
|
|
@@ -23,9 +21,7 @@ export interface ThemeProviderProps {
|
|
|
23
21
|
tone?: ThemeColorCardToneKey
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
/**
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
24
|
+
/** @public */
|
|
29
25
|
export function ThemeProvider(props: ThemeProviderProps): ReactElement {
|
|
30
26
|
const parentTheme = useContext(ThemeContext)
|
|
31
27
|
const {children} = props
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import {getTheme_v2, Theme, Theme_v2} from '@sanity/ui/theme'
|
|
2
2
|
import {useTheme as useStyledTheme} from 'styled-components'
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
4
|
+
/** @public */
|
|
7
5
|
export function useTheme(): Theme {
|
|
8
6
|
return useStyledTheme() as Theme
|
|
9
7
|
}
|
|
10
8
|
|
|
11
|
-
/**
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
9
|
+
/** @public */
|
|
14
10
|
export function useTheme_v2(): Theme_v2 {
|
|
15
11
|
return getTheme_v2(useStyledTheme() as Theme)
|
|
16
12
|
}
|
package/src/ui/_compat/types.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
type BaseTheme as _BaseTheme,
|
|
5
|
-
buildTheme,
|
|
6
5
|
type HSL as _HSL,
|
|
7
6
|
type PartialThemeColorBuilderOpts,
|
|
8
7
|
type RGB as _RGB,
|
|
@@ -190,85 +189,3 @@ export {
|
|
|
190
189
|
type ThemeColorToneKey,
|
|
191
190
|
type ThemeInput,
|
|
192
191
|
}
|
|
193
|
-
|
|
194
|
-
import {
|
|
195
|
-
createColorTheme as _createColorTheme,
|
|
196
|
-
hexToRgb as _hexToRgb,
|
|
197
|
-
hslToRgb as _hslToRgb,
|
|
198
|
-
multiply as _multiply,
|
|
199
|
-
parseColor as _parseColor,
|
|
200
|
-
rgba as _rgba,
|
|
201
|
-
rgbToHex as _rgbToHex,
|
|
202
|
-
rgbToHsl as _rgbToHsl,
|
|
203
|
-
screen as _screen,
|
|
204
|
-
} from '@sanity/ui/theme'
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @public
|
|
208
|
-
* @deprecated Use `createColorTheme` from `@sanity/ui/theme` instead.
|
|
209
|
-
*/
|
|
210
|
-
export const createColorTheme = _createColorTheme
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* @public
|
|
214
|
-
* @deprecated Use `hexToRgb` from `@sanity/ui/theme` instead.
|
|
215
|
-
*/
|
|
216
|
-
export const hexToRgb = _hexToRgb
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* @public
|
|
220
|
-
* @deprecated Use `hslToRgb` from `@sanity/ui/theme` instead.
|
|
221
|
-
*/
|
|
222
|
-
export const hslToRgb = _hslToRgb
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* @public
|
|
226
|
-
* @deprecated Use `multiply` from `@sanity/ui/theme` instead.
|
|
227
|
-
*/
|
|
228
|
-
export const multiply = _multiply
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* @public
|
|
232
|
-
* @deprecated Use `parseColor` from `@sanity/ui/theme` instead.
|
|
233
|
-
*/
|
|
234
|
-
export const parseColor = _parseColor
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* @public
|
|
238
|
-
* @deprecated Use `rgbToHex` from `@sanity/ui/theme` instead.
|
|
239
|
-
*/
|
|
240
|
-
export const rgbToHex = _rgbToHex
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* @public
|
|
244
|
-
* @deprecated Use `rgbToHsl` from `@sanity/ui/theme` instead.
|
|
245
|
-
*/
|
|
246
|
-
export const rgbToHsl = _rgbToHsl
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @public
|
|
250
|
-
* @deprecated Use `rgba` from `@sanity/ui/theme` instead.
|
|
251
|
-
*/
|
|
252
|
-
export const rgba = _rgba
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* @public
|
|
256
|
-
* @deprecated Use `screen` from `@sanity/ui/theme` instead.
|
|
257
|
-
*/
|
|
258
|
-
export const screen = _screen
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* @public
|
|
262
|
-
* @deprecated Use `buildTheme` from `@sanity/ui/theme` instead.
|
|
263
|
-
*/
|
|
264
|
-
export const studioTheme = (() => {
|
|
265
|
-
let theme: ReturnType<typeof buildTheme> | undefined
|
|
266
|
-
return {
|
|
267
|
-
get value() {
|
|
268
|
-
if (!theme) {
|
|
269
|
-
theme = buildTheme()
|
|
270
|
-
}
|
|
271
|
-
return theme
|
|
272
|
-
},
|
|
273
|
-
}
|
|
274
|
-
})()
|
|
@@ -83,13 +83,13 @@ function ConstrainedHeightExampleField({id, label}: {id: string; label: string})
|
|
|
83
83
|
},
|
|
84
84
|
popoverRef: React.Ref<HTMLDivElement>,
|
|
85
85
|
) => {
|
|
86
|
-
const {hidden, inputElement, ...
|
|
86
|
+
const {hidden, inputElement, ...rest} = popoverProps
|
|
87
87
|
|
|
88
88
|
if (hidden) return null
|
|
89
89
|
|
|
90
90
|
return (
|
|
91
91
|
<Popover
|
|
92
|
-
{...
|
|
92
|
+
{...rest}
|
|
93
93
|
arrow={false}
|
|
94
94
|
constrainSize
|
|
95
95
|
matchReferenceWidth
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import {ChevronDownIcon} from '@sanity/icons'
|
|
2
2
|
import {ResponsiveProp} from '@sanity/ui/css'
|
|
3
|
-
import {
|
|
3
|
+
import {Space} from '@sanity/ui/theme'
|
|
4
4
|
import {
|
|
5
|
-
ChangeEvent,
|
|
5
|
+
type ChangeEvent,
|
|
6
6
|
cloneElement,
|
|
7
|
-
ElementType,
|
|
8
|
-
FocusEvent,
|
|
9
|
-
ForwardedRef,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
ReactElement,
|
|
14
|
-
ReactNode,
|
|
7
|
+
type ElementType,
|
|
8
|
+
type FocusEvent,
|
|
9
|
+
type ForwardedRef,
|
|
10
|
+
type KeyboardEvent,
|
|
11
|
+
type MouseEvent,
|
|
12
|
+
type ReactNode,
|
|
15
13
|
useCallback,
|
|
16
14
|
useEffect,
|
|
17
15
|
useImperativeHandle,
|
|
@@ -29,14 +27,14 @@ import {
|
|
|
29
27
|
Button,
|
|
30
28
|
Card,
|
|
31
29
|
Popover,
|
|
32
|
-
PopoverProps,
|
|
30
|
+
type PopoverProps,
|
|
33
31
|
Stack,
|
|
34
32
|
Text,
|
|
35
33
|
TextInput,
|
|
34
|
+
TextInputOwnProps,
|
|
36
35
|
} from '../../primitives'
|
|
37
|
-
// import {Selectable} from '../../primitives/_selectable'
|
|
38
36
|
import {AnimatedSpinnerIcon} from '../../primitives/spinner/animatedSpinnerIcon'
|
|
39
|
-
import {Props, Radius} from '../../types'
|
|
37
|
+
import type {ComponentType, Props, Radius} from '../../types'
|
|
40
38
|
import {AutocompleteOption} from './autocompleteOption'
|
|
41
39
|
import {autocompleteReducer} from './autocompleteReducer'
|
|
42
40
|
import {
|
|
@@ -44,58 +42,62 @@ import {
|
|
|
44
42
|
AUTOCOMPLETE_POPOVER_FALLBACK_PLACEMENTS,
|
|
45
43
|
AUTOCOMPLETE_POPOVER_PLACEMENT,
|
|
46
44
|
} from './constants'
|
|
47
|
-
import {AutocompleteOpenButtonProps, BaseAutocompleteOption} from './types'
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
45
|
+
import type {AutocompleteOpenButtonProps, BaseAutocompleteOption} from './types'
|
|
46
|
+
|
|
47
|
+
/** @public */
|
|
48
|
+
export const DEFAULT_AUTOCOMPLETE_ELEMENT = 'input'
|
|
49
|
+
|
|
50
|
+
/** @public */
|
|
51
|
+
export type AutocompleteOwnProps<O extends BaseAutocompleteOption = BaseAutocompleteOption> =
|
|
52
|
+
TextInputOwnProps & {
|
|
53
|
+
border?: boolean
|
|
54
|
+
customValidity?: string
|
|
55
|
+
filterOption?: (query: string, option: O) => boolean
|
|
56
|
+
icon?: ElementType | ReactNode
|
|
57
|
+
/** @beta */
|
|
58
|
+
listBox?: BoxProps
|
|
59
|
+
loading?: boolean
|
|
60
|
+
onChange?: (value: string) => void
|
|
61
|
+
onQueryChange?: (query: string | null) => void
|
|
62
|
+
onSelect?: (value: string) => void
|
|
63
|
+
/** @beta */
|
|
64
|
+
openButton?: boolean | AutocompleteOpenButtonProps
|
|
65
|
+
/** @beta */
|
|
66
|
+
openOnFocus?: boolean
|
|
67
|
+
/** The options to render. */
|
|
68
|
+
options?: O[]
|
|
69
|
+
padding?: ResponsiveProp<Space>
|
|
70
|
+
popover?: Omit<Props<PopoverProps, 'div'>, 'content' | 'onMouseEnter' | 'onMouseLeave' | 'open'>
|
|
71
|
+
prefix?: ReactNode
|
|
72
|
+
radius?: Radius | Radius[]
|
|
73
|
+
/** @beta */
|
|
74
|
+
relatedElements?: HTMLElement[]
|
|
75
|
+
/** The callback function for rendering each option. */
|
|
76
|
+
renderOption?: (option: O) => React.JSX.Element
|
|
77
|
+
/** @beta */
|
|
78
|
+
renderPopover?: (
|
|
79
|
+
props: {
|
|
80
|
+
content: React.JSX.Element | null
|
|
81
|
+
hidden: boolean
|
|
82
|
+
inputElement: HTMLInputElement | null
|
|
83
|
+
onMouseEnter: () => void
|
|
84
|
+
onMouseLeave: () => void
|
|
85
|
+
},
|
|
86
|
+
ref: ForwardedRef<HTMLDivElement>,
|
|
87
|
+
) => ReactNode
|
|
88
|
+
renderValue?: (value: string, option?: O) => string
|
|
89
|
+
suffix?: ReactNode
|
|
90
|
+
value?: string
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @public */
|
|
94
|
+
export type AutocompleteElementType = 'input' | ComponentType
|
|
95
|
+
|
|
96
|
+
/** @public */
|
|
97
|
+
export type AutocompleteProps<
|
|
98
|
+
E extends AutocompleteElementType = AutocompleteElementType,
|
|
99
|
+
O extends BaseAutocompleteOption = BaseAutocompleteOption,
|
|
100
|
+
> = Props<AutocompleteOwnProps<O>, E>
|
|
99
101
|
|
|
100
102
|
const DEFAULT_RENDER_VALUE = (value: string, option?: BaseAutocompleteOption) =>
|
|
101
103
|
option ? option.value : value
|
|
@@ -103,27 +105,18 @@ const DEFAULT_RENDER_VALUE = (value: string, option?: BaseAutocompleteOption) =>
|
|
|
103
105
|
const DEFAULT_FILTER_OPTION = (query: string, option: BaseAutocompleteOption) =>
|
|
104
106
|
option.value.toLowerCase().indexOf(query.toLowerCase()) > -1
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
| 'autoCapitalize'
|
|
117
|
-
| 'autoComplete'
|
|
118
|
-
| 'autoCorrect'
|
|
119
|
-
| 'inputMode'
|
|
120
|
-
| 'role'
|
|
121
|
-
| 'spellCheck'
|
|
122
|
-
| 'type'
|
|
123
|
-
>,
|
|
124
|
-
forwardedRef: ForwardedRef<HTMLInputElement>,
|
|
125
|
-
) {
|
|
108
|
+
/**
|
|
109
|
+
* The Autocomplete component is typically used for search components.
|
|
110
|
+
* It consists of a text input for writing a query, and properties for rendering suggestions.
|
|
111
|
+
*
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
export function Autocomplete<
|
|
115
|
+
E extends AutocompleteElementType = typeof DEFAULT_AUTOCOMPLETE_ELEMENT,
|
|
116
|
+
O extends BaseAutocompleteOption = BaseAutocompleteOption,
|
|
117
|
+
>(props: AutocompleteProps<E, O>) {
|
|
126
118
|
const {
|
|
119
|
+
as = DEFAULT_AUTOCOMPLETE_ELEMENT,
|
|
127
120
|
border = true,
|
|
128
121
|
customValidity,
|
|
129
122
|
disabled,
|
|
@@ -146,14 +139,15 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
146
139
|
prefix,
|
|
147
140
|
radius = 2,
|
|
148
141
|
readOnly,
|
|
142
|
+
ref: forwardedRef,
|
|
149
143
|
relatedElements,
|
|
150
144
|
renderOption: renderOptionProp,
|
|
151
145
|
renderPopover,
|
|
152
146
|
renderValue = DEFAULT_RENDER_VALUE,
|
|
153
147
|
suffix,
|
|
154
148
|
value: valueProp,
|
|
155
|
-
...
|
|
156
|
-
} = props
|
|
149
|
+
...rest
|
|
150
|
+
} = props as AutocompleteProps<typeof DEFAULT_AUTOCOMPLETE_ELEMENT, O>
|
|
157
151
|
|
|
158
152
|
const [state, dispatch] = useReducer(autocompleteReducer, {
|
|
159
153
|
activeValue: valueProp || null,
|
|
@@ -186,7 +180,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
186
180
|
const rootElementRef = useRef<HTMLDivElement | null>(null)
|
|
187
181
|
const resultsPopoverElementRef = useRef<HTMLDivElement | null>(null)
|
|
188
182
|
const inputElementRef = useRef<HTMLInputElement | null>(null)
|
|
189
|
-
const listBoxElementRef = useRef<
|
|
183
|
+
const listBoxElementRef = useRef<HTMLUListElement | null>(null)
|
|
190
184
|
|
|
191
185
|
// Value refs
|
|
192
186
|
const listFocusedRef = useRef(false)
|
|
@@ -535,7 +529,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
535
529
|
|
|
536
530
|
const input = (
|
|
537
531
|
<TextInput
|
|
538
|
-
{...
|
|
532
|
+
{...rest}
|
|
539
533
|
aria-activedescendant={activeItemId}
|
|
540
534
|
aria-autocomplete="list"
|
|
541
535
|
aria-expanded={expanded}
|
|
@@ -543,6 +537,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
543
537
|
autoCapitalize="off"
|
|
544
538
|
autoComplete="off"
|
|
545
539
|
autoCorrect="off"
|
|
540
|
+
as={as}
|
|
546
541
|
border={border}
|
|
547
542
|
clearButton={clearButton}
|
|
548
543
|
customValidity={customValidity}
|
|
@@ -694,29 +689,6 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
694
689
|
{results}
|
|
695
690
|
</div>
|
|
696
691
|
)
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
InnerAutocomplete.displayName = 'ForwardRef(Autocomplete)'
|
|
692
|
+
}
|
|
700
693
|
|
|
701
|
-
|
|
702
|
-
* The Autocomplete component is typically used for search components.
|
|
703
|
-
* It consists of a text input for writing a query, and properties for rendering suggestions.
|
|
704
|
-
*
|
|
705
|
-
* @public
|
|
706
|
-
*/
|
|
707
|
-
export const Autocomplete = InnerAutocomplete as <Option extends BaseAutocompleteOption>(
|
|
708
|
-
props: Omit<
|
|
709
|
-
Props<AutocompleteProps<Option>, 'input'>,
|
|
710
|
-
| 'aria-activedescendant'
|
|
711
|
-
| 'aria-autocomplete'
|
|
712
|
-
| 'aria-expanded'
|
|
713
|
-
| 'aria-owns'
|
|
714
|
-
| 'autoCapitalize'
|
|
715
|
-
| 'autoComplete'
|
|
716
|
-
| 'autoCorrect'
|
|
717
|
-
| 'inputMode'
|
|
718
|
-
| 'role'
|
|
719
|
-
| 'spellCheck'
|
|
720
|
-
| 'type'
|
|
721
|
-
>,
|
|
722
|
-
) => ReactElement
|
|
694
|
+
Autocomplete.displayName = 'Autocomplete'
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import {ButtonProps} from '../../primitives'
|
|
2
|
-
import {Props} from '../../types'
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export type AutocompleteOpenButtonProps = Omit<Props<ButtonProps, 'button'>, 'as'>
|
|
3
|
+
/** @public */
|
|
4
|
+
export type AutocompleteOpenButtonProps = Omit<ButtonProps<'button'>, 'as'>
|
|
8
5
|
|
|
9
|
-
/**
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
6
|
+
/** @public */
|
|
12
7
|
export interface BaseAutocompleteOption {
|
|
13
8
|
value: string
|
|
14
9
|
}
|