@sanity/ui 5.0.0-alpha.19 → 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/dist/index.d.ts +9 -41
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +87 -150
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/checkbox/Checkbox.tsx +13 -28
- package/src/components/checkbox/checkbox.css +19 -20
- package/src/components/checkbox/checkbox.props.ts +3 -12
- package/src/components/index.css +0 -1
- package/src/components/radio/Radio.tsx +11 -29
- package/src/components/radio/radio.css +17 -32
- package/src/components/radio/radio.props.ts +1 -24
- package/src/components/switch/Switch.tsx +10 -22
- package/src/components/switch/switch.css +22 -23
- package/src/components/switch/switch.props.ts +3 -12
- package/src/components/tooltip/Tooltip.tsx +1 -1
- package/src/components/tooltip/tooltip.css +2 -0
- package/src/css/classes/generic/placement.css +81 -93
- package/src/css/classes/local/text-trim.css +11 -0
- package/src/css/tokens/surface.css +2 -0
- package/src/index.ts +0 -1
- package/src/types/TextAlign.ts +1 -1
- package/src/version.ts +2 -2
- package/src/components/label/Label.tsx +0 -34
- package/src/components/label/label.css +0 -3
- package/src/components/label/label.props.ts +0 -25
package/package.json
CHANGED
|
@@ -6,21 +6,15 @@ import {useEffect, useRef} from 'react'
|
|
|
6
6
|
import {getProps} from '../../utils/getProps'
|
|
7
7
|
import {suffixClassName} from '../../utils/suffixClassName'
|
|
8
8
|
import {Box} from '../box/Box'
|
|
9
|
-
import {Label} from '../label/Label'
|
|
10
|
-
import {VisuallyHidden} from '../visually-hidden/VisuallyHidden'
|
|
11
9
|
import {type CheckboxProps, checkboxProps} from './checkbox.props'
|
|
12
10
|
|
|
13
11
|
const checkboxClassName = suffixClassName('sui-Checkbox')
|
|
14
12
|
const checkboxInputClassName = suffixClassName('sui-CheckboxInput')
|
|
15
|
-
const checkboxMarkClassName = suffixClassName('sui-CheckboxMark')
|
|
16
13
|
|
|
17
14
|
/** @beta */
|
|
18
15
|
export function Checkbox(props: CheckboxProps) {
|
|
19
16
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
20
|
-
const {className, style,
|
|
21
|
-
props,
|
|
22
|
-
checkboxProps,
|
|
23
|
-
)
|
|
17
|
+
const {className, style, hasError, indeterminate, ...rest} = getProps(props, checkboxProps)
|
|
24
18
|
|
|
25
19
|
useEffect(() => {
|
|
26
20
|
if (inputRef.current) {
|
|
@@ -29,35 +23,26 @@ export function Checkbox(props: CheckboxProps) {
|
|
|
29
23
|
}, [indeterminate, inputRef])
|
|
30
24
|
|
|
31
25
|
return (
|
|
32
|
-
<
|
|
33
|
-
|
|
26
|
+
<Box
|
|
27
|
+
as="span"
|
|
28
|
+
className={clsx(checkboxClassName, className)}
|
|
34
29
|
style={style}
|
|
35
30
|
data-ui="Checkbox"
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
position="relative"
|
|
32
|
+
radius={2}
|
|
33
|
+
width="17px"
|
|
34
|
+
height="17px"
|
|
38
35
|
>
|
|
39
|
-
<
|
|
40
|
-
|
|
36
|
+
{indeterminate ? <RemoveIcon aria-hidden="true" /> : <CheckmarkIcon aria-hidden="true" />}
|
|
37
|
+
|
|
38
|
+
<input
|
|
41
39
|
type="checkbox"
|
|
42
40
|
className={checkboxInputClassName}
|
|
43
41
|
ref={inputRef}
|
|
44
|
-
|
|
42
|
+
aria-invalid={hasError || undefined}
|
|
45
43
|
{...rest}
|
|
46
44
|
/>
|
|
47
|
-
|
|
48
|
-
<Box
|
|
49
|
-
as="span"
|
|
50
|
-
className={clsx(checkboxMarkClassName, hasError && 'sui-error')}
|
|
51
|
-
position="relative"
|
|
52
|
-
radius={2}
|
|
53
|
-
width="17px"
|
|
54
|
-
height="17px"
|
|
55
|
-
>
|
|
56
|
-
{indeterminate ? <RemoveIcon /> : <CheckmarkIcon />}
|
|
57
|
-
</Box>
|
|
58
|
-
|
|
59
|
-
{label}
|
|
60
|
-
</Label>
|
|
45
|
+
</Box>
|
|
61
46
|
)
|
|
62
47
|
}
|
|
63
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,11 +1,10 @@
|
|
|
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'
|
|
4
|
+
export interface CheckboxProps extends React.ComponentProps<'input'> {
|
|
6
5
|
/**
|
|
7
|
-
* Applies error styling to the checkbox mark.
|
|
8
|
-
* @remarks Use when form validation fails. Pair with a visible error message.
|
|
6
|
+
* Applies error styling to the checkbox mark for invalid states.
|
|
7
|
+
* @remarks Use when form validation fails. Pair with a visible error message.
|
|
9
8
|
*/
|
|
10
9
|
hasError?: boolean
|
|
11
10
|
/**
|
|
@@ -13,10 +12,6 @@ export interface CheckboxProps extends React.ComponentProps<'input'>, MarginProp
|
|
|
13
12
|
* @remarks Use when the checkbox controls a group with some-but-not-all children checked.
|
|
14
13
|
*/
|
|
15
14
|
indeterminate?: boolean
|
|
16
|
-
/**
|
|
17
|
-
* Visible label next to the checkbox.
|
|
18
|
-
*/
|
|
19
|
-
label: React.ReactNode
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
export const checkboxProps: Record<string, PropDef> = {
|
|
@@ -26,8 +21,4 @@ export const checkboxProps: Record<string, PropDef> = {
|
|
|
26
21
|
indeterminate: {
|
|
27
22
|
type: 'boolean',
|
|
28
23
|
},
|
|
29
|
-
label: {
|
|
30
|
-
type: 'string',
|
|
31
|
-
},
|
|
32
|
-
...marginProps,
|
|
33
24
|
}
|
package/src/components/index.css
CHANGED
|
@@ -1,47 +1,29 @@
|
|
|
1
1
|
import clsx from 'clsx'
|
|
2
2
|
|
|
3
|
-
import {getProps} from '../../utils/getProps'
|
|
4
3
|
import {suffixClassName} from '../../utils/suffixClassName'
|
|
5
4
|
import {Box} from '../box/Box'
|
|
6
|
-
import {
|
|
7
|
-
import {VisuallyHidden} from '../visually-hidden/VisuallyHidden'
|
|
8
|
-
import {type RadioProps, radioProps} from './radio.props'
|
|
5
|
+
import {type RadioProps} from './radio.props'
|
|
9
6
|
|
|
10
7
|
const radioClassName = suffixClassName('sui-Radio')
|
|
11
8
|
const radioInputClassName = suffixClassName('sui-RadioInput')
|
|
12
|
-
const radioMarkClassName = suffixClassName('sui-RadioMark')
|
|
13
9
|
|
|
14
10
|
/** @beta */
|
|
15
11
|
export function Radio(props: RadioProps) {
|
|
16
|
-
const {className, style,
|
|
12
|
+
const {className, style, ...rest} = props
|
|
17
13
|
|
|
18
14
|
return (
|
|
19
|
-
<
|
|
20
|
-
|
|
15
|
+
<Box
|
|
16
|
+
as="span"
|
|
17
|
+
className={clsx(radioClassName, className)}
|
|
21
18
|
style={style}
|
|
22
19
|
data-ui="Radio"
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
position="relative"
|
|
21
|
+
radius="full"
|
|
22
|
+
width="17px"
|
|
23
|
+
height="17px"
|
|
25
24
|
>
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
type="radio"
|
|
29
|
-
className={radioInputClassName}
|
|
30
|
-
disabled={disabled}
|
|
31
|
-
{...rest}
|
|
32
|
-
/>
|
|
33
|
-
|
|
34
|
-
<Box
|
|
35
|
-
as="span"
|
|
36
|
-
className={clsx(radioMarkClassName, hasError && 'sui-error')}
|
|
37
|
-
position="relative"
|
|
38
|
-
radius="full"
|
|
39
|
-
width="17px"
|
|
40
|
-
height="17px"
|
|
41
|
-
/>
|
|
42
|
-
|
|
43
|
-
{label}
|
|
44
|
-
</Label>
|
|
25
|
+
<input type="radio" className={radioInputClassName} {...rest} />
|
|
26
|
+
</Box>
|
|
45
27
|
)
|
|
46
28
|
}
|
|
47
29
|
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Custom radio control, base
|
|
3
|
-
*/
|
|
4
|
-
.sui-RadioMark {
|
|
5
|
-
/* Background and border colours are computed relatively in hover states;
|
|
6
|
-
we use custom properties to make this easier */
|
|
1
|
+
.sui-Radio {
|
|
7
2
|
--background-color: var(--backdrop);
|
|
8
3
|
--border-color: var(--separator-high);
|
|
9
4
|
background-color: var(--background-color);
|
|
@@ -11,10 +6,17 @@
|
|
|
11
6
|
transition: var(--hover-transition);
|
|
12
7
|
}
|
|
13
8
|
|
|
9
|
+
.sui-RadioInput {
|
|
10
|
+
opacity: 0;
|
|
11
|
+
position: absolute;
|
|
12
|
+
/* Use negative inset for 24x24 pixel hit area */
|
|
13
|
+
inset: var(--form-element-inset);
|
|
14
|
+
}
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* Custom radio marker
|
|
16
18
|
*/
|
|
17
|
-
.sui-
|
|
19
|
+
.sui-Radio:before {
|
|
18
20
|
content: '';
|
|
19
21
|
background: var(--active-foreground-emphasized);
|
|
20
22
|
border-radius: var(--radius-round);
|
|
@@ -28,16 +30,14 @@
|
|
|
28
30
|
/**
|
|
29
31
|
* Hover - uses relative border/background colours to darken/lighten in both normal & error state
|
|
30
32
|
*/
|
|
31
|
-
|
|
32
|
-
.sui-Radio:hover .sui-RadioMark {
|
|
33
|
+
.sui-Radio:has(.sui-RadioInput:hover) {
|
|
33
34
|
border-color: light-dark(
|
|
34
35
|
oklch(from var(--border-color) calc(l - var(--hover-lightness-delta)) c h),
|
|
35
36
|
oklch(from var(--border-color) calc(l + var(--hover-lightness-delta)) c h)
|
|
36
37
|
);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
.sui-Radio:hover .sui-RadioInput:is(:checked) + .sui-RadioMark {
|
|
40
|
+
.sui-Radio:has(.sui-RadioInput:is(:checked):hover) {
|
|
41
41
|
background-color: light-dark(
|
|
42
42
|
oklch(from var(--background-color) calc(l - var(--hover-lightness-delta)) c h),
|
|
43
43
|
oklch(from var(--background-color) calc(l + var(--hover-lightness-delta)) c h)
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
/**
|
|
48
48
|
* Focus
|
|
49
49
|
*/
|
|
50
|
-
.sui-RadioInput:focus-visible
|
|
50
|
+
.sui-Radio:has(.sui-RadioInput:focus-visible) {
|
|
51
51
|
outline: var(--focus-outline);
|
|
52
52
|
outline-offset: var(--focus-offset);
|
|
53
53
|
}
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
/**
|
|
56
56
|
* Checked
|
|
57
57
|
*/
|
|
58
|
-
.sui-
|
|
58
|
+
.sui-Radio:has(.sui-RadioInput:checked) {
|
|
59
59
|
--background-color: var(--active-background-emphasized);
|
|
60
60
|
--border-color: transparent;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
.sui-
|
|
63
|
+
.sui-Radio:has(.sui-RadioInput:checked):before {
|
|
64
64
|
inset: 4px;
|
|
65
65
|
opacity: 1;
|
|
66
66
|
}
|
|
@@ -68,30 +68,15 @@
|
|
|
68
68
|
/**
|
|
69
69
|
* Disabled
|
|
70
70
|
*/
|
|
71
|
-
.sui-
|
|
71
|
+
.sui-Radio:has(.sui-RadioInput:disabled) {
|
|
72
72
|
--background-color: var(--inert-background);
|
|
73
73
|
--border-color: var(--separator-low);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
.sui-
|
|
76
|
+
.sui-Radio:has(.sui-RadioInput:disabled):before {
|
|
77
77
|
background: light-dark(var(--gray-300), var(--gray-500));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
.sui-Radio:has(:disabled) {
|
|
80
|
+
.sui-RadioInput:disabled {
|
|
82
81
|
pointer-events: none;
|
|
83
82
|
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Error
|
|
87
|
-
*/
|
|
88
|
-
.sui-RadioMark.sui-error {
|
|
89
|
-
--border-color: var(--error-separator);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Error, checked
|
|
94
|
-
*/
|
|
95
|
-
.sui-RadioInput:checked + .sui-RadioMark.sui-error {
|
|
96
|
-
--background-color: var(--error-background-emphasized);
|
|
97
|
-
}
|
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
import {type MarginProps, marginProps} from '../../props/margin'
|
|
2
|
-
import {type PropDef} from '../../types/PropDef'
|
|
3
|
-
|
|
4
1
|
/** @beta */
|
|
5
|
-
export interface RadioProps extends React.ComponentProps<'input'
|
|
6
|
-
/**
|
|
7
|
-
* Applies error styling to the radio mark.
|
|
8
|
-
* @remarks Use when form validation fails. Pair with a visible error message. The prop is visual only.
|
|
9
|
-
*/
|
|
10
|
-
hasError?: boolean
|
|
11
|
-
/**
|
|
12
|
-
* Visible label next to the radio.
|
|
13
|
-
*/
|
|
14
|
-
label: React.ReactNode
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const radioProps: Record<string, PropDef> = {
|
|
18
|
-
hasError: {
|
|
19
|
-
type: 'boolean',
|
|
20
|
-
},
|
|
21
|
-
label: {
|
|
22
|
-
type: 'string',
|
|
23
|
-
},
|
|
24
|
-
...marginProps,
|
|
25
|
-
}
|
|
2
|
+
export interface RadioProps extends React.ComponentProps<'input'> {}
|
|
@@ -3,45 +3,33 @@ import clsx from 'clsx'
|
|
|
3
3
|
import {getProps} from '../../utils/getProps'
|
|
4
4
|
import {suffixClassName} from '../../utils/suffixClassName'
|
|
5
5
|
import {Flex} from '../flex/Flex'
|
|
6
|
-
import {Label} from '../label/Label'
|
|
7
|
-
import {VisuallyHidden} from '../visually-hidden/VisuallyHidden'
|
|
8
6
|
import {type SwitchProps, switchProps} from './switch.props'
|
|
9
7
|
|
|
10
8
|
const switchClassName = suffixClassName('sui-Switch')
|
|
11
9
|
const switchInputClassName = suffixClassName('sui-SwitchInput')
|
|
12
|
-
const switchMarkClassName = suffixClassName('sui-SwitchMark')
|
|
13
10
|
|
|
14
11
|
/** @beta */
|
|
15
12
|
export function Switch(props: SwitchProps) {
|
|
16
|
-
const {className, style,
|
|
13
|
+
const {className, style, hasError, ...rest} = getProps(props, switchProps)
|
|
17
14
|
|
|
18
15
|
return (
|
|
19
|
-
<
|
|
20
|
-
|
|
16
|
+
<Flex
|
|
17
|
+
as="span"
|
|
18
|
+
className={clsx(switchClassName, className)}
|
|
21
19
|
style={style}
|
|
22
20
|
data-ui="Switch"
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
position="relative"
|
|
22
|
+
alignItems="center"
|
|
23
|
+
radius={6}
|
|
25
24
|
>
|
|
26
|
-
<
|
|
27
|
-
as="input"
|
|
25
|
+
<input
|
|
28
26
|
type="checkbox"
|
|
29
27
|
role="switch"
|
|
30
28
|
className={switchInputClassName}
|
|
31
|
-
|
|
29
|
+
aria-invalid={hasError || undefined}
|
|
32
30
|
{...rest}
|
|
33
31
|
/>
|
|
34
|
-
|
|
35
|
-
<Flex
|
|
36
|
-
as="span"
|
|
37
|
-
className={clsx(switchMarkClassName, hasError && 'sui-error')}
|
|
38
|
-
alignItems="center"
|
|
39
|
-
radius={6}
|
|
40
|
-
aria-hidden="true"
|
|
41
|
-
/>
|
|
42
|
-
|
|
43
|
-
{label}
|
|
44
|
-
</Label>
|
|
32
|
+
</Flex>
|
|
45
33
|
)
|
|
46
34
|
}
|
|
47
35
|
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Custom switch control, base
|
|
3
|
-
*/
|
|
4
|
-
.sui-SwitchMark {
|
|
5
|
-
/* Background and border colours are computed relatively in hover states;
|
|
6
|
-
we use custom properties to make this easier */
|
|
1
|
+
.sui-Switch {
|
|
7
2
|
--background-color: var(--backdrop);
|
|
8
3
|
--border-color: var(--separator-high);
|
|
9
4
|
/* Switch size stored as custom properties to be used with calc
|
|
@@ -17,10 +12,17 @@
|
|
|
17
12
|
transition: var(--hover-transition);
|
|
18
13
|
}
|
|
19
14
|
|
|
15
|
+
.sui-SwitchInput {
|
|
16
|
+
opacity: 0;
|
|
17
|
+
position: absolute;
|
|
18
|
+
/* Use negative inset for 24x24 pixel hit area */
|
|
19
|
+
inset: var(--form-element-inset);
|
|
20
|
+
}
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* Custom switch marker
|
|
22
24
|
*/
|
|
23
|
-
.sui-
|
|
25
|
+
.sui-Switch:before {
|
|
24
26
|
content: '';
|
|
25
27
|
display: block;
|
|
26
28
|
background-color: var(--foreground-high);
|
|
@@ -34,16 +36,14 @@
|
|
|
34
36
|
/**
|
|
35
37
|
* Hover - uses relative border/background colours to darken/lighten in both normal & error state
|
|
36
38
|
*/
|
|
37
|
-
|
|
38
|
-
.sui-Switch:hover .sui-SwitchMark {
|
|
39
|
+
.sui-Switch:has(.sui-SwitchInput:hover) {
|
|
39
40
|
border-color: light-dark(
|
|
40
41
|
oklch(from var(--border-color) calc(l - var(--hover-lightness-delta)) c h),
|
|
41
42
|
oklch(from var(--border-color) calc(l + var(--hover-lightness-delta)) c h)
|
|
42
43
|
);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
.sui-Switch:hover .sui-SwitchInput:is(:checked) + .sui-SwitchMark {
|
|
46
|
+
.sui-Switch:has(.sui-SwitchInput:is(:checked):hover) {
|
|
47
47
|
background-color: light-dark(
|
|
48
48
|
oklch(from var(--background-color) calc(l - var(--hover-lightness-delta)) c h),
|
|
49
49
|
oklch(from var(--background-color) calc(l + var(--hover-lightness-delta)) c h)
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
/**
|
|
54
54
|
* Focus
|
|
55
55
|
*/
|
|
56
|
-
.sui-SwitchInput:focus-visible
|
|
56
|
+
.sui-Switch:has(.sui-SwitchInput:focus-visible) {
|
|
57
57
|
outline: var(--focus-outline);
|
|
58
58
|
outline-offset: var(--focus-offset);
|
|
59
59
|
}
|
|
@@ -61,12 +61,12 @@
|
|
|
61
61
|
/**
|
|
62
62
|
* Checked
|
|
63
63
|
*/
|
|
64
|
-
.sui-
|
|
64
|
+
.sui-Switch:has(.sui-SwitchInput:checked) {
|
|
65
65
|
--background-color: var(--active-background-emphasized);
|
|
66
66
|
--border-color: transparent;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
.sui-
|
|
69
|
+
.sui-Switch:has(.sui-SwitchInput:checked):before {
|
|
70
70
|
background-color: var(--active-foreground-emphasized);
|
|
71
71
|
translate: calc(var(--width) - 175%);
|
|
72
72
|
}
|
|
@@ -74,46 +74,45 @@
|
|
|
74
74
|
/**
|
|
75
75
|
* Disabled
|
|
76
76
|
*/
|
|
77
|
-
.sui-
|
|
77
|
+
.sui-Switch:has(.sui-SwitchInput:disabled) {
|
|
78
78
|
--background-color: var(--inert-background);
|
|
79
79
|
--border-color: var(--separator-low);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
.sui-
|
|
82
|
+
.sui-Switch:has(.sui-SwitchInput:disabled):before {
|
|
83
83
|
background: var(--inert-foreground);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
.sui-Switch:has(:disabled) {
|
|
86
|
+
.sui-SwitchInput:disabled {
|
|
88
87
|
pointer-events: none;
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
/**
|
|
92
91
|
* Disabled and checked
|
|
93
92
|
*/
|
|
94
|
-
.sui-SwitchInput:disabled:checked
|
|
93
|
+
.sui-Switch:has(.sui-SwitchInput:disabled:checked) {
|
|
95
94
|
--background-color: var(--inert-foreground);
|
|
96
95
|
--border-color: transparent;
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
.sui-SwitchInput:disabled:checked
|
|
98
|
+
.sui-Switch:has(.sui-SwitchInput:disabled:checked):before {
|
|
100
99
|
background-color: var(--inert-background);
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
/**
|
|
104
103
|
* Error
|
|
105
104
|
*/
|
|
106
|
-
.sui-
|
|
105
|
+
.sui-Switch:has(.sui-SwitchInput[aria-invalid="true"]) {
|
|
107
106
|
--border-color: var(--error-separator);
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
.sui-
|
|
109
|
+
.sui-Switch:has(.sui-SwitchInput:not(:checked)[aria-invalid="true"]):before {
|
|
111
110
|
background-color: var(--error-separator);
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
/**
|
|
115
114
|
* Error and checked
|
|
116
115
|
*/
|
|
117
|
-
.sui-
|
|
116
|
+
.sui-Switch:has(.sui-SwitchInput:checked[aria-invalid="true"]) {
|
|
118
117
|
--background-color: var(--error-background-emphasized);
|
|
119
118
|
}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import {type MarginProps, marginProps} from '../../props/margin'
|
|
2
1
|
import {type PropDef} from '../../types/PropDef'
|
|
3
2
|
|
|
4
3
|
/** @beta */
|
|
5
|
-
export interface SwitchProps extends React.ComponentProps<'input'
|
|
4
|
+
export interface SwitchProps extends React.ComponentProps<'input'> {
|
|
6
5
|
/**
|
|
7
|
-
* Applies error styling to the switch track.
|
|
8
|
-
* @remarks Use when form validation fails. Pair with a visible error message.
|
|
6
|
+
* Applies error styling to the switch track for invalid states.
|
|
7
|
+
* @remarks Use when form validation fails. Pair with a visible error message.
|
|
9
8
|
*/
|
|
10
9
|
hasError?: boolean
|
|
11
|
-
/**
|
|
12
|
-
* Visible label next to the switch.
|
|
13
|
-
*/
|
|
14
|
-
label: React.ReactNode
|
|
15
10
|
}
|
|
16
11
|
|
|
17
12
|
export const switchProps: Record<string, PropDef> = {
|
|
18
13
|
hasError: {
|
|
19
14
|
type: 'boolean',
|
|
20
15
|
},
|
|
21
|
-
label: {
|
|
22
|
-
type: 'string',
|
|
23
|
-
},
|
|
24
|
-
...marginProps,
|
|
25
16
|
}
|