@sanity/ui 5.0.0-alpha.2 → 5.0.0-alpha.20
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/README.md +1 -1
- package/dist/LazyRefractor-CQ22IeXB.js +19 -0
- package/dist/LazyRefractor-CQ22IeXB.js.map +1 -0
- package/dist/cli/install.js +2 -1
- package/dist/index.d.ts +825 -855
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2460 -1796
- package/dist/index.js.map +1 -1
- package/dist/polyfills.d.ts +1 -0
- package/dist/polyfills.js +5 -0
- package/dist/polyfills.js.map +1 -0
- package/dist/styles.css +1 -1
- package/package.json +16 -9
- package/src/cli/install.ts +2 -1
- package/src/components/avatar/Avatar.tsx +50 -0
- package/src/components/avatar/avatar.css +51 -0
- package/src/components/avatar/avatar.props.ts +57 -0
- package/src/components/avatar-counter/AvatarCounter.tsx +38 -0
- package/src/components/avatar-counter/avatar-counter.css +8 -0
- package/src/components/avatar-counter/avatarCounter.props.ts +44 -0
- package/src/components/avatar-stack/AvatarStack.tsx +60 -0
- package/src/components/avatar-stack/avatar-stack.css +16 -0
- package/src/components/avatar-stack/avatarStack.props.ts +20 -0
- package/src/components/badge/Badge.tsx +53 -0
- package/src/components/badge/badge.css +6 -0
- package/src/components/badge/badge.props.ts +31 -0
- package/src/components/box/box.css +5 -0
- package/src/components/box/box.props.ts +7 -2
- package/src/components/button/Button.tsx +7 -1
- package/src/components/button/button.css +51 -23
- package/src/components/button/button.props.ts +27 -9
- package/src/components/card/Card.tsx +1 -1
- package/src/components/card/card.props.ts +10 -5
- package/src/components/checkbox/Checkbox.tsx +15 -29
- package/src/components/checkbox/checkbox.css +19 -20
- package/src/components/checkbox/checkbox.props.ts +11 -12
- package/src/components/code/code.props.ts +10 -3
- package/src/components/container/Container.tsx +5 -1
- package/src/components/container/container.css +4 -0
- package/src/components/container/container.props.ts +6 -2
- package/src/components/dialog/Dialog.tsx +139 -0
- package/src/components/dialog/dialog.css +49 -0
- package/src/components/dialog/dialog.props.ts +45 -0
- package/src/components/eyebrow/eyebrow.props.ts +6 -2
- package/src/components/flex/flex.css +5 -0
- package/src/components/flex/flex.props.ts +6 -2
- package/src/components/grid/grid.css +5 -0
- package/src/components/grid/grid.props.ts +14 -3
- package/src/components/h-stack/HStack.tsx +8 -14
- package/src/components/h-stack/hStack.props.ts +5 -13
- package/src/components/heading/heading.props.ts +8 -2
- package/src/components/hotkeys/Hotkeys.tsx +29 -0
- package/src/components/hotkeys/hotkeys.css +3 -0
- package/src/components/hotkeys/hotkeys.props.ts +15 -0
- package/src/components/icon/Icon.tsx +22 -11
- package/src/components/icon/icon.props.ts +7 -3
- package/src/components/icon-button/iconButton.props.ts +7 -2
- package/src/components/index.css +12 -1
- package/src/components/indicator/indicator.css +1 -1
- package/src/components/indicator/indicator.props.ts +6 -2
- package/src/components/indicator-stack/indicatorStack.props.ts +3 -1
- package/src/components/inline/inline.props.ts +6 -2
- package/src/components/kbd/KBD.tsx +33 -0
- package/src/components/kbd/kbd.css +6 -0
- package/src/components/kbd/kbd.props.ts +20 -0
- package/src/components/link/link.props.ts +4 -4
- package/src/components/list/list.props.ts +27 -9
- package/src/components/popover/Popover.tsx +85 -0
- package/src/components/popover/popover.css +21 -0
- package/src/components/popover/popover.props.ts +38 -0
- package/src/components/press-area/pressArea.props.ts +3 -1
- package/src/components/radio/Radio.tsx +10 -28
- package/src/components/radio/radio.css +17 -32
- package/src/components/radio/radio.props.ts +1 -19
- package/src/components/select/Select.tsx +41 -0
- package/src/components/select/select.css +67 -0
- package/src/components/select/select.props.ts +18 -0
- package/src/components/skip-to-content/skipToContent.props.ts +9 -3
- package/src/components/spinner/Spinner.tsx +2 -1
- package/src/components/spinner/spinner.props.ts +3 -0
- package/src/components/switch/Switch.tsx +9 -21
- package/src/components/switch/switch.css +22 -23
- package/src/components/switch/switch.props.ts +7 -11
- package/src/components/tabs/Tabs.tsx +186 -0
- package/src/components/tabs/tabs.css +34 -0
- package/src/components/tabs/tabs.props.ts +66 -0
- package/src/components/text/text.props.ts +6 -2
- package/src/components/text-area/TextArea.tsx +32 -0
- package/src/components/text-area/text-area.css +56 -0
- package/src/components/text-area/textArea.props.ts +35 -0
- package/src/components/text-input/TextInput.tsx +32 -0
- package/src/components/text-input/text-input.css +55 -0
- package/src/components/text-input/textInput.props.ts +42 -0
- package/src/components/tooltip/Tooltip.tsx +59 -55
- package/src/components/tooltip/tooltip.css +21 -40
- package/src/components/tooltip/tooltip.props.ts +24 -8
- package/src/components/tooltip-group/TooltipGroup.tsx +2 -5
- package/src/components/tooltip-group/tooltipGroup.props.ts +3 -1
- package/src/components/v-stack/VStack.tsx +8 -14
- package/src/components/v-stack/vStack.props.ts +5 -13
- package/src/components/visually-hidden/visuallyHidden.props.ts +6 -2
- package/src/css/classes/dynamic/height.css +2 -0
- package/src/css/classes/generic/display.css +8 -8
- package/src/css/classes/generic/placement.css +105 -86
- package/src/css/classes/local/animation.css +4 -0
- package/src/css/classes/local/field-sizing.css +3 -0
- package/src/css/classes/local/index.css +3 -1
- package/src/css/classes/local/text-trim.css +11 -4
- package/src/css/classes/local/top-anchor.css +4 -0
- package/src/css/classes/system/shadow.css +6 -6
- package/src/css/classes/system/typography.css +0 -4
- package/src/css/global/reset.css +12 -1
- package/src/css/tokens/semantic.css +7 -6
- package/src/css/tokens/surface.css +80 -12
- package/src/hooks/useIsClient.ts +10 -0
- package/src/index.ts +17 -2
- package/src/polyfills.ts +17 -0
- package/src/props/formElement.ts +34 -0
- package/src/props/layout.ts +3 -3
- package/src/props/tone.ts +13 -2
- package/src/types/Avatar.ts +14 -0
- package/src/types/Eyebrow.ts +1 -1
- package/src/types/FormElement.ts +2 -0
- package/src/types/Heading.ts +1 -1
- package/src/types/TextAlign.ts +1 -1
- package/src/types/Tone.ts +2 -0
- package/src/utils/getProps.ts +1 -1
- package/src/utils/mergeTriggerProps.ts +66 -0
- package/src/utils/renderPortal.tsx +14 -0
- package/src/version.ts +2 -2
- package/dist/_chunks-es/LazyRefractor.js +0 -20
- package/dist/_chunks-es/LazyRefractor.js.map +0 -1
- package/src/components/label/Label.tsx +0 -34
- package/src/components/label/label.css +0 -3
- package/src/components/label/label.props.ts +0 -19
- package/src/css/classes/local/tone.css +0 -75
|
@@ -1,72 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Button defaults
|
|
3
|
+
*/
|
|
1
4
|
.sui-Button {
|
|
5
|
+
--background-color: hsl(from var(--backdrop) h s l / var(--opacity-high));
|
|
6
|
+
--foreground-color: var(--foreground-high);
|
|
7
|
+
--hover-blend-color: var(--gray-500);
|
|
2
8
|
background: var(--background-color);
|
|
3
9
|
box-shadow: inset 0 0 0 1px var(--border-color, transparent);
|
|
4
10
|
color: var(--foreground-color);
|
|
5
11
|
text-decoration: none;
|
|
6
|
-
transition: var(--hover-transition);
|
|
12
|
+
transition: var(--hover-transition), transform 100ms linear;
|
|
7
13
|
appearance: none;
|
|
8
14
|
}
|
|
9
15
|
|
|
10
16
|
.sui-Button:hover {
|
|
11
17
|
background: color-mix(
|
|
12
18
|
in srgb,
|
|
13
|
-
var(--
|
|
19
|
+
var(--hover-blend-color) 12%,
|
|
14
20
|
var(--background-color)
|
|
15
21
|
);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
.sui-Button.sui-button-level-primary:hover {
|
|
19
|
-
background: color-mix(
|
|
22
|
+
color: color-mix(
|
|
20
23
|
in srgb,
|
|
21
|
-
var(--
|
|
22
|
-
var(--
|
|
24
|
+
var(--foreground-high) 25%,
|
|
25
|
+
var(--foreground-color)
|
|
23
26
|
);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
.sui-Button[class*='sui-tone']:disabled {
|
|
27
|
-
--background-color: var(--inert-background);
|
|
28
|
-
--foreground-color: var(--inert-foreground);
|
|
29
|
-
--border-color: transparent;
|
|
30
|
-
pointer-events: none;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
29
|
.sui-Button:focus-visible {
|
|
34
30
|
outline: var(--focus-outline);
|
|
35
31
|
outline-offset: var(--focus-offset);
|
|
36
32
|
}
|
|
37
33
|
|
|
34
|
+
.sui-Button:active {
|
|
35
|
+
transform: scale(0.975);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
38
|
.sui-Button :is([data-sanity-icon], .sui-Spinner, .sui-Text) {
|
|
39
39
|
color: inherit;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
.sui-Button >
|
|
42
|
+
.sui-Button > [data-ui="Button-Spinner"] + * {
|
|
43
43
|
opacity: 0;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Disabled
|
|
48
|
+
*/
|
|
49
|
+
.sui-Button[class*='sui-tone']:disabled {
|
|
50
|
+
--background-color: var(--inert-background);
|
|
51
|
+
--foreground-color: var(--inert-foreground);
|
|
52
|
+
--border-color: transparent;
|
|
53
|
+
pointer-events: none;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Primary
|
|
58
|
+
*/
|
|
46
59
|
.sui-button-level-primary {
|
|
47
60
|
--background-color: var(--background-high-emphasized);
|
|
48
61
|
--foreground-color: var(--foreground-low-emphasized);
|
|
62
|
+
--hover-blend-color: light-dark(var(--gray-950), var(--gray-50));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.sui-Button.sui-button-level-primary:hover {
|
|
66
|
+
background: color-mix(
|
|
67
|
+
in srgb,
|
|
68
|
+
var(--hover-blend-color) 12%,
|
|
69
|
+
var(--background-color)
|
|
70
|
+
);
|
|
71
|
+
color: var(--foreground-low-emphasized);
|
|
49
72
|
}
|
|
50
73
|
|
|
51
74
|
.sui-button-level-primary.sui-tone-critical {
|
|
52
75
|
--background-color: var(--background-low-emphasized);
|
|
76
|
+
--hover-blend-color: light-dark(var(--red-950), var(--red-50));
|
|
53
77
|
}
|
|
54
78
|
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Secondary
|
|
83
|
+
*/
|
|
55
84
|
.sui-button-level-secondary {
|
|
56
|
-
--background-color: var(--background-high);
|
|
57
|
-
--foreground-color: var(--foreground-high);
|
|
58
85
|
--border-color: var(--separator-low)
|
|
59
86
|
}
|
|
60
87
|
|
|
61
88
|
.sui-button-level-secondary.sui-tone-critical {
|
|
89
|
+
--background-color: var(--background-low);
|
|
62
90
|
--foreground-color: var(--foreground-low);
|
|
91
|
+
--hover-blend-color: var(--red-500);
|
|
63
92
|
}
|
|
64
93
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Tertiary
|
|
96
|
+
*/
|
|
70
97
|
.sui-button-level-tertiary.sui-tone-critical {
|
|
71
98
|
--foreground-color: var(--foreground-low);
|
|
99
|
+
--hover-blend-color: var(--red-500);
|
|
72
100
|
}
|
|
@@ -16,23 +16,41 @@ import type {Responsive} from '../../types/Responsive'
|
|
|
16
16
|
|
|
17
17
|
/** @public */
|
|
18
18
|
export interface ButtonProps<T extends React.ElementType = 'button'> {
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* HTML element to render.
|
|
21
|
+
*/
|
|
20
22
|
as?: InteractiveAs<T>
|
|
21
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Sets padding and gap together to specify size.
|
|
25
|
+
*/
|
|
22
26
|
density?: ButtonDensity
|
|
23
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Sets Button to fill the width of its container.
|
|
29
|
+
*/
|
|
24
30
|
fullWidth?: Responsive<boolean>
|
|
25
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Shows an icon in the start position (left side in left-to-right languages).
|
|
33
|
+
*/
|
|
26
34
|
iconStart?: React.ElementType | React.ReactNode
|
|
27
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Shows an icon in the end position (right side in left-to-right languages).
|
|
37
|
+
*/
|
|
28
38
|
iconEnd?: React.ElementType | React.ReactNode
|
|
29
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Sets the importance of Button's action.
|
|
41
|
+
*/
|
|
30
42
|
level?: ButtonLevel
|
|
31
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Places Button into a loading state.
|
|
45
|
+
*/
|
|
32
46
|
loading?: boolean
|
|
33
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Sets Button's text label.
|
|
49
|
+
*/
|
|
34
50
|
text?: string
|
|
35
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Sets Button's semantic meaning and related color.
|
|
53
|
+
*/
|
|
36
54
|
tone?: ButtonTone
|
|
37
55
|
}
|
|
38
56
|
|
|
@@ -10,7 +10,7 @@ const cardClassName = suffixClassName('sui-Card')
|
|
|
10
10
|
/** @public */
|
|
11
11
|
export function Card<T extends ElementType = 'div'>({
|
|
12
12
|
density = 'regular',
|
|
13
|
-
tone = '
|
|
13
|
+
tone = 'default',
|
|
14
14
|
...props
|
|
15
15
|
}: CardProps<T> & Omit<ComponentPropsWithRef<T>, keyof CardProps<T>>) {
|
|
16
16
|
const {as, children, className, style, ...rest} = getProps({density, tone, ...props}, cardProps)
|
|
@@ -2,16 +2,21 @@ import {borderProps} from '../../props/border'
|
|
|
2
2
|
import {gapProps} from '../../props/gap'
|
|
3
3
|
import {type MarginProps, marginProps} from '../../props/margin'
|
|
4
4
|
import {paddingProps} from '../../props/padding'
|
|
5
|
-
import {type
|
|
5
|
+
import {toneWithDefaultProps, type ToneWithDefaultProps} from '../../props/tone'
|
|
6
6
|
import {DENSITY, type Density} from '../../types/Density'
|
|
7
7
|
import {type PropDef} from '../../types/PropDef'
|
|
8
8
|
import {type Responsive} from '../../types/Responsive'
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
|
-
export interface CardProps<T extends React.ElementType = 'div'>
|
|
12
|
-
|
|
11
|
+
export interface CardProps<T extends React.ElementType = 'div'>
|
|
12
|
+
extends MarginProps, ToneWithDefaultProps {
|
|
13
|
+
/**
|
|
14
|
+
* HTML element or component to render.
|
|
15
|
+
*/
|
|
13
16
|
as?: T
|
|
14
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Sets padding, gap, and border-radius together to specify size. This prop is used in place of separate `padding`, `gap`, and `border-radius` props.
|
|
19
|
+
*/
|
|
15
20
|
density?: Responsive<Density>
|
|
16
21
|
}
|
|
17
22
|
|
|
@@ -49,6 +54,6 @@ export const cardProps: Record<string, PropDef> = {
|
|
|
49
54
|
},
|
|
50
55
|
},
|
|
51
56
|
} satisfies PropDef<Density>,
|
|
52
|
-
...
|
|
57
|
+
...toneWithDefaultProps,
|
|
53
58
|
...marginProps,
|
|
54
59
|
}
|
|
@@ -1,62 +1,48 @@
|
|
|
1
|
-
import {CheckmarkIcon
|
|
1
|
+
import {CheckmarkIcon} from '@sanity/icons/Checkmark'
|
|
2
|
+
import {RemoveIcon} from '@sanity/icons/Remove'
|
|
2
3
|
import clsx from 'clsx'
|
|
3
4
|
import {useEffect, useRef} from 'react'
|
|
4
5
|
|
|
5
6
|
import {getProps} from '../../utils/getProps'
|
|
6
7
|
import {suffixClassName} from '../../utils/suffixClassName'
|
|
7
8
|
import {Box} from '../box/Box'
|
|
8
|
-
import {Label} from '../label/Label'
|
|
9
|
-
import {VisuallyHidden} from '../visually-hidden/VisuallyHidden'
|
|
10
9
|
import {type CheckboxProps, checkboxProps} from './checkbox.props'
|
|
11
10
|
|
|
12
11
|
const checkboxClassName = suffixClassName('sui-Checkbox')
|
|
13
12
|
const checkboxInputClassName = suffixClassName('sui-CheckboxInput')
|
|
14
|
-
const checkboxMarkClassName = suffixClassName('sui-CheckboxMark')
|
|
15
13
|
|
|
16
14
|
/** @beta */
|
|
17
15
|
export function Checkbox(props: CheckboxProps) {
|
|
18
16
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
19
|
-
const {className, style,
|
|
20
|
-
props,
|
|
21
|
-
checkboxProps,
|
|
22
|
-
)
|
|
17
|
+
const {className, style, hasError, indeterminate, ...rest} = getProps(props, checkboxProps)
|
|
23
18
|
|
|
24
19
|
useEffect(() => {
|
|
25
20
|
if (inputRef.current) {
|
|
26
21
|
inputRef.current.indeterminate = indeterminate
|
|
27
22
|
}
|
|
28
|
-
}, [indeterminate])
|
|
23
|
+
}, [indeterminate, inputRef])
|
|
29
24
|
|
|
30
25
|
return (
|
|
31
|
-
<
|
|
26
|
+
<Box
|
|
27
|
+
as="span"
|
|
32
28
|
className={clsx(checkboxClassName, className)}
|
|
33
29
|
style={style}
|
|
34
30
|
data-ui="Checkbox"
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
position="relative"
|
|
32
|
+
radius={2}
|
|
33
|
+
width="17px"
|
|
34
|
+
height="17px"
|
|
37
35
|
>
|
|
38
|
-
<
|
|
39
|
-
|
|
36
|
+
{indeterminate ? <RemoveIcon aria-hidden="true" /> : <CheckmarkIcon aria-hidden="true" />}
|
|
37
|
+
|
|
38
|
+
<input
|
|
40
39
|
type="checkbox"
|
|
41
40
|
className={checkboxInputClassName}
|
|
42
41
|
ref={inputRef}
|
|
43
|
-
|
|
42
|
+
aria-invalid={hasError || undefined}
|
|
44
43
|
{...rest}
|
|
45
44
|
/>
|
|
46
|
-
|
|
47
|
-
<Box
|
|
48
|
-
as="span"
|
|
49
|
-
className={clsx(checkboxMarkClassName, error && 'sui-error')}
|
|
50
|
-
position="relative"
|
|
51
|
-
radius={2}
|
|
52
|
-
width="17px"
|
|
53
|
-
height="17px"
|
|
54
|
-
>
|
|
55
|
-
{indeterminate ? <RemoveIcon /> : <CheckmarkIcon />}
|
|
56
|
-
</Box>
|
|
57
|
-
|
|
58
|
-
{label}
|
|
59
|
-
</Label>
|
|
45
|
+
</Box>
|
|
60
46
|
)
|
|
61
47
|
}
|
|
62
48
|
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Custom checkbox, base
|
|
3
|
-
*/
|
|
4
|
-
.sui-CheckboxMark {
|
|
5
|
-
/* Background and border colours are computed relatively in hover states;
|
|
6
|
-
we use custom properties to make this easier */
|
|
1
|
+
.sui-Checkbox {
|
|
7
2
|
--background-color: var(--backdrop);
|
|
8
3
|
--border-color: var(--separator-high);
|
|
9
4
|
background-color: var(--background-color);
|
|
@@ -13,19 +8,24 @@
|
|
|
13
8
|
transition: var(--hover-transition);
|
|
14
9
|
}
|
|
15
10
|
|
|
11
|
+
.sui-CheckboxInput {
|
|
12
|
+
opacity: 0;
|
|
13
|
+
position: absolute;
|
|
14
|
+
/* Use negative inset for 24x24 pixel hit area */
|
|
15
|
+
inset: var(--form-element-inset);
|
|
16
|
+
}
|
|
17
|
+
|
|
16
18
|
/**
|
|
17
19
|
* Hover - uses relative border/background colours to darken/lighten in both normal & error state
|
|
18
20
|
*/
|
|
19
|
-
|
|
20
|
-
.sui-Checkbox:hover .sui-CheckboxMark {
|
|
21
|
+
.sui-Checkbox:has(.sui-CheckboxInput:hover) {
|
|
21
22
|
border-color: light-dark(
|
|
22
23
|
oklch(from var(--border-color) calc(l - var(--hover-lightness-delta)) c h),
|
|
23
24
|
oklch(from var(--border-color) calc(l + var(--hover-lightness-delta)) c h)
|
|
24
25
|
);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
.sui-Checkbox:hover .sui-CheckboxInput:is(:checked, :indeterminate) + .sui-CheckboxMark {
|
|
28
|
+
.sui-Checkbox:has(.sui-CheckboxInput:hover:is(:checked, :indeterminate)) {
|
|
29
29
|
background-color: light-dark(
|
|
30
30
|
oklch(from var(--background-color) calc(l - var(--hover-lightness-delta)) c h),
|
|
31
31
|
oklch(from var(--background-color) calc(l + var(--hover-lightness-delta)) c h)
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
/**
|
|
36
36
|
* Focus
|
|
37
37
|
*/
|
|
38
|
-
.sui-CheckboxInput:focus-visible
|
|
38
|
+
.sui-Checkbox:has(.sui-CheckboxInput:focus-visible) {
|
|
39
39
|
outline: var(--focus-outline);
|
|
40
40
|
outline-offset: var(--focus-offset);
|
|
41
41
|
}
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
/**
|
|
44
44
|
* Checked/indeterminate
|
|
45
45
|
*/
|
|
46
|
-
.sui-CheckboxInput:is(:checked, :indeterminate)
|
|
46
|
+
.sui-Checkbox:has(.sui-CheckboxInput:is(:checked, :indeterminate)) {
|
|
47
47
|
--background-color: var(--active-background-emphasized);
|
|
48
48
|
--border-color: transparent;
|
|
49
49
|
color: var(--active-foreground-emphasized);
|
|
@@ -52,20 +52,19 @@
|
|
|
52
52
|
/**
|
|
53
53
|
* Disabled
|
|
54
54
|
*/
|
|
55
|
-
.sui-
|
|
55
|
+
.sui-Checkbox:has(.sui-CheckboxInput:disabled) {
|
|
56
56
|
--background-color: var(--inert-background);
|
|
57
57
|
--border-color: var(--separator-low);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
.sui-Checkbox:has(:disabled) {
|
|
60
|
+
.sui-CheckboxInput:disabled {
|
|
62
61
|
pointer-events: none;
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
/**
|
|
66
65
|
* Disabled, but checked/indeterminate
|
|
67
66
|
*/
|
|
68
|
-
.sui-CheckboxInput:is(:checked, :indeterminate):disabled
|
|
67
|
+
.sui-Checkbox:has(.sui-CheckboxInput:is(:checked, :indeterminate):disabled) {
|
|
69
68
|
--border-color: var(--separator-low);
|
|
70
69
|
color: var(--inert-foreground);
|
|
71
70
|
}
|
|
@@ -73,28 +72,28 @@
|
|
|
73
72
|
/**
|
|
74
73
|
* Error
|
|
75
74
|
*/
|
|
76
|
-
.sui-
|
|
75
|
+
.sui-Checkbox:has(.sui-CheckboxInput[aria-invalid="true"]) {
|
|
77
76
|
--border-color: var(--error-separator);
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
/**
|
|
81
80
|
* Error, checked/indeterminate
|
|
82
81
|
*/
|
|
83
|
-
.sui-CheckboxInput:is(:checked, :indeterminate)
|
|
82
|
+
.sui-Checkbox:has(.sui-CheckboxInput:is(:checked, :indeterminate)[aria-invalid="true"]) {
|
|
84
83
|
--background-color: var(--error-background-emphasized);
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
87
|
* Check/dash icons
|
|
89
88
|
*/
|
|
90
|
-
.sui-
|
|
89
|
+
.sui-Checkbox svg {
|
|
91
90
|
position: absolute;
|
|
92
91
|
top: 50%;
|
|
93
92
|
left: 50%;
|
|
94
93
|
transform: translate(-50%, -50%);
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
.sui-
|
|
96
|
+
.sui-Checkbox path {
|
|
98
97
|
vector-effect: non-scaling-stroke;
|
|
99
98
|
stroke-width: 1.5px;
|
|
100
99
|
}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import {type MarginProps, marginProps} from '../../props/margin'
|
|
2
1
|
import {type PropDef} from '../../types/PropDef'
|
|
3
2
|
|
|
4
3
|
/** @beta */
|
|
5
|
-
export interface CheckboxProps extends React.ComponentProps<'input'
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export interface CheckboxProps extends React.ComponentProps<'input'> {
|
|
5
|
+
/**
|
|
6
|
+
* Applies error styling to the checkbox mark for invalid states.
|
|
7
|
+
* @remarks Use when form validation fails. Pair with a visible error message.
|
|
8
|
+
*/
|
|
9
|
+
hasError?: boolean
|
|
10
|
+
/**
|
|
11
|
+
* Renders the "mixed state" mark (a horizontal line).
|
|
12
|
+
* @remarks Use when the checkbox controls a group with some-but-not-all children checked.
|
|
13
|
+
*/
|
|
9
14
|
indeterminate?: boolean
|
|
10
|
-
/** Input label */
|
|
11
|
-
label: React.ReactNode
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
export const checkboxProps: Record<string, PropDef> = {
|
|
15
|
-
|
|
18
|
+
hasError: {
|
|
16
19
|
type: 'boolean',
|
|
17
20
|
},
|
|
18
21
|
indeterminate: {
|
|
19
22
|
type: 'boolean',
|
|
20
23
|
},
|
|
21
|
-
label: {
|
|
22
|
-
type: 'string',
|
|
23
|
-
},
|
|
24
|
-
...marginProps,
|
|
25
24
|
}
|
|
@@ -9,11 +9,18 @@ export interface CodeProps<T extends CodeTag = 'pre'> extends Omit<
|
|
|
9
9
|
TypographyProps,
|
|
10
10
|
'align' | 'truncate' | 'tone'
|
|
11
11
|
> {
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* HTML element or component to render.
|
|
14
|
+
* @remarks The defined element wraps an inner `<code>` tag.
|
|
15
|
+
*/
|
|
13
16
|
as?: T
|
|
14
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Refractor language for syntax highlighting.
|
|
19
|
+
*/
|
|
15
20
|
language?: string
|
|
16
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Sets font size.
|
|
23
|
+
*/
|
|
17
24
|
size?: Responsive<CodeSize>
|
|
18
25
|
}
|
|
19
26
|
|
|
@@ -10,9 +10,13 @@ const containerClassName = suffixClassName('sui-Container')
|
|
|
10
10
|
/** @public */
|
|
11
11
|
export function Container<T extends ElementType = 'div'>({
|
|
12
12
|
marginX = 'auto',
|
|
13
|
+
size = 2,
|
|
13
14
|
...props
|
|
14
15
|
}: ContainerProps<T> & Omit<ComponentPropsWithRef<T>, keyof ContainerProps<T>>) {
|
|
15
|
-
const {as, children, className, style, ...rest} = getProps(
|
|
16
|
+
const {as, children, className, style, ...rest} = getProps(
|
|
17
|
+
{marginX, size, ...props},
|
|
18
|
+
containerProps,
|
|
19
|
+
)
|
|
16
20
|
const Component = as || 'div'
|
|
17
21
|
|
|
18
22
|
return (
|
|
@@ -5,9 +5,13 @@ import type {Responsive} from '../../types/Responsive'
|
|
|
5
5
|
|
|
6
6
|
/** @public */
|
|
7
7
|
export interface ContainerProps<T extends React.ElementType = 'div'> extends LayoutProps {
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* HTML element or component to render.
|
|
10
|
+
*/
|
|
9
11
|
as?: T
|
|
10
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Maximum width of the container.
|
|
14
|
+
*/
|
|
11
15
|
size?: Responsive<ContainerSize>
|
|
12
16
|
}
|
|
13
17
|
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {CloseIcon} from '@sanity/icons/Close'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import {type ComponentProps, useEffect, useId, useRef} from 'react'
|
|
4
|
+
|
|
5
|
+
import {getProps} from '../../utils/getProps'
|
|
6
|
+
import {suffixClassName} from '../../utils/suffixClassName'
|
|
7
|
+
import {Box} from '../box/Box'
|
|
8
|
+
import {Flex} from '../flex/Flex'
|
|
9
|
+
import {Heading} from '../heading/Heading'
|
|
10
|
+
import {IconButton} from '../icon-button/IconButton'
|
|
11
|
+
import {type DialogProps, dialogProps} from './dialog.props'
|
|
12
|
+
|
|
13
|
+
const dialogClassName = suffixClassName('sui-Dialog')
|
|
14
|
+
const dialogContentClassName = suffixClassName('sui-DialogContent')
|
|
15
|
+
const dialogFooterClassName = suffixClassName('sui-DialogFooter')
|
|
16
|
+
|
|
17
|
+
function DialogRoot({open = false, size = 0, ...props}: DialogProps) {
|
|
18
|
+
const {children, className, style, header, onClose, ...rest} = getProps(
|
|
19
|
+
{size, ...props},
|
|
20
|
+
dialogProps,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const dialogRef = useRef<HTMLDialogElement>(null)
|
|
24
|
+
const headerId = useId()
|
|
25
|
+
|
|
26
|
+
const dialogClasses = clsx(
|
|
27
|
+
dialogClassName,
|
|
28
|
+
`${props.topAnchor ? 'sui-mx-auto' : 'sui-m-auto'} sui-radius5 sui-shadow3 sui-p4 sui-flex-direction-column sui-gap4 sui-overflow-y-auto`,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const dialogElement = dialogRef.current
|
|
33
|
+
if (!dialogElement) return
|
|
34
|
+
|
|
35
|
+
// `open` = `open` prop
|
|
36
|
+
// dialogElement.open = the `open` attribute on the HTML dialog element
|
|
37
|
+
// The prop and the attribute are manipulated independently, thus they
|
|
38
|
+
// can get out of sync if not handled within this effect.
|
|
39
|
+
if (open) {
|
|
40
|
+
if (!dialogElement.open) {
|
|
41
|
+
dialogElement.showModal()
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
if (dialogElement.open) {
|
|
45
|
+
dialogElement.close()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Ensure the dialog is closed (and thus its `open` attribute updated)
|
|
50
|
+
// when the component is unmounted.
|
|
51
|
+
return () => {
|
|
52
|
+
dialogElement.close()
|
|
53
|
+
}
|
|
54
|
+
}, [open])
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<dialog
|
|
58
|
+
{...rest}
|
|
59
|
+
ref={dialogRef}
|
|
60
|
+
closedby="any"
|
|
61
|
+
aria-labelledby={header ? headerId : undefined}
|
|
62
|
+
onClose={onClose}
|
|
63
|
+
className={clsx(dialogClasses, className)}
|
|
64
|
+
style={style}
|
|
65
|
+
data-ui="Dialog"
|
|
66
|
+
>
|
|
67
|
+
<Flex flexShrink={0} justifyContent="space-between" alignItems="center">
|
|
68
|
+
{header ? (
|
|
69
|
+
<Heading trim size={1} id={headerId}>
|
|
70
|
+
{header}
|
|
71
|
+
</Heading>
|
|
72
|
+
) : (
|
|
73
|
+
<div />
|
|
74
|
+
)}
|
|
75
|
+
<IconButton
|
|
76
|
+
aria-label="Close"
|
|
77
|
+
level="tertiary"
|
|
78
|
+
icon={CloseIcon}
|
|
79
|
+
onClick={() => dialogRef.current?.close()}
|
|
80
|
+
/>
|
|
81
|
+
</Flex>
|
|
82
|
+
{children}
|
|
83
|
+
</dialog>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function DialogContent(props: ComponentProps<'div'>) {
|
|
88
|
+
const {children, className, style, ...rest} = getProps(props, {})
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Box
|
|
92
|
+
{...rest}
|
|
93
|
+
className={clsx(dialogContentClassName, className)}
|
|
94
|
+
style={style}
|
|
95
|
+
data-ui="DialogContent"
|
|
96
|
+
flexGrow={1}
|
|
97
|
+
overflowY="auto"
|
|
98
|
+
>
|
|
99
|
+
{children}
|
|
100
|
+
</Box>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function DialogFooter(props: ComponentProps<'div'>) {
|
|
105
|
+
const {children, className, style, ...rest} = getProps(props, {})
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<Box
|
|
109
|
+
{...rest}
|
|
110
|
+
className={clsx(dialogFooterClassName, className)}
|
|
111
|
+
style={style}
|
|
112
|
+
data-ui="DialogFooter"
|
|
113
|
+
flexShrink={0}
|
|
114
|
+
>
|
|
115
|
+
{children}
|
|
116
|
+
</Box>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
DialogRoot.displayName = 'Dialog'
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @beta
|
|
124
|
+
*
|
|
125
|
+
* Renders a modal dialog element — should not be used for nonmodal dialogs.
|
|
126
|
+
* Modal dialogs make their containing documents inert, and render on the topmost
|
|
127
|
+
* layer within that containing document; they must be dimissed before the containing
|
|
128
|
+
* document and its contents become unblocked. They also trap focus within the bounds
|
|
129
|
+
* of the dialog element and its descendants.
|
|
130
|
+
*
|
|
131
|
+
* For more on dialogs and modality, refer to the HTML specification for the dialog element:
|
|
132
|
+
* https://html.spec.whatwg.org/dev/interactive-elements.html#the-dialog-element
|
|
133
|
+
*/
|
|
134
|
+
export const Dialog = DialogRoot
|
|
135
|
+
|
|
136
|
+
DialogRoot.Content = DialogContent
|
|
137
|
+
DialogRoot.Footer = DialogFooter
|
|
138
|
+
|
|
139
|
+
export type {DialogProps}
|