@sanity/ui 1.0.0-next.3 → 1.0.1

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.
Files changed (146) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -2
  3. package/dist/{types/src/index.d.ts → index.d.ts} +4450 -4398
  4. package/dist/{sanity-ui.esm.js → index.esm.js} +889 -2678
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/{sanity-ui.js → index.js} +883 -2688
  7. package/dist/index.js.map +1 -0
  8. package/package.json +114 -23
  9. package/src/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
  10. package/src/components/autocomplete/__workshop__/example.tsx +1 -1
  11. package/src/components/autocomplete/__workshop__/index.ts +36 -32
  12. package/src/components/autocomplete/autocomplete.styles.tsx +22 -28
  13. package/src/components/autocomplete/autocomplete.tsx +1 -2
  14. package/src/components/autocomplete/constants.ts +3 -8
  15. package/src/components/breadcrumbs/__workshop__/index.ts +11 -7
  16. package/src/components/breadcrumbs/breadcrumbs.styles.ts +13 -18
  17. package/src/components/dialog/__workshop__/index.ts +13 -9
  18. package/src/components/dialog/dialog.tsx +53 -67
  19. package/src/components/hotkeys/__workshop__/index.ts +11 -3
  20. package/src/components/hotkeys/hotkeys.tsx +12 -16
  21. package/src/components/menu/__workshop__/index.ts +71 -67
  22. package/src/components/menu/menu.tsx +5 -7
  23. package/src/components/menu/menuButton.tsx +16 -14
  24. package/src/components/menu/menuDivider.ts +8 -10
  25. package/src/components/skeleton/__workshop__/index.ts +8 -4
  26. package/src/components/skeleton/skeleton.tsx +4 -6
  27. package/src/components/skeleton/styles.ts +13 -9
  28. package/src/components/skeleton/textSkeleton.tsx +12 -14
  29. package/src/components/tab/__workshop__/index.ts +11 -3
  30. package/src/components/toast/__workshop__/index.ts +16 -4
  31. package/src/components/toast/toast.tsx +6 -11
  32. package/src/components/toast/toastProvider.tsx +18 -22
  33. package/src/components/tree/__workshop__/basic.perf.ts +1 -14
  34. package/src/components/tree/__workshop__/basic.tsx +1 -1
  35. package/src/components/tree/__workshop__/index.ts +12 -8
  36. package/src/components/tree/style.ts +78 -76
  37. package/src/components/tree/treeItem.tsx +7 -12
  38. package/src/global.ts +6 -0
  39. package/src/hooks/useElementRect/__workshop__/index.ts +11 -3
  40. package/src/hooks/useMediaIndex/__workshop__/index.ts +11 -3
  41. package/src/primitives/_selectable/selectable.tsx +4 -7
  42. package/src/primitives/_selectable/style.ts +85 -82
  43. package/src/primitives/avatar/__workshop__/index.ts +16 -12
  44. package/src/primitives/avatar/avatar.tsx +9 -12
  45. package/src/primitives/avatar/avatarCounter.tsx +22 -24
  46. package/src/primitives/avatar/avatarStack.tsx +16 -14
  47. package/src/primitives/avatar/styles.ts +1 -1
  48. package/src/primitives/badge/__workshop__/index.ts +16 -12
  49. package/src/primitives/badge/__workshop__/tones.tsx +1 -1
  50. package/src/primitives/badge/badge.tsx +6 -5
  51. package/src/primitives/box/__workshop__/index.ts +16 -4
  52. package/src/primitives/box/box.tsx +21 -49
  53. package/src/primitives/button/__workshop__/index.ts +51 -47
  54. package/src/primitives/button/__workshop__/sanityUploadButton.tsx +19 -20
  55. package/src/primitives/button/__workshop__/styled1.tsx +6 -6
  56. package/src/primitives/button/button.tsx +20 -26
  57. package/src/primitives/button/styles.ts +30 -29
  58. package/src/primitives/card/__workshop__/index.ts +15 -11
  59. package/src/primitives/card/card.tsx +9 -25
  60. package/src/primitives/card/styles.ts +119 -114
  61. package/src/primitives/checkbox/__workshop__/index.ts +10 -6
  62. package/src/primitives/checkbox/checkbox.tsx +4 -4
  63. package/src/primitives/checkbox/styles.ts +71 -69
  64. package/src/primitives/code/__workshop__/index.ts +16 -12
  65. package/src/primitives/code/code.tsx +3 -5
  66. package/src/primitives/code/styles.ts +20 -18
  67. package/src/primitives/container/__workshop__/index.ts +5 -3
  68. package/src/primitives/container/container.tsx +5 -4
  69. package/src/primitives/flex/__workshop__/index.ts +8 -4
  70. package/src/primitives/flex/flex.tsx +7 -23
  71. package/src/primitives/grid/__workshop__/index.ts +7 -3
  72. package/src/primitives/grid/grid.tsx +4 -27
  73. package/src/primitives/heading/__workshop__/index.ts +16 -12
  74. package/src/primitives/heading/heading.tsx +10 -17
  75. package/src/primitives/heading/styles.ts +45 -36
  76. package/src/primitives/inline/__workshop__/index.ts +5 -3
  77. package/src/primitives/inline/inline.tsx +3 -5
  78. package/src/primitives/kbd/__workshop__/index.ts +5 -3
  79. package/src/primitives/kbd/kbd.tsx +12 -13
  80. package/src/primitives/label/__workshop__/index.ts +16 -12
  81. package/src/primitives/label/label.tsx +13 -18
  82. package/src/primitives/label/styles.ts +24 -18
  83. package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -1
  84. package/src/primitives/popover/__workshop__/TestStory.tsx +0 -1
  85. package/src/primitives/popover/__workshop__/index.ts +36 -32
  86. package/src/primitives/popover/constants.ts +0 -3
  87. package/src/primitives/popover/floating-ui/size.ts +40 -25
  88. package/src/primitives/popover/popover.tsx +220 -196
  89. package/src/primitives/popover/popoverArrow.tsx +42 -48
  90. package/src/primitives/popover/popoverCard.tsx +12 -22
  91. package/src/primitives/radio/__workshop__/index.ts +8 -4
  92. package/src/primitives/radio/radio.tsx +3 -3
  93. package/src/primitives/radio/styles.ts +73 -73
  94. package/src/primitives/select/__workshop__/index.ts +8 -4
  95. package/src/primitives/select/select.tsx +9 -11
  96. package/src/primitives/select/styles.ts +77 -77
  97. package/src/primitives/spinner/__workshop__/index.ts +11 -7
  98. package/src/primitives/spinner/spinner.tsx +2 -5
  99. package/src/primitives/stack/__workshop__/index.ts +11 -7
  100. package/src/primitives/stack/stack.tsx +3 -5
  101. package/src/primitives/switch/__workshop__/index.ts +8 -4
  102. package/src/primitives/switch/styles.ts +119 -112
  103. package/src/primitives/switch/switch.tsx +6 -6
  104. package/src/primitives/text/__workshop__/index.ts +21 -17
  105. package/src/primitives/text/styles.ts +51 -45
  106. package/src/primitives/text/text.tsx +11 -16
  107. package/src/primitives/textArea/__workshop__/index.ts +11 -7
  108. package/src/primitives/textArea/textArea.tsx +15 -22
  109. package/src/primitives/textInput/__workshop__/index.ts +46 -42
  110. package/src/primitives/textInput/__workshop__/plain.tsx +2 -1
  111. package/src/primitives/textInput/textInput.tsx +50 -69
  112. package/src/primitives/tooltip/__workshop__/index.ts +11 -7
  113. package/src/primitives/tooltip/tooltip.tsx +3 -6
  114. package/src/primitives/tooltip/tooltipArrow.tsx +69 -59
  115. package/src/styles/border/borderStyle.ts +10 -18
  116. package/src/styles/box/boxStyle.ts +14 -18
  117. package/src/styles/flex/flexItemStyle.ts +7 -1
  118. package/src/styles/flex/flexStyle.ts +14 -9
  119. package/src/styles/grid/gridItemStyle.ts +18 -30
  120. package/src/styles/grid/gridStyle.ts +25 -33
  121. package/src/styles/helpers.ts +2 -2
  122. package/src/styles/index.ts +0 -1
  123. package/src/styles/input/textInputStyle.ts +127 -123
  124. package/src/styles/margin/marginStyle.ts +11 -10
  125. package/src/styles/margin/marginsStyle.test.ts +12 -10
  126. package/src/styles/padding/paddingStyle.test.ts +12 -10
  127. package/src/styles/padding/paddingStyle.ts +9 -10
  128. package/src/theme/__workshop__/index.ts +26 -22
  129. package/src/theme/{ThemeContext.ts → themeContext.ts} +0 -0
  130. package/src/utils/boundaryElement/__workshop__/index.ts +11 -7
  131. package/src/utils/elementQuery/__workshop__/index.ts +11 -7
  132. package/src/utils/layer/__workshop__/index.ts +21 -17
  133. package/src/utils/layer/layer.tsx +4 -6
  134. package/src/utils/portal/__workshop__/index.ts +11 -7
  135. package/src/utils/srOnly/srOnly.tsx +8 -10
  136. package/src/utils/virtualList/__workshop__/index.ts +26 -22
  137. package/src/utils/virtualList/virtualList.tsx +10 -14
  138. package/dist/sanity-ui.esm.js.map +0 -1
  139. package/dist/sanity-ui.js.map +0 -1
  140. package/src/__workshop__/color/overview.tsx +0 -101
  141. package/src/__workshop__/index.ts +0 -10
  142. package/src/icons/__workshop__/.eslintrc +0 -5
  143. package/src/icons/__workshop__/index.tsx +0 -6
  144. package/src/icons/__workshop__/overview.tsx +0 -76
  145. package/src/styles/compose.ts +0 -35
  146. 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(): CSSObject {
13
- return {
14
- position: 'relative',
15
- width: 'stretch',
12
+ function rootStyle(): FlattenSimpleInterpolation {
13
+ return css`
14
+ position: relative;
15
+ width: stretch;
16
16
 
17
- '&:not([hidden])': {
18
- display: 'inline-block',
19
- },
20
- }
17
+ &:not([hidden]) {
18
+ display: inline-block;
19
+ }
20
+ `
21
21
  }
22
22
 
23
- function inputBaseStyle(props: ThemeProps): CSSObject {
23
+ function inputBaseStyle(props: ThemeProps): FlattenSimpleInterpolation {
24
24
  const {theme} = props
25
25
  const font = theme.sanity.fonts.text
26
26
 
27
- return {
28
- WebkitFontSmoothing: 'antialiased',
29
- appearance: 'none',
30
- border: 0,
31
- fontFamily: font.family,
32
- color: 'inherit',
33
- width: '100%',
34
- outline: 'none',
35
- margin: 0,
36
-
37
- '&:disabled': {
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): CSSObject {
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
- backgroundColor: color.default.enabled.bg,
51
- color: color.default.enabled.fg,
52
- boxShadow: focusRingBorderStyle({
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
- '@media (hover: hover)': {
59
- '&:not(:disabled):hover': {
60
- backgroundColor: color.default.hovered.bg,
61
- color: color.default.hovered.fg,
62
- boxShadow: focusRingBorderStyle({
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
- '&:not(:disabled):focus': {
71
- boxShadow: focusRingStyle({
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
- '&[data-read-only]': {
79
- backgroundColor: color.default.readOnly.bg,
80
- color: color.default.readOnly.fg,
81
- boxShadow: focusRingBorderStyle({
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
- '&:not([data-read-only]):disabled': {
89
- backgroundColor: color.default.disabled.bg,
90
- color: color.default.disabled.fg,
91
- boxShadow: focusRingBorderStyle({
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): CSSObject {
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): CSSObject[] {
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) => CSSObject)
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): CSSObject {
131
+ function iconBoxStyle(props: ThemeProps): FlattenSimpleInterpolation {
132
132
  const {theme} = props
133
133
  const color = theme.sanity.color.input
134
134
 
135
- return {
136
- pointerEvents: 'none',
137
- position: 'absolute',
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
- '--card-fg-color': color.default.enabled.fg,
142
+ --card-fg-color: ${color.default.enabled.fg};
143
143
 
144
144
  /* hover */
145
- '@media (hover: hover)': {
146
- 'select:not(disabled):not(:read-only):hover + &&': {
147
- '--card-fg-color': color.default.hovered.fg,
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
- 'select:disabled + &&': {
153
- '--card-fg-color': color.default.disabled.fg,
154
- },
152
+ select:disabled + && {
153
+ --card-fg-color: ${color.default.disabled.fg};
154
+ }
155
155
 
156
156
  /* read-only */
157
- 'select[data-read-only] + &&': {
158
- '--card-fg-color': color.default.readOnly.fg,
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('primitives/spinner', 'Spinner', [
5
- {
6
- name: 'props',
7
- title: 'Props',
8
- component: lazy(() => import('./Props')),
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, memo} from 'react'
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 RawRoot = styled(Text)`
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('primitives/stack', 'Stack', [
5
- {
6
- name: 'plain',
7
- title: 'Plain',
8
- component: lazy(() => import('./plain')),
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, memo} from 'react'
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 = memo(
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('primitives/switch', 'Switch', [
5
- {name: 'props', title: 'Props', component: lazy(() => import('./props'))},
6
- {name: 'example', title: 'Example', component: lazy(() => import('./example'))},
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 {CSSObject} from 'styled-components'
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(): CSSObject {
7
- return {
8
- position: 'relative',
9
- '&:not([hidden])': {
10
- display: 'inline-block',
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(): CSSObject {
16
+ export function switchInputStyles(): FlattenSimpleInterpolation {
17
17
  // Visually hide the input element while keeping it interactive
18
- return {
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,
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
- zIndex: 1,
33
- }
32
+ z-index: 1;
33
+ `
34
34
  }
35
35
 
36
36
  /* Representation */
37
- export function switchRepresentationStyles(props: ThemeProps): CSSObject {
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
- '--switch-bg-color': color.default.enabled.bg,
44
- '--switch-fg-color': color.default.enabled.fg,
45
- '--switch-box-shadow': 'none',
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
- '&:not([hidden])': {
48
- display: 'block',
49
- },
50
- position: 'relative',
51
- width: rem(input.switch.width),
52
- height: rem(input.switch.height),
53
- borderRadius: rem(input.switch.height / 2),
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
- pointerEvents: '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
- zIndex: 1,
67
- boxShadow: 'var(--switch-box-shadow)',
68
- borderRadius: 'inherit',
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
- '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
- }
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): CSSObject {
105
+ export function switchTrackStyles(props: ThemeProps): FlattenSimpleInterpolation {
106
106
  const {theme} = props
107
107
  const {input} = theme.sanity
108
108
 
109
- return {
110
- '&:not([hidden])': {
111
- display: 'block',
112
- },
113
- backgroundColor: '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
- borderRadius: rem(input.switch.height / 2),
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
- ): CSSObject {
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
- '&: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
- borderRadius: rem(size / 2),
147
- transitionProperty: 'transform',
148
- transitionDuration: `${input.switch.transitionDurationMs}ms`,
149
- transitionTimingFunction: input.switch.transitionTimingFunction,
150
- background: 'var(--switch-fg-color)',
151
- transform: 'translate3d(0, 0, 0)',
152
-
153
- ...(checked ? {transform: `translate3d(${checkedOffset}px, 0, 0)`} : {}),
154
- ...($indeterminate ? {transform: `translate3d(${indeterminateOffset}px, 0, 0)`} : {}),
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, memo, useEffect} from 'react'
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 = memo(styled.span(switchBaseStyles))
20
- const Input = memo(styled.input(switchInputStyles))
21
- const Representation = memo(styled.span(switchRepresentationStyles))
22
- const Track = memo(styled.span(switchTrackStyles))
23
- const Thumb = memo(styled.span<{$checked?: boolean; $indeterminate?: boolean}>(switchThumbStyles))
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