@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
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
import {_selectable, composeClassNames, SelectableStyleProps} from '@sanity/ui/css'
|
|
2
|
-
import {ForwardedRef, forwardRef} from 'react'
|
|
3
2
|
|
|
4
|
-
import {Props, SelectableTone} from '../../types'
|
|
5
|
-
import {Box,
|
|
3
|
+
import type {ComponentType, Props, SelectableTone} from '../../types'
|
|
4
|
+
import {Box, BoxOwnProps} from '../box'
|
|
6
5
|
|
|
7
6
|
/** @internal */
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
export const DEFAULT_SELECTABLE_ELEMENT = 'button'
|
|
8
|
+
|
|
9
|
+
/** @internal */
|
|
10
|
+
export type SelectableOwnProps = BoxOwnProps &
|
|
11
|
+
SelectableStyleProps & {
|
|
12
|
+
disabled?: boolean
|
|
13
|
+
href?: string
|
|
14
|
+
tone?: SelectableTone
|
|
15
|
+
type?: 'button'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** @internal */
|
|
19
|
+
export type SelectableElementType = 'button' | 'a' | ComponentType
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export type SelectableProps<E extends SelectableElementType = SelectableElementType> = Props<
|
|
23
|
+
SelectableOwnProps,
|
|
24
|
+
E
|
|
25
|
+
>
|
|
14
26
|
|
|
15
27
|
/** @internal */
|
|
16
|
-
export
|
|
17
|
-
props:
|
|
18
|
-
ref: ForwardedRef<HTMLDivElement>,
|
|
28
|
+
export function Selectable<E extends SelectableElementType = typeof DEFAULT_SELECTABLE_ELEMENT>(
|
|
29
|
+
props: SelectableProps<E>,
|
|
19
30
|
) {
|
|
20
|
-
const {
|
|
31
|
+
const {
|
|
32
|
+
as = DEFAULT_SELECTABLE_ELEMENT,
|
|
33
|
+
className,
|
|
34
|
+
radius,
|
|
35
|
+
tone,
|
|
36
|
+
...rest
|
|
37
|
+
} = props as SelectableProps<typeof DEFAULT_SELECTABLE_ELEMENT>
|
|
21
38
|
|
|
22
39
|
return (
|
|
23
|
-
<Box
|
|
24
|
-
{...restProps}
|
|
25
|
-
className={composeClassNames(className, _selectable({radius, tone}))}
|
|
26
|
-
ref={ref}
|
|
27
|
-
/>
|
|
40
|
+
<Box {...rest} as={as} className={composeClassNames(className, _selectable({radius, tone}))} />
|
|
28
41
|
)
|
|
29
|
-
}
|
|
42
|
+
}
|
|
30
43
|
|
|
31
|
-
Selectable.displayName = '
|
|
44
|
+
Selectable.displayName = 'Selectable'
|
|
@@ -6,19 +6,19 @@ import {
|
|
|
6
6
|
composeClassNames,
|
|
7
7
|
ResponsiveProp,
|
|
8
8
|
} from '@sanity/ui/css'
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import ReactIs from 'react-is'
|
|
9
|
+
import {ThemeColorAvatarColorKey} from '@sanity/ui/theme'
|
|
10
|
+
import {useCallback, useEffect, useMemo, useState} from 'react'
|
|
12
11
|
|
|
13
12
|
import {useArrayProp} from '../../hooks'
|
|
14
|
-
import {AvatarPosition, AvatarStatus, Props} from '../../types'
|
|
13
|
+
import type {AvatarPosition, AvatarSize, AvatarStatus, ComponentType, Props} from '../../types'
|
|
15
14
|
import {Box} from '../box'
|
|
16
15
|
import {Label} from '../label'
|
|
17
16
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
/** @public */
|
|
18
|
+
export const DEFAULT_AVATAR_ELEMENT = 'div'
|
|
19
|
+
|
|
20
|
+
/** @public */
|
|
21
|
+
export interface AvatarOwnProps {
|
|
22
22
|
/** @beta */
|
|
23
23
|
__unstable_hideInnerStroke?: boolean
|
|
24
24
|
animateArrowFrom?: AvatarPosition
|
|
@@ -30,24 +30,29 @@ export interface AvatarProps {
|
|
|
30
30
|
src?: string
|
|
31
31
|
/**
|
|
32
32
|
* The status of the entity this Avatar represents.
|
|
33
|
-
* @
|
|
33
|
+
* @deprecated Will be removed in next major version.
|
|
34
34
|
*/
|
|
35
35
|
status?: AvatarStatus
|
|
36
36
|
title?: string
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/** @public */
|
|
40
|
+
export type AvatarElementType = 'a' | 'button' | 'div' | 'span' | ComponentType
|
|
41
|
+
|
|
42
|
+
/** @public */
|
|
43
|
+
export type AvatarProps<E extends AvatarElementType = AvatarElementType> = Props<AvatarOwnProps, E>
|
|
44
|
+
|
|
39
45
|
/**
|
|
40
46
|
* Avatars are used to represent people and other agents (e.g. bots).
|
|
41
47
|
*
|
|
42
48
|
* @public
|
|
43
49
|
*/
|
|
44
|
-
export
|
|
45
|
-
props:
|
|
46
|
-
ref: ForwardedRef<HTMLDivElement>,
|
|
50
|
+
export function Avatar<E extends AvatarElementType = typeof DEFAULT_AVATAR_ELEMENT>(
|
|
51
|
+
props: AvatarProps<E>,
|
|
47
52
|
) {
|
|
48
53
|
const {
|
|
49
54
|
__unstable_hideInnerStroke,
|
|
50
|
-
as:
|
|
55
|
+
as: Element = DEFAULT_AVATAR_ELEMENT,
|
|
51
56
|
className,
|
|
52
57
|
color = 'gray',
|
|
53
58
|
src,
|
|
@@ -56,11 +61,12 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
56
61
|
onImageLoadError,
|
|
57
62
|
arrowPosition: arrowPositionProp,
|
|
58
63
|
animateArrowFrom,
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59
65
|
status = 'online',
|
|
60
66
|
size: sizeProp = 1,
|
|
61
|
-
...
|
|
62
|
-
} = props
|
|
63
|
-
|
|
67
|
+
...rest
|
|
68
|
+
} = props as AvatarProps<typeof DEFAULT_AVATAR_ELEMENT>
|
|
69
|
+
|
|
64
70
|
const size = useArrayProp(sizeProp)
|
|
65
71
|
|
|
66
72
|
const [arrowPosition, setArrowPosition] = useState<AvatarPosition | undefined>(
|
|
@@ -103,17 +109,14 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
103
109
|
)
|
|
104
110
|
|
|
105
111
|
return (
|
|
106
|
-
<
|
|
107
|
-
// data-as={typeof As === 'string' ? As : undefined}
|
|
112
|
+
<Element
|
|
108
113
|
data-hide-inner-stroke={__unstable_hideInnerStroke ? '' : undefined}
|
|
109
114
|
data-ui="Avatar"
|
|
110
|
-
{...
|
|
115
|
+
{...rest}
|
|
111
116
|
aria-label={title}
|
|
112
117
|
className={composeClassNames(className, avatar({color, size: sizeProp}))}
|
|
113
118
|
data-arrow-position={arrowPosition}
|
|
114
119
|
data-image-error={imageError ? '' : undefined}
|
|
115
|
-
data-status={status}
|
|
116
|
-
ref={ref}
|
|
117
120
|
title={title}
|
|
118
121
|
>
|
|
119
122
|
<span className={avatarArrow()}>
|
|
@@ -134,13 +137,7 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
134
137
|
position="absolute"
|
|
135
138
|
inset={0}
|
|
136
139
|
>
|
|
137
|
-
<Label
|
|
138
|
-
align="center"
|
|
139
|
-
as="span"
|
|
140
|
-
size={initialsSize}
|
|
141
|
-
style={{color: 'inherit'}}
|
|
142
|
-
weight="medium"
|
|
143
|
-
>
|
|
140
|
+
<Label align="center" as="span" size={initialsSize} weight="medium">
|
|
144
141
|
{initials}
|
|
145
142
|
</Label>
|
|
146
143
|
</Box>
|
|
@@ -151,8 +148,8 @@ export const Avatar = forwardRef(function Avatar(
|
|
|
151
148
|
<span />
|
|
152
149
|
</Box>
|
|
153
150
|
)}
|
|
154
|
-
</
|
|
151
|
+
</Element>
|
|
155
152
|
)
|
|
156
|
-
}
|
|
153
|
+
}
|
|
157
154
|
|
|
158
|
-
Avatar.displayName = '
|
|
155
|
+
Avatar.displayName = 'Avatar'
|
|
@@ -1,34 +1,42 @@
|
|
|
1
1
|
import {avatarCounter, composeClassNames, ResponsiveProp} from '@sanity/ui/css'
|
|
2
|
-
import {AvatarSize} from '@sanity/ui/theme'
|
|
3
|
-
import {
|
|
2
|
+
import type {AvatarSize, FontLabelSize} from '@sanity/ui/theme'
|
|
3
|
+
import {useMemo} from 'react'
|
|
4
4
|
|
|
5
5
|
import {useArrayProp} from '../../hooks'
|
|
6
|
-
import {Props} from '../../types'
|
|
7
|
-
import {Box
|
|
6
|
+
import {ComponentType, Props} from '../../types'
|
|
7
|
+
import {Box} from '../box'
|
|
8
8
|
import {Label} from '../label'
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
/** @public */
|
|
11
|
+
export const DEFAULT_AVATAR_COUNTER_ELEMENT = 'div'
|
|
12
|
+
|
|
13
|
+
/** @public */
|
|
14
|
+
export interface AvatarCounterOwnProps {
|
|
15
15
|
count: number
|
|
16
16
|
size?: ResponsiveProp<AvatarSize>
|
|
17
|
-
/** @deprecated No longer supported. */
|
|
18
|
-
tone?: 'navbar'
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
/** @public */
|
|
20
|
+
export type AvatarCounterElementType = 'button' | 'div' | 'span' | ComponentType
|
|
21
|
+
|
|
22
|
+
/** @public */
|
|
23
|
+
export type AvatarCounterProps<E extends AvatarCounterElementType = AvatarCounterElementType> =
|
|
24
|
+
Props<AvatarCounterOwnProps, E>
|
|
25
|
+
|
|
26
|
+
/** @public */
|
|
27
|
+
export function AvatarCounter<
|
|
28
|
+
E extends AvatarCounterElementType = typeof DEFAULT_AVATAR_COUNTER_ELEMENT,
|
|
29
|
+
>(props: AvatarCounterProps<E>) {
|
|
30
|
+
const {
|
|
31
|
+
as = DEFAULT_AVATAR_COUNTER_ELEMENT,
|
|
32
|
+
className,
|
|
33
|
+
count,
|
|
34
|
+
size: sizeProp = 1,
|
|
35
|
+
...rest
|
|
36
|
+
} = props as AvatarCounterProps<typeof DEFAULT_AVATAR_COUNTER_ELEMENT>
|
|
29
37
|
const size = useArrayProp(sizeProp)
|
|
30
38
|
|
|
31
|
-
const
|
|
39
|
+
const labelSize: FontLabelSize[] = useMemo(
|
|
32
40
|
() =>
|
|
33
41
|
size.map((s) => {
|
|
34
42
|
if (s === 1) return 1
|
|
@@ -43,20 +51,20 @@ export const AvatarCounter = forwardRef(function AvatarCounter(
|
|
|
43
51
|
return (
|
|
44
52
|
<Box
|
|
45
53
|
data-ui="AvatarCounter"
|
|
46
|
-
{...
|
|
54
|
+
{...rest}
|
|
47
55
|
align="center"
|
|
56
|
+
as={as}
|
|
48
57
|
className={composeClassNames(className, avatarCounter({size}))}
|
|
49
58
|
display="flex"
|
|
50
59
|
justify="center"
|
|
51
60
|
paddingX={2}
|
|
52
|
-
ref={ref}
|
|
53
61
|
sizing="border"
|
|
54
62
|
>
|
|
55
|
-
<Label align="center" as="span" size={
|
|
63
|
+
<Label align="center" as="span" size={labelSize} weight="medium">
|
|
56
64
|
{count}
|
|
57
65
|
</Label>
|
|
58
66
|
</Box>
|
|
59
67
|
)
|
|
60
|
-
}
|
|
68
|
+
}
|
|
61
69
|
|
|
62
|
-
AvatarCounter.displayName = '
|
|
70
|
+
AvatarCounter.displayName = 'AvatarCounter'
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import {avatarStack, composeClassNames, ResponsiveProp} from '@sanity/ui/css'
|
|
2
2
|
import {AvatarSize} from '@sanity/ui/theme'
|
|
3
|
-
import {Children, cloneElement,
|
|
3
|
+
import {Children, cloneElement, isValidElement, ReactElement} from 'react'
|
|
4
4
|
|
|
5
5
|
import {useArrayProp} from '../../hooks'
|
|
6
|
-
import {Props} from '../../types'
|
|
7
|
-
import {Box,
|
|
6
|
+
import {ComponentType, Props} from '../../types'
|
|
7
|
+
import {Box, BoxOwnProps} from '../box'
|
|
8
8
|
import {AvatarProps} from './avatar'
|
|
9
9
|
import {AvatarCounter} from './avatarCounter'
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
export type AvatarStackChild = ReactElement<Props<AvatarProps, 'div'>> | null | undefined | false
|
|
11
|
+
/** @public */
|
|
12
|
+
export const DEFAULT_AVATAR_STACK_ELEMENT = 'div'
|
|
15
13
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
/** @public */
|
|
15
|
+
export type AvatarStackChild = ReactElement<AvatarProps<'div'>> | null | undefined | false
|
|
16
|
+
|
|
17
|
+
/** @public */
|
|
18
|
+
export type AvatarStackOwnProps = Omit<BoxOwnProps, 'align' | 'display'> & {
|
|
20
19
|
children: AvatarStackChild | AvatarStackChild[]
|
|
21
20
|
maxLength?: number
|
|
22
21
|
size?: ResponsiveProp<AvatarSize>
|
|
@@ -24,22 +23,30 @@ export interface AvatarStackProps extends Omit<BoxProps, 'align' | 'className' |
|
|
|
24
23
|
tone?: 'navbar'
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
/** @public */
|
|
27
|
+
export type AvatarStackElementType = 'div' | 'span' | ComponentType
|
|
28
|
+
|
|
29
|
+
/** @public */
|
|
30
|
+
export type AvatarStackProps<E extends AvatarStackElementType = AvatarStackElementType> = Props<
|
|
31
|
+
AvatarStackOwnProps,
|
|
32
|
+
E
|
|
33
|
+
>
|
|
34
|
+
|
|
35
|
+
/** @public */
|
|
36
|
+
export function AvatarStack<E extends AvatarStackElementType = typeof DEFAULT_AVATAR_STACK_ELEMENT>(
|
|
37
|
+
props: AvatarStackProps<E>,
|
|
33
38
|
) {
|
|
34
39
|
const {
|
|
40
|
+
as = DEFAULT_AVATAR_STACK_ELEMENT,
|
|
35
41
|
children: childrenProp,
|
|
36
42
|
className,
|
|
37
43
|
maxLength: maxLengthProp = 4,
|
|
38
44
|
size: sizeProp = 1,
|
|
39
|
-
...
|
|
40
|
-
} = props
|
|
45
|
+
...rest
|
|
46
|
+
} = props as AvatarStackProps<typeof DEFAULT_AVATAR_STACK_ELEMENT>
|
|
47
|
+
|
|
41
48
|
const children = Children.toArray(childrenProp).filter(isValidElement) as ReactElement<
|
|
42
|
-
|
|
49
|
+
AvatarProps<'div'>
|
|
43
50
|
>[]
|
|
44
51
|
const maxLength = Math.max(maxLengthProp, 0)
|
|
45
52
|
const size = useArrayProp(sizeProp)
|
|
@@ -52,11 +59,11 @@ export const AvatarStack = forwardRef(function AvatarStack(
|
|
|
52
59
|
return (
|
|
53
60
|
<Box
|
|
54
61
|
data-ui="AvatarStack"
|
|
55
|
-
{...
|
|
62
|
+
{...rest}
|
|
56
63
|
align="center"
|
|
64
|
+
as={as}
|
|
57
65
|
className={composeClassNames(className, avatarStack({size}))}
|
|
58
66
|
display="flex"
|
|
59
|
-
ref={ref}
|
|
60
67
|
>
|
|
61
68
|
{len === 0 && (
|
|
62
69
|
<Box flex="none">
|
|
@@ -77,6 +84,6 @@ export const AvatarStack = forwardRef(function AvatarStack(
|
|
|
77
84
|
))}
|
|
78
85
|
</Box>
|
|
79
86
|
)
|
|
80
|
-
}
|
|
87
|
+
}
|
|
81
88
|
|
|
82
|
-
AvatarStack.displayName = '
|
|
89
|
+
AvatarStack.displayName = 'AvatarStack'
|
|
@@ -4,6 +4,7 @@ import {AvatarSize} from '../../types'
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
|
+
* @deprecated This will be removed in next major version.
|
|
7
8
|
*/
|
|
8
9
|
export interface AvatarRootStyleProps {
|
|
9
10
|
$color: ThemeColorAvatarColorKey
|
|
@@ -11,6 +12,7 @@ export interface AvatarRootStyleProps {
|
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @internal
|
|
15
|
+
* @deprecated This will be removed in next major version.
|
|
14
16
|
*/
|
|
15
17
|
export interface ResponsiveAvatarSizeStyleProps {
|
|
16
18
|
$size: AvatarSize[]
|
|
@@ -2,13 +2,11 @@ import {Badge, Flex} from '@sanity/ui'
|
|
|
2
2
|
import {useAction, useSelect, useText} from '@sanity/ui-workshop'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
WORKSHOP_BADGE_MODE_OPTIONS,
|
|
6
5
|
WORKSHOP_BADGE_TONE_OPTIONS,
|
|
7
6
|
WORKSHOP_SPACE_OPTIONS,
|
|
8
7
|
} from '../../../../../workshop/constants'
|
|
9
8
|
|
|
10
9
|
export default function PropsStory() {
|
|
11
|
-
const mode = useSelect('Mode (deprecated)', WORKSHOP_BADGE_MODE_OPTIONS, 'default', 'Props')
|
|
12
10
|
const paddingX = useSelect('Padding X', WORKSHOP_SPACE_OPTIONS, 1, 'Props')
|
|
13
11
|
const paddingY = useSelect('Padding Y', WORKSHOP_SPACE_OPTIONS, 1, 'Props')
|
|
14
12
|
const tone = useSelect('Tone', WORKSHOP_BADGE_TONE_OPTIONS, 'default', 'Props')
|
|
@@ -16,13 +14,7 @@ export default function PropsStory() {
|
|
|
16
14
|
|
|
17
15
|
return (
|
|
18
16
|
<Flex align="center" height="fill" justify="center">
|
|
19
|
-
<Badge
|
|
20
|
-
mode={mode}
|
|
21
|
-
onClick={useAction('onClick')}
|
|
22
|
-
paddingX={paddingX}
|
|
23
|
-
paddingY={paddingY}
|
|
24
|
-
tone={tone}
|
|
25
|
-
>
|
|
17
|
+
<Badge onClick={useAction('onClick')} paddingX={paddingX} paddingY={paddingY} tone={tone}>
|
|
26
18
|
{textProp}
|
|
27
19
|
</Badge>
|
|
28
20
|
</Flex>
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import {Badge, Flex} from '@sanity/ui'
|
|
2
2
|
import {THEME_COLOR_STATE_TONES} from '@sanity/ui/theme'
|
|
3
|
-
import {useSelect} from '@sanity/ui-workshop'
|
|
4
|
-
|
|
5
|
-
import {WORKSHOP_BADGE_MODE_OPTIONS} from '../../../../../workshop/constants'
|
|
6
3
|
|
|
7
4
|
export default function Tones() {
|
|
8
|
-
const mode = useSelect('Mode (deprecated)', WORKSHOP_BADGE_MODE_OPTIONS, 'default', 'Props')
|
|
9
|
-
|
|
10
5
|
return (
|
|
11
6
|
<Flex align="center" height="fill" justify="center" padding={4} sizing="border">
|
|
12
7
|
<Flex align="center" direction="column" gap={2}>
|
|
13
8
|
{THEME_COLOR_STATE_TONES.map((tone) => (
|
|
14
|
-
<Badge key={tone}
|
|
9
|
+
<Badge key={tone} tone={tone}>
|
|
15
10
|
{tone}
|
|
16
11
|
</Badge>
|
|
17
12
|
))}
|
|
@@ -1,48 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type {PaddingStyleProps, RadiusStyleProps, ResponsiveProp} from '@sanity/ui/css'
|
|
2
|
+
import {badge, composeClassNames} from '@sanity/ui/css'
|
|
3
|
+
import {FontTextSize} from '@sanity/ui/theme'
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
-
import {Box
|
|
6
|
-
import {Text
|
|
5
|
+
import type {BadgeTone, ComponentType, Props} from '../../types'
|
|
6
|
+
import {Box} from '../box'
|
|
7
|
+
import {Text} from '../text'
|
|
7
8
|
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
/** @public */
|
|
10
|
+
export const DEFAULT_BADGE_ELEMENT = 'span'
|
|
11
|
+
|
|
12
|
+
/** @public */
|
|
13
|
+
export type BadgeOwnProps = PaddingStyleProps &
|
|
14
|
+
RadiusStyleProps & {
|
|
15
|
+
fontSize?: ResponsiveProp<FontTextSize>
|
|
16
|
+
tone?: BadgeTone
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @public */
|
|
20
|
+
export type BadgeElementType = 'div' | 'span' | ComponentType
|
|
21
|
+
|
|
22
|
+
/** @public */
|
|
23
|
+
export type BadgeProps<E extends BadgeElementType = BadgeElementType> = Props<BadgeOwnProps, E>
|
|
18
24
|
|
|
19
25
|
/**
|
|
20
26
|
* Badges are used to tag resources.
|
|
21
27
|
*
|
|
22
28
|
* @public
|
|
23
29
|
*/
|
|
24
|
-
export
|
|
25
|
-
props:
|
|
26
|
-
ref: ForwardedRef<HTMLDivElement>,
|
|
30
|
+
export function Badge<E extends BadgeElementType = typeof DEFAULT_BADGE_ELEMENT>(
|
|
31
|
+
props: BadgeProps<E>,
|
|
27
32
|
) {
|
|
28
33
|
const {
|
|
34
|
+
as = DEFAULT_BADGE_ELEMENT,
|
|
29
35
|
children,
|
|
30
36
|
className,
|
|
31
|
-
display = 'inline-block',
|
|
32
37
|
fontSize = 1,
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
-
mode: _deprecated_mode,
|
|
35
38
|
padding = 1,
|
|
36
39
|
radius = 2,
|
|
37
|
-
textAlign,
|
|
38
40
|
tone = 'default',
|
|
39
|
-
...
|
|
40
|
-
} = props
|
|
41
|
+
...rest
|
|
42
|
+
} = props as BadgeProps<typeof DEFAULT_BADGE_ELEMENT>
|
|
41
43
|
|
|
42
44
|
return (
|
|
43
45
|
<Box
|
|
44
46
|
data-ui="Badge"
|
|
45
|
-
{...
|
|
47
|
+
{...rest}
|
|
48
|
+
as={as}
|
|
46
49
|
className={composeClassNames(
|
|
47
50
|
className,
|
|
48
51
|
badge({
|
|
@@ -50,15 +53,13 @@ export const Badge = forwardRef(function Badge(
|
|
|
50
53
|
tone,
|
|
51
54
|
}),
|
|
52
55
|
)}
|
|
53
|
-
display=
|
|
56
|
+
display="inline-flex"
|
|
57
|
+
maxWidth="fill"
|
|
54
58
|
padding={padding}
|
|
55
|
-
ref={ref}
|
|
56
59
|
>
|
|
57
|
-
<Text
|
|
58
|
-
{children}
|
|
59
|
-
</Text>
|
|
60
|
+
<Text size={fontSize}>{children}</Text>
|
|
60
61
|
</Box>
|
|
61
62
|
)
|
|
62
|
-
}
|
|
63
|
+
}
|
|
63
64
|
|
|
64
|
-
Badge.displayName = '
|
|
65
|
+
Badge.displayName = 'Badge'
|