@sanity/ui 1.0.0-next.3 → 1.0.0
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/LICENSE +1 -1
- package/README.md +2 -2
- package/dist/{types/src/index.d.ts → index.d.ts} +4450 -4398
- package/dist/{sanity-ui.esm.js → index.esm.js} +888 -2678
- package/dist/index.esm.js.map +1 -0
- package/dist/{sanity-ui.js → index.js} +882 -2688
- package/dist/index.js.map +1 -0
- package/package.json +112 -23
- package/src/components/autocomplete/__workshop__/example.tsx +1 -1
- package/src/components/autocomplete/__workshop__/index.ts +36 -32
- package/src/components/autocomplete/autocomplete.styles.tsx +22 -28
- package/src/components/autocomplete/autocomplete.tsx +1 -2
- package/src/components/autocomplete/constants.ts +3 -8
- package/src/components/breadcrumbs/__workshop__/index.ts +11 -7
- package/src/components/breadcrumbs/breadcrumbs.styles.ts +13 -18
- package/src/components/dialog/__workshop__/index.ts +13 -9
- package/src/components/dialog/dialog.tsx +53 -67
- package/src/components/hotkeys/__workshop__/index.ts +11 -3
- package/src/components/hotkeys/hotkeys.tsx +12 -16
- package/src/components/menu/__workshop__/index.ts +71 -67
- package/src/components/menu/menu.tsx +5 -7
- package/src/components/menu/menuButton.tsx +16 -14
- package/src/components/menu/menuDivider.ts +8 -10
- package/src/components/skeleton/__workshop__/index.ts +8 -4
- package/src/components/skeleton/skeleton.tsx +4 -6
- package/src/components/skeleton/styles.ts +13 -9
- package/src/components/skeleton/textSkeleton.tsx +12 -14
- package/src/components/tab/__workshop__/index.ts +11 -3
- package/src/components/toast/__workshop__/index.ts +16 -4
- package/src/components/toast/toast.tsx +6 -11
- package/src/components/toast/toastProvider.tsx +18 -22
- package/src/components/tree/__workshop__/basic.perf.ts +1 -14
- package/src/components/tree/__workshop__/basic.tsx +1 -1
- package/src/components/tree/__workshop__/index.ts +12 -8
- package/src/components/tree/style.ts +78 -76
- package/src/components/tree/treeItem.tsx +7 -12
- package/src/hooks/useElementRect/__workshop__/index.ts +11 -3
- package/src/hooks/useMediaIndex/__workshop__/index.ts +11 -3
- package/src/primitives/_selectable/selectable.tsx +4 -7
- package/src/primitives/_selectable/style.ts +85 -82
- package/src/primitives/avatar/__workshop__/index.ts +16 -12
- package/src/primitives/avatar/avatar.tsx +9 -12
- package/src/primitives/avatar/avatarCounter.tsx +22 -24
- package/src/primitives/avatar/avatarStack.tsx +16 -14
- package/src/primitives/avatar/styles.ts +1 -1
- package/src/primitives/badge/__workshop__/index.ts +16 -12
- package/src/primitives/badge/__workshop__/tones.tsx +1 -1
- package/src/primitives/badge/badge.tsx +6 -5
- package/src/primitives/box/__workshop__/index.ts +16 -4
- package/src/primitives/box/box.tsx +21 -49
- package/src/primitives/button/__workshop__/index.ts +51 -47
- package/src/primitives/button/__workshop__/sanityUploadButton.tsx +19 -20
- package/src/primitives/button/__workshop__/styled1.tsx +6 -6
- package/src/primitives/button/button.tsx +20 -26
- package/src/primitives/button/styles.ts +30 -29
- package/src/primitives/card/__workshop__/index.ts +15 -11
- package/src/primitives/card/card.tsx +9 -25
- package/src/primitives/card/styles.ts +119 -114
- package/src/primitives/checkbox/__workshop__/index.ts +10 -6
- package/src/primitives/checkbox/checkbox.tsx +4 -4
- package/src/primitives/checkbox/styles.ts +71 -69
- package/src/primitives/code/__workshop__/index.ts +16 -12
- package/src/primitives/code/code.tsx +3 -5
- package/src/primitives/code/styles.ts +20 -18
- package/src/primitives/container/__workshop__/index.ts +5 -3
- package/src/primitives/container/container.tsx +5 -4
- package/src/primitives/flex/__workshop__/index.ts +8 -4
- package/src/primitives/flex/flex.tsx +7 -23
- package/src/primitives/grid/__workshop__/index.ts +7 -3
- package/src/primitives/grid/grid.tsx +4 -27
- package/src/primitives/heading/__workshop__/index.ts +16 -12
- package/src/primitives/heading/heading.tsx +10 -17
- package/src/primitives/heading/styles.ts +45 -36
- package/src/primitives/inline/__workshop__/index.ts +5 -3
- package/src/primitives/inline/inline.tsx +3 -5
- package/src/primitives/kbd/__workshop__/index.ts +5 -3
- package/src/primitives/kbd/kbd.tsx +12 -13
- package/src/primitives/label/__workshop__/index.ts +16 -12
- package/src/primitives/label/label.tsx +13 -18
- package/src/primitives/label/styles.ts +24 -18
- package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -1
- package/src/primitives/popover/__workshop__/TestStory.tsx +0 -1
- package/src/primitives/popover/__workshop__/index.ts +36 -32
- package/src/primitives/popover/constants.ts +0 -3
- package/src/primitives/popover/floating-ui/size.ts +40 -25
- package/src/primitives/popover/popover.tsx +220 -196
- package/src/primitives/popover/popoverArrow.tsx +42 -48
- package/src/primitives/popover/popoverCard.tsx +12 -22
- package/src/primitives/radio/__workshop__/index.ts +8 -4
- package/src/primitives/radio/radio.tsx +3 -3
- package/src/primitives/radio/styles.ts +73 -73
- package/src/primitives/select/__workshop__/index.ts +8 -4
- package/src/primitives/select/select.tsx +9 -11
- package/src/primitives/select/styles.ts +77 -77
- package/src/primitives/spinner/__workshop__/index.ts +11 -7
- package/src/primitives/spinner/spinner.tsx +2 -5
- package/src/primitives/stack/__workshop__/index.ts +11 -7
- package/src/primitives/stack/stack.tsx +3 -5
- package/src/primitives/switch/__workshop__/index.ts +8 -4
- package/src/primitives/switch/styles.ts +119 -112
- package/src/primitives/switch/switch.tsx +6 -6
- package/src/primitives/text/__workshop__/index.ts +21 -17
- package/src/primitives/text/styles.ts +51 -45
- package/src/primitives/text/text.tsx +11 -16
- package/src/primitives/textArea/__workshop__/index.ts +11 -7
- package/src/primitives/textArea/textArea.tsx +15 -22
- package/src/primitives/textInput/__workshop__/index.ts +46 -42
- package/src/primitives/textInput/__workshop__/plain.tsx +2 -1
- package/src/primitives/textInput/textInput.tsx +49 -69
- package/src/primitives/tooltip/__workshop__/index.ts +11 -7
- package/src/primitives/tooltip/tooltip.tsx +3 -6
- package/src/primitives/tooltip/tooltipArrow.tsx +69 -59
- package/src/styles/border/borderStyle.ts +10 -18
- package/src/styles/box/boxStyle.ts +14 -18
- package/src/styles/flex/flexItemStyle.ts +7 -1
- package/src/styles/flex/flexStyle.ts +14 -9
- package/src/styles/grid/gridItemStyle.ts +18 -30
- package/src/styles/grid/gridStyle.ts +25 -33
- package/src/styles/helpers.ts +2 -2
- package/src/styles/index.ts +0 -1
- package/src/styles/input/textInputStyle.ts +127 -123
- package/src/styles/margin/marginStyle.ts +11 -10
- package/src/styles/margin/marginsStyle.test.ts +12 -10
- package/src/styles/padding/paddingStyle.test.ts +12 -10
- package/src/styles/padding/paddingStyle.ts +9 -10
- package/src/theme/__workshop__/index.ts +26 -22
- package/src/theme/{ThemeContext.ts → themeContext.ts} +0 -0
- package/src/utils/boundaryElement/__workshop__/index.ts +11 -7
- package/src/utils/elementQuery/__workshop__/index.ts +11 -7
- package/src/utils/layer/__workshop__/index.ts +21 -17
- package/src/utils/layer/layer.tsx +4 -6
- package/src/utils/portal/__workshop__/index.ts +11 -7
- package/src/utils/srOnly/srOnly.tsx +8 -10
- package/src/utils/virtualList/__workshop__/index.ts +26 -22
- package/src/utils/virtualList/virtualList.tsx +10 -14
- package/dist/sanity-ui.esm.js.map +0 -1
- package/dist/sanity-ui.js.map +0 -1
- package/src/__workshop__/color/overview.tsx +0 -101
- package/src/__workshop__/index.ts +0 -10
- package/src/icons/__workshop__/.eslintrc +0 -5
- package/src/icons/__workshop__/index.tsx +0 -6
- package/src/icons/__workshop__/overview.tsx +0 -76
- package/src/styles/compose.ts +0 -35
- package/src/utils/srOnly/__workshop__/.eslintrc +0 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {CSSObject} from 'styled-components'
|
|
1
|
+
import {css, CSSObject, FlattenSimpleInterpolation} from 'styled-components'
|
|
2
2
|
import {rem, _responsive, ThemeProps} from '../../styles'
|
|
3
3
|
import {
|
|
4
4
|
focusRingBorderStyle,
|
|
@@ -9,98 +9,98 @@ import {
|
|
|
9
9
|
} from '../../styles/internal'
|
|
10
10
|
import {ThemeFontSize} from '../../theme'
|
|
11
11
|
|
|
12
|
-
function rootStyle():
|
|
13
|
-
return
|
|
14
|
-
position:
|
|
15
|
-
width:
|
|
12
|
+
function rootStyle(): FlattenSimpleInterpolation {
|
|
13
|
+
return css`
|
|
14
|
+
position: relative;
|
|
15
|
+
width: stretch;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
display:
|
|
19
|
-
}
|
|
20
|
-
|
|
17
|
+
&:not([hidden]) {
|
|
18
|
+
display: inline-block;
|
|
19
|
+
}
|
|
20
|
+
`
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function inputBaseStyle(props: ThemeProps):
|
|
23
|
+
function inputBaseStyle(props: ThemeProps): FlattenSimpleInterpolation {
|
|
24
24
|
const {theme} = props
|
|
25
25
|
const font = theme.sanity.fonts.text
|
|
26
26
|
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
appearance:
|
|
30
|
-
border: 0
|
|
31
|
-
|
|
32
|
-
color:
|
|
33
|
-
width:
|
|
34
|
-
outline:
|
|
35
|
-
margin: 0
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
opacity: 1
|
|
39
|
-
}
|
|
40
|
-
|
|
27
|
+
return css`
|
|
28
|
+
-webkit-font-smoothing: antialiased;
|
|
29
|
+
appearance: none;
|
|
30
|
+
border: 0;
|
|
31
|
+
font-family: ${font.family};
|
|
32
|
+
color: inherit;
|
|
33
|
+
width: 100%;
|
|
34
|
+
outline: none;
|
|
35
|
+
margin: 0;
|
|
36
|
+
|
|
37
|
+
&:disabled {
|
|
38
|
+
opacity: 1;
|
|
39
|
+
}
|
|
40
|
+
`
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function inputColorStyle(props: ThemeProps)
|
|
43
|
+
function inputColorStyle(props: ThemeProps) {
|
|
44
44
|
const {theme} = props
|
|
45
45
|
const {focusRing, input} = theme.sanity
|
|
46
46
|
const color = theme.sanity.color.input
|
|
47
47
|
|
|
48
|
-
return
|
|
48
|
+
return css`
|
|
49
49
|
/* enabled */
|
|
50
|
-
|
|
51
|
-
color: color.default.enabled.fg
|
|
52
|
-
|
|
50
|
+
background-color: ${color.default.enabled.bg};
|
|
51
|
+
color: ${color.default.enabled.fg};
|
|
52
|
+
box-shadow: ${focusRingBorderStyle({
|
|
53
53
|
color: color.default.enabled.border,
|
|
54
54
|
width: input.border.width,
|
|
55
|
-
})
|
|
55
|
+
})};
|
|
56
56
|
|
|
57
57
|
/* hovered */
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
color: color.default.hovered.fg
|
|
62
|
-
|
|
58
|
+
@media (hover: hover) {
|
|
59
|
+
&:not(:disabled):hover {
|
|
60
|
+
background-color: ${color.default.hovered.bg};
|
|
61
|
+
color: ${color.default.hovered.fg};
|
|
62
|
+
box-shadow: ${focusRingBorderStyle({
|
|
63
63
|
color: color.default.hovered.border,
|
|
64
64
|
width: input.border.width,
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
}
|
|
65
|
+
})};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
68
|
|
|
69
69
|
/* focused */
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
&:not(:disabled):focus {
|
|
71
|
+
box-shadow: ${focusRingStyle({
|
|
72
72
|
border: {width: input.border.width, color: color.default.enabled.border},
|
|
73
73
|
focusRing,
|
|
74
|
-
})
|
|
75
|
-
}
|
|
74
|
+
})};
|
|
75
|
+
}
|
|
76
76
|
|
|
77
77
|
/* read-only */
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
color: color.default.readOnly.fg
|
|
81
|
-
|
|
78
|
+
&[data-read-only] {
|
|
79
|
+
background-color: ${color.default.readOnly.bg};
|
|
80
|
+
color: ${color.default.readOnly.fg};
|
|
81
|
+
box-shadow: ${focusRingBorderStyle({
|
|
82
82
|
color: color.default.readOnly.border,
|
|
83
83
|
width: input.border.width,
|
|
84
|
-
})
|
|
85
|
-
}
|
|
84
|
+
})};
|
|
85
|
+
}
|
|
86
86
|
|
|
87
87
|
/* disabled */
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
color: color.default.disabled.fg
|
|
91
|
-
|
|
88
|
+
&:not([data-read-only]):disabled {
|
|
89
|
+
background-color: ${color.default.disabled.bg};
|
|
90
|
+
color: ${color.default.disabled.fg};
|
|
91
|
+
box-shadow: ${focusRingBorderStyle({
|
|
92
92
|
color: color.default.disabled.border,
|
|
93
93
|
width: input.border.width,
|
|
94
|
-
})
|
|
95
|
-
}
|
|
96
|
-
|
|
94
|
+
})};
|
|
95
|
+
}
|
|
96
|
+
`
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
function textSize(size: ThemeFontSize)
|
|
99
|
+
function textSize(size: ThemeFontSize) {
|
|
100
100
|
return {fontSize: rem(size.fontSize), lineHeight: rem(size.lineHeight)}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
function inputTextSizeStyle(props: {$fontSize: number[]} & ThemeProps)
|
|
103
|
+
function inputTextSizeStyle(props: {$fontSize: number[]} & ThemeProps) {
|
|
104
104
|
const {theme, $fontSize} = props
|
|
105
105
|
const {sizes} = theme.sanity.fonts.text
|
|
106
106
|
|
|
@@ -117,7 +117,7 @@ function inputStyle(): Array<
|
|
|
117
117
|
$space: number[]
|
|
118
118
|
} & ThemeProps
|
|
119
119
|
) => CSSObject[])
|
|
120
|
-
| ((props: ThemeProps) =>
|
|
120
|
+
| ((props: ThemeProps) => FlattenSimpleInterpolation)
|
|
121
121
|
> {
|
|
122
122
|
return [
|
|
123
123
|
responsiveRadiusStyle,
|
|
@@ -128,36 +128,36 @@ function inputStyle(): Array<
|
|
|
128
128
|
]
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
function iconBoxStyle(props: ThemeProps):
|
|
131
|
+
function iconBoxStyle(props: ThemeProps): FlattenSimpleInterpolation {
|
|
132
132
|
const {theme} = props
|
|
133
133
|
const color = theme.sanity.color.input
|
|
134
134
|
|
|
135
|
-
return
|
|
136
|
-
|
|
137
|
-
position:
|
|
138
|
-
top: 0
|
|
139
|
-
right: 0
|
|
135
|
+
return css`
|
|
136
|
+
pointer-events: none;
|
|
137
|
+
position: absolute;
|
|
138
|
+
top: 0;
|
|
139
|
+
right: 0;
|
|
140
140
|
|
|
141
141
|
/* enabled */
|
|
142
|
-
|
|
142
|
+
--card-fg-color: ${color.default.enabled.fg};
|
|
143
143
|
|
|
144
144
|
/* hover */
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
}
|
|
145
|
+
@media (hover: hover) {
|
|
146
|
+
select:not(disabled):not(:read-only):hover + && {
|
|
147
|
+
--card-fg-color: ${color.default.hovered.fg};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
150
|
|
|
151
151
|
/* disabled */
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
152
|
+
select:disabled + && {
|
|
153
|
+
--card-fg-color: ${color.default.disabled.fg};
|
|
154
|
+
}
|
|
155
155
|
|
|
156
156
|
/* read-only */
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
157
|
+
select[data-read-only] + && {
|
|
158
|
+
--card-fg-color: ${color.default.readOnly.fg};
|
|
159
|
+
}
|
|
160
|
+
`
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
export const selectStyle = {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import {defineScope} from '@sanity/ui-workshop'
|
|
2
2
|
import {lazy} from 'react'
|
|
3
3
|
|
|
4
|
-
export default defineScope(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export default defineScope({
|
|
5
|
+
name: 'primitives/spinner',
|
|
6
|
+
title: 'Spinner',
|
|
7
|
+
stories: [
|
|
8
|
+
{
|
|
9
|
+
name: 'props',
|
|
10
|
+
title: 'Props',
|
|
11
|
+
component: lazy(() => import('./Props')),
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {SpinnerIcon} from '@sanity/icons'
|
|
2
|
-
import {forwardRef
|
|
2
|
+
import {forwardRef} from 'react'
|
|
3
3
|
import styled, {keyframes} from 'styled-components'
|
|
4
4
|
import {Text} from '../text'
|
|
5
5
|
|
|
@@ -21,15 +21,12 @@ const rotate = keyframes`
|
|
|
21
21
|
}
|
|
22
22
|
`
|
|
23
23
|
|
|
24
|
-
const
|
|
24
|
+
const Root = styled(Text)`
|
|
25
25
|
& > span > svg {
|
|
26
26
|
animation: ${rotate} 500ms linear infinite;
|
|
27
27
|
}
|
|
28
28
|
`
|
|
29
29
|
|
|
30
|
-
// NOTE: workaround for VS Code syntax highlighting
|
|
31
|
-
const Root = memo(RawRoot)
|
|
32
|
-
|
|
33
30
|
/**
|
|
34
31
|
* @public
|
|
35
32
|
*/
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import {defineScope} from '@sanity/ui-workshop'
|
|
2
2
|
import {lazy} from 'react'
|
|
3
3
|
|
|
4
|
-
export default defineScope(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export default defineScope({
|
|
5
|
+
name: 'primitives/stack',
|
|
6
|
+
title: 'Stack',
|
|
7
|
+
stories: [
|
|
8
|
+
{
|
|
9
|
+
name: 'plain',
|
|
10
|
+
title: 'Plain',
|
|
11
|
+
component: lazy(() => import('./plain')),
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {forwardRef
|
|
1
|
+
import {forwardRef} from 'react'
|
|
2
|
+
import styled from 'styled-components'
|
|
2
3
|
import {useArrayProp} from '../../hooks'
|
|
3
|
-
import {compose} from '../../styles'
|
|
4
4
|
import {Box, BoxProps} from '../box'
|
|
5
5
|
import {stackBaseStyle, responsiveStackSpaceStyle, ResponsiveStackSpaceStyleProps} from './styles'
|
|
6
6
|
|
|
@@ -12,9 +12,7 @@ export interface StackProps extends BoxProps {
|
|
|
12
12
|
space?: number | number[]
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const Root =
|
|
16
|
-
compose<ResponsiveStackSpaceStyleProps>(Box, [stackBaseStyle, responsiveStackSpaceStyle])
|
|
17
|
-
)
|
|
15
|
+
const Root = styled(Box)<ResponsiveStackSpaceStyleProps>(stackBaseStyle, responsiveStackSpaceStyle)
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* @public
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import {defineScope} from '@sanity/ui-workshop'
|
|
2
2
|
import {lazy} from 'react'
|
|
3
3
|
|
|
4
|
-
export default defineScope(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export default defineScope({
|
|
5
|
+
name: 'primitives/switch',
|
|
6
|
+
title: 'Switch',
|
|
7
|
+
stories: [
|
|
8
|
+
{name: 'props', title: 'Props', component: lazy(() => import('./props'))},
|
|
9
|
+
{name: 'example', title: 'Example', component: lazy(() => import('./example'))},
|
|
10
|
+
],
|
|
11
|
+
})
|
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {css, FlattenSimpleInterpolation} from 'styled-components'
|
|
2
2
|
import {rem, ThemeProps} from '../../styles'
|
|
3
3
|
import {focusRingStyle} from '../../styles/internal'
|
|
4
4
|
|
|
5
5
|
/* Root */
|
|
6
|
-
export function switchBaseStyles():
|
|
7
|
-
return
|
|
8
|
-
position:
|
|
9
|
-
|
|
10
|
-
display:
|
|
11
|
-
}
|
|
12
|
-
|
|
6
|
+
export function switchBaseStyles(): FlattenSimpleInterpolation {
|
|
7
|
+
return css`
|
|
8
|
+
position: relative;
|
|
9
|
+
&:not([hidden]) {
|
|
10
|
+
display: inline-block;
|
|
11
|
+
}
|
|
12
|
+
`
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/* Input */
|
|
16
|
-
export function switchInputStyles():
|
|
16
|
+
export function switchInputStyles(): FlattenSimpleInterpolation {
|
|
17
17
|
// Visually hide the input element while keeping it interactive
|
|
18
|
-
return
|
|
19
|
-
position:
|
|
20
|
-
top: 0
|
|
21
|
-
right: 0
|
|
22
|
-
bottom: 0
|
|
23
|
-
left: 0
|
|
24
|
-
opacity: 0
|
|
25
|
-
height:
|
|
26
|
-
width:
|
|
27
|
-
outline:
|
|
28
|
-
padding: 0
|
|
29
|
-
margin: 0
|
|
18
|
+
return css`
|
|
19
|
+
position: absolute;
|
|
20
|
+
top: 0;
|
|
21
|
+
right: 0;
|
|
22
|
+
bottom: 0;
|
|
23
|
+
left: 0;
|
|
24
|
+
opacity: 0;
|
|
25
|
+
height: 100%;
|
|
26
|
+
width: 100%;
|
|
27
|
+
outline: none;
|
|
28
|
+
padding: 0;
|
|
29
|
+
margin: 0;
|
|
30
30
|
|
|
31
31
|
/* Place the input element above the representation element */
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
z-index: 1;
|
|
33
|
+
`
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/* Representation */
|
|
37
|
-
export function switchRepresentationStyles(props: ThemeProps):
|
|
37
|
+
export function switchRepresentationStyles(props: ThemeProps): FlattenSimpleInterpolation {
|
|
38
38
|
const {theme} = props
|
|
39
39
|
const {focusRing, input} = theme.sanity
|
|
40
40
|
const color = theme.sanity.color.button.default
|
|
41
41
|
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
return css`
|
|
43
|
+
--switch-bg-color: ${color.default.enabled.bg};
|
|
44
|
+
--switch-fg-color: ${color.default.enabled.fg};
|
|
45
|
+
--switch-box-shadow: none;
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
display:
|
|
49
|
-
}
|
|
50
|
-
position:
|
|
51
|
-
width: rem(input.switch.width)
|
|
52
|
-
height: rem(input.switch.height)
|
|
53
|
-
|
|
47
|
+
&:not([hidden]) {
|
|
48
|
+
display: block;
|
|
49
|
+
}
|
|
50
|
+
position: relative;
|
|
51
|
+
width: ${rem(input.switch.width)};
|
|
52
|
+
height: ${rem(input.switch.height)};
|
|
53
|
+
border-radius: ${rem(input.switch.height / 2)};
|
|
54
54
|
|
|
55
55
|
/* Make sure it’s not possible to interact with the wrapper element */
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
content: '
|
|
60
|
-
display:
|
|
61
|
-
position:
|
|
62
|
-
top: 0
|
|
63
|
-
left: 0
|
|
64
|
-
right: 0
|
|
65
|
-
bottom: 0
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
56
|
+
pointer-events: none;
|
|
57
|
+
|
|
58
|
+
&:after {
|
|
59
|
+
content: '';
|
|
60
|
+
display: block;
|
|
61
|
+
position: absolute;
|
|
62
|
+
top: 0;
|
|
63
|
+
left: 0;
|
|
64
|
+
right: 0;
|
|
65
|
+
bottom: 0;
|
|
66
|
+
z-index: 1;
|
|
67
|
+
box-shadow: var(--switch-box-shadow);
|
|
68
|
+
border-radius: inherit;
|
|
69
|
+
}
|
|
70
70
|
|
|
71
71
|
/* Focus styles */
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
72
|
+
input:focus + && {
|
|
73
|
+
--switch-box-shadow: ${focusRingStyle({focusRing})};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
input:focus:not(:focus-visible) + && {
|
|
77
|
+
--switch-box-shadow: none;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
input:checked + && {
|
|
81
|
+
--switch-bg-color: ${color.positive.enabled.bg};
|
|
82
|
+
--switch-fg-color: ${color.positive.enabled.fg};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@media (hover: hover) {
|
|
86
|
+
input:not(:disabled):hover + && {
|
|
87
|
+
--switch-bg-color: ${color.default.hovered.bg};
|
|
88
|
+
--switch-fg-color: ${color.default.hovered.fg};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
input:not(:disabled):checked:hover + && {
|
|
92
|
+
--switch-bg-color: ${color.positive.hovered.bg};
|
|
93
|
+
--switch-fg-color: ${color.positive.hovered.fg};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
input:not([data-read-only]):disabled + && {
|
|
98
|
+
--switch-bg-color: ${color.default.disabled.bg};
|
|
99
|
+
--switch-fg-color: ${color.default.disabled.fg};
|
|
100
|
+
}
|
|
101
|
+
`
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/* Track */
|
|
105
|
-
export function switchTrackStyles(props: ThemeProps):
|
|
105
|
+
export function switchTrackStyles(props: ThemeProps): FlattenSimpleInterpolation {
|
|
106
106
|
const {theme} = props
|
|
107
107
|
const {input} = theme.sanity
|
|
108
108
|
|
|
109
|
-
return
|
|
110
|
-
|
|
111
|
-
display:
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
position:
|
|
115
|
-
left: 0
|
|
116
|
-
top: 0
|
|
117
|
-
width: rem(input.switch.width)
|
|
118
|
-
height: rem(input.switch.height)
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
return css`
|
|
110
|
+
&:not([hidden]) {
|
|
111
|
+
display: block;
|
|
112
|
+
}
|
|
113
|
+
background-color: var(--switch-bg-color);
|
|
114
|
+
position: absolute;
|
|
115
|
+
left: 0;
|
|
116
|
+
top: 0;
|
|
117
|
+
width: ${rem(input.switch.width)};
|
|
118
|
+
height: ${rem(input.switch.height)};
|
|
119
|
+
border-radius: ${rem(input.switch.height / 2)};
|
|
120
|
+
`
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/* Thumb */
|
|
124
124
|
export function switchThumbStyles(
|
|
125
125
|
props: {$checked?: boolean; $indeterminate?: boolean} & ThemeProps
|
|
126
|
-
):
|
|
126
|
+
): FlattenSimpleInterpolation {
|
|
127
127
|
const {$indeterminate, theme} = props
|
|
128
128
|
const {input} = theme.sanity
|
|
129
129
|
const trackWidth = input.switch.width
|
|
@@ -134,23 +134,30 @@ export function switchThumbStyles(
|
|
|
134
134
|
const indeterminateOffset = trackWidth / 2 - size / 2 - trackPadding
|
|
135
135
|
const checked = $indeterminate !== true && props.$checked === true
|
|
136
136
|
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
display:
|
|
140
|
-
}
|
|
141
|
-
position:
|
|
142
|
-
left: rem(trackPadding)
|
|
143
|
-
top: rem(trackPadding)
|
|
144
|
-
height: rem(size)
|
|
145
|
-
width: rem(size)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
background:
|
|
151
|
-
transform:
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
137
|
+
return css`
|
|
138
|
+
&:not([hidden]) {
|
|
139
|
+
display: block;
|
|
140
|
+
}
|
|
141
|
+
position: absolute;
|
|
142
|
+
left: ${rem(trackPadding)};
|
|
143
|
+
top: ${rem(trackPadding)};
|
|
144
|
+
height: ${rem(size)};
|
|
145
|
+
width: ${rem(size)};
|
|
146
|
+
border-radius: ${rem(size / 2)};
|
|
147
|
+
transition-property: transform;
|
|
148
|
+
transition-duration: ${input.switch.transitionDurationMs}ms;
|
|
149
|
+
transition-timing-function: ${input.switch.transitionTimingFunction};
|
|
150
|
+
background: var(--switch-fg-color);
|
|
151
|
+
transform: translate3d(0, 0, 0);
|
|
152
|
+
|
|
153
|
+
${checked &&
|
|
154
|
+
css`
|
|
155
|
+
transform: translate3d(${checkedOffset}px, 0, 0);
|
|
156
|
+
`}
|
|
157
|
+
|
|
158
|
+
${$indeterminate &&
|
|
159
|
+
css`
|
|
160
|
+
transform: translate3d(${indeterminateOffset}px, 0, 0);
|
|
161
|
+
`}
|
|
162
|
+
`
|
|
156
163
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {forwardRef,
|
|
1
|
+
import {forwardRef, useEffect} from 'react'
|
|
2
2
|
import styled from 'styled-components'
|
|
3
3
|
import {useForwardedRef} from '../../hooks'
|
|
4
4
|
import {
|
|
@@ -16,11 +16,11 @@ export interface SwitchProps {
|
|
|
16
16
|
indeterminate?: boolean
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const Root =
|
|
20
|
-
const Input =
|
|
21
|
-
const Representation =
|
|
22
|
-
const Track =
|
|
23
|
-
const Thumb =
|
|
19
|
+
const Root = styled.span(switchBaseStyles)
|
|
20
|
+
const Input = styled.input(switchInputStyles)
|
|
21
|
+
const Representation = styled.span(switchRepresentationStyles)
|
|
22
|
+
const Track = styled.span(switchTrackStyles)
|
|
23
|
+
const Thumb = styled.span<{$checked?: boolean; $indeterminate?: boolean}>(switchThumbStyles)
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @public
|