@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.
Files changed (144) 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} +888 -2678
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/{sanity-ui.js → index.js} +882 -2688
  7. package/dist/index.js.map +1 -0
  8. package/package.json +112 -23
  9. package/src/components/autocomplete/__workshop__/example.tsx +1 -1
  10. package/src/components/autocomplete/__workshop__/index.ts +36 -32
  11. package/src/components/autocomplete/autocomplete.styles.tsx +22 -28
  12. package/src/components/autocomplete/autocomplete.tsx +1 -2
  13. package/src/components/autocomplete/constants.ts +3 -8
  14. package/src/components/breadcrumbs/__workshop__/index.ts +11 -7
  15. package/src/components/breadcrumbs/breadcrumbs.styles.ts +13 -18
  16. package/src/components/dialog/__workshop__/index.ts +13 -9
  17. package/src/components/dialog/dialog.tsx +53 -67
  18. package/src/components/hotkeys/__workshop__/index.ts +11 -3
  19. package/src/components/hotkeys/hotkeys.tsx +12 -16
  20. package/src/components/menu/__workshop__/index.ts +71 -67
  21. package/src/components/menu/menu.tsx +5 -7
  22. package/src/components/menu/menuButton.tsx +16 -14
  23. package/src/components/menu/menuDivider.ts +8 -10
  24. package/src/components/skeleton/__workshop__/index.ts +8 -4
  25. package/src/components/skeleton/skeleton.tsx +4 -6
  26. package/src/components/skeleton/styles.ts +13 -9
  27. package/src/components/skeleton/textSkeleton.tsx +12 -14
  28. package/src/components/tab/__workshop__/index.ts +11 -3
  29. package/src/components/toast/__workshop__/index.ts +16 -4
  30. package/src/components/toast/toast.tsx +6 -11
  31. package/src/components/toast/toastProvider.tsx +18 -22
  32. package/src/components/tree/__workshop__/basic.perf.ts +1 -14
  33. package/src/components/tree/__workshop__/basic.tsx +1 -1
  34. package/src/components/tree/__workshop__/index.ts +12 -8
  35. package/src/components/tree/style.ts +78 -76
  36. package/src/components/tree/treeItem.tsx +7 -12
  37. package/src/hooks/useElementRect/__workshop__/index.ts +11 -3
  38. package/src/hooks/useMediaIndex/__workshop__/index.ts +11 -3
  39. package/src/primitives/_selectable/selectable.tsx +4 -7
  40. package/src/primitives/_selectable/style.ts +85 -82
  41. package/src/primitives/avatar/__workshop__/index.ts +16 -12
  42. package/src/primitives/avatar/avatar.tsx +9 -12
  43. package/src/primitives/avatar/avatarCounter.tsx +22 -24
  44. package/src/primitives/avatar/avatarStack.tsx +16 -14
  45. package/src/primitives/avatar/styles.ts +1 -1
  46. package/src/primitives/badge/__workshop__/index.ts +16 -12
  47. package/src/primitives/badge/__workshop__/tones.tsx +1 -1
  48. package/src/primitives/badge/badge.tsx +6 -5
  49. package/src/primitives/box/__workshop__/index.ts +16 -4
  50. package/src/primitives/box/box.tsx +21 -49
  51. package/src/primitives/button/__workshop__/index.ts +51 -47
  52. package/src/primitives/button/__workshop__/sanityUploadButton.tsx +19 -20
  53. package/src/primitives/button/__workshop__/styled1.tsx +6 -6
  54. package/src/primitives/button/button.tsx +20 -26
  55. package/src/primitives/button/styles.ts +30 -29
  56. package/src/primitives/card/__workshop__/index.ts +15 -11
  57. package/src/primitives/card/card.tsx +9 -25
  58. package/src/primitives/card/styles.ts +119 -114
  59. package/src/primitives/checkbox/__workshop__/index.ts +10 -6
  60. package/src/primitives/checkbox/checkbox.tsx +4 -4
  61. package/src/primitives/checkbox/styles.ts +71 -69
  62. package/src/primitives/code/__workshop__/index.ts +16 -12
  63. package/src/primitives/code/code.tsx +3 -5
  64. package/src/primitives/code/styles.ts +20 -18
  65. package/src/primitives/container/__workshop__/index.ts +5 -3
  66. package/src/primitives/container/container.tsx +5 -4
  67. package/src/primitives/flex/__workshop__/index.ts +8 -4
  68. package/src/primitives/flex/flex.tsx +7 -23
  69. package/src/primitives/grid/__workshop__/index.ts +7 -3
  70. package/src/primitives/grid/grid.tsx +4 -27
  71. package/src/primitives/heading/__workshop__/index.ts +16 -12
  72. package/src/primitives/heading/heading.tsx +10 -17
  73. package/src/primitives/heading/styles.ts +45 -36
  74. package/src/primitives/inline/__workshop__/index.ts +5 -3
  75. package/src/primitives/inline/inline.tsx +3 -5
  76. package/src/primitives/kbd/__workshop__/index.ts +5 -3
  77. package/src/primitives/kbd/kbd.tsx +12 -13
  78. package/src/primitives/label/__workshop__/index.ts +16 -12
  79. package/src/primitives/label/label.tsx +13 -18
  80. package/src/primitives/label/styles.ts +24 -18
  81. package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -1
  82. package/src/primitives/popover/__workshop__/TestStory.tsx +0 -1
  83. package/src/primitives/popover/__workshop__/index.ts +36 -32
  84. package/src/primitives/popover/constants.ts +0 -3
  85. package/src/primitives/popover/floating-ui/size.ts +40 -25
  86. package/src/primitives/popover/popover.tsx +220 -196
  87. package/src/primitives/popover/popoverArrow.tsx +42 -48
  88. package/src/primitives/popover/popoverCard.tsx +12 -22
  89. package/src/primitives/radio/__workshop__/index.ts +8 -4
  90. package/src/primitives/radio/radio.tsx +3 -3
  91. package/src/primitives/radio/styles.ts +73 -73
  92. package/src/primitives/select/__workshop__/index.ts +8 -4
  93. package/src/primitives/select/select.tsx +9 -11
  94. package/src/primitives/select/styles.ts +77 -77
  95. package/src/primitives/spinner/__workshop__/index.ts +11 -7
  96. package/src/primitives/spinner/spinner.tsx +2 -5
  97. package/src/primitives/stack/__workshop__/index.ts +11 -7
  98. package/src/primitives/stack/stack.tsx +3 -5
  99. package/src/primitives/switch/__workshop__/index.ts +8 -4
  100. package/src/primitives/switch/styles.ts +119 -112
  101. package/src/primitives/switch/switch.tsx +6 -6
  102. package/src/primitives/text/__workshop__/index.ts +21 -17
  103. package/src/primitives/text/styles.ts +51 -45
  104. package/src/primitives/text/text.tsx +11 -16
  105. package/src/primitives/textArea/__workshop__/index.ts +11 -7
  106. package/src/primitives/textArea/textArea.tsx +15 -22
  107. package/src/primitives/textInput/__workshop__/index.ts +46 -42
  108. package/src/primitives/textInput/__workshop__/plain.tsx +2 -1
  109. package/src/primitives/textInput/textInput.tsx +49 -69
  110. package/src/primitives/tooltip/__workshop__/index.ts +11 -7
  111. package/src/primitives/tooltip/tooltip.tsx +3 -6
  112. package/src/primitives/tooltip/tooltipArrow.tsx +69 -59
  113. package/src/styles/border/borderStyle.ts +10 -18
  114. package/src/styles/box/boxStyle.ts +14 -18
  115. package/src/styles/flex/flexItemStyle.ts +7 -1
  116. package/src/styles/flex/flexStyle.ts +14 -9
  117. package/src/styles/grid/gridItemStyle.ts +18 -30
  118. package/src/styles/grid/gridStyle.ts +25 -33
  119. package/src/styles/helpers.ts +2 -2
  120. package/src/styles/index.ts +0 -1
  121. package/src/styles/input/textInputStyle.ts +127 -123
  122. package/src/styles/margin/marginStyle.ts +11 -10
  123. package/src/styles/margin/marginsStyle.test.ts +12 -10
  124. package/src/styles/padding/paddingStyle.test.ts +12 -10
  125. package/src/styles/padding/paddingStyle.ts +9 -10
  126. package/src/theme/__workshop__/index.ts +26 -22
  127. package/src/theme/{ThemeContext.ts → themeContext.ts} +0 -0
  128. package/src/utils/boundaryElement/__workshop__/index.ts +11 -7
  129. package/src/utils/elementQuery/__workshop__/index.ts +11 -7
  130. package/src/utils/layer/__workshop__/index.ts +21 -17
  131. package/src/utils/layer/layer.tsx +4 -6
  132. package/src/utils/portal/__workshop__/index.ts +11 -7
  133. package/src/utils/srOnly/srOnly.tsx +8 -10
  134. package/src/utils/virtualList/__workshop__/index.ts +26 -22
  135. package/src/utils/virtualList/virtualList.tsx +10 -14
  136. package/dist/sanity-ui.esm.js.map +0 -1
  137. package/dist/sanity-ui.js.map +0 -1
  138. package/src/__workshop__/color/overview.tsx +0 -101
  139. package/src/__workshop__/index.ts +0 -10
  140. package/src/icons/__workshop__/.eslintrc +0 -5
  141. package/src/icons/__workshop__/index.tsx +0 -6
  142. package/src/icons/__workshop__/overview.tsx +0 -76
  143. package/src/styles/compose.ts +0 -35
  144. 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 {ThemeColorSchemeKey, ThemeFontWeightKey} from '../../theme'
3
3
  import {CardTone} from '../../types'
4
4
  import {focusRingBorderStyle, focusRingStyle} from '../focusRing'
@@ -25,86 +25,90 @@ export interface TextInputRepresentationStyleProps {
25
25
  $tone: CardTone
26
26
  }
27
27
 
28
- const ROOT_STYLE: CSSObject = {
29
- '&:not([hidden])': {
30
- display: 'flex',
31
- },
28
+ const ROOT_STYLE = css`
29
+ &:not([hidden]) {
30
+ display: flex;
31
+ }
32
32
 
33
- alignItems: 'center',
34
- }
33
+ align-items: center;
34
+ `
35
35
 
36
- export function textInputRootStyle(): CSSObject {
36
+ export function textInputRootStyle(): FlattenSimpleInterpolation {
37
37
  return ROOT_STYLE
38
38
  }
39
39
 
40
- export function textInputBaseStyle(props: TextInputInputStyleProps & ThemeProps): CSSObject {
40
+ export function textInputBaseStyle(
41
+ props: TextInputInputStyleProps & ThemeProps
42
+ ): FlattenSimpleInterpolation {
41
43
  const {theme, $scheme, $tone, $weight} = props
42
44
  const font = theme.sanity.fonts.text
43
45
  const color = theme.sanity.color.input
44
46
 
45
- return {
46
- appearance: 'none',
47
- background: 'none',
48
- border: 0,
49
- borderRadius: 0,
50
- outline: 'none',
51
- width: '100%',
52
- boxSizing: 'border-box',
53
- fontFamily: font.family,
54
- fontWeight: ($weight && font.weights[$weight]) || font.weights.regular,
55
- margin: 0,
56
- position: 'relative',
57
- zIndex: 1,
58
- display: 'block',
47
+ return css`
48
+ appearance: none;
49
+ background: none;
50
+ border: 0;
51
+ border-radius: 0;
52
+ outline: none;
53
+ width: 100%;
54
+ box-sizing: border-box;
55
+ font-family: ${font.family};
56
+ font-weight: ${($weight && font.weights[$weight]) || font.weights.regular};
57
+ margin: 0;
58
+ position: relative;
59
+ z-index: 1;
60
+ display: block;
59
61
 
60
62
  /* NOTE: This is a hack to disable Chrome’s autofill styles */
61
- '&:-webkit-autofill, &:-webkit-autofill:hover, &:-webkit-autofill:focus, &:-webkit-autofill:active':
62
- {
63
- WebkitTextFillColor: 'var(--input-fg-color) !important',
64
- transition: 'background-color 5000s',
65
- transitionDelay: '86400s' /* 24h */,
66
- },
63
+ &:-webkit-autofill,
64
+ &:-webkit-autofill:hover,
65
+ &:-webkit-autofill:focus,
66
+ &:-webkit-autofill:active {
67
+ -webkit-text-fill-color: var(--input-fg-color) !important;
68
+ transition: background-color 5000s;
69
+ transition-delay: 86400s /* 24h */;
70
+ }
67
71
 
68
72
  /* &:is(textarea) */
69
- '&[data-as="textarea"]': {
70
- resize: 'none',
71
- },
73
+ &[data-as='textarea'] {
74
+ resize: none;
75
+ }
72
76
 
73
- color: 'var(--input-fg-color)',
77
+ color: var(--input-fg-color);
74
78
 
75
- '&::placeholder': {
76
- color: 'var(--input-placeholder-color)',
77
- },
79
+ &::placeholder {
80
+ color: var(--input-placeholder-color);
81
+ }
78
82
 
79
- [`&[data-scheme="${$scheme}"][data-tone="${$tone}"]`]: {
80
- '--input-fg-color': color.default.enabled.fg,
81
- '--input-placeholder-color': color.default.enabled.placeholder,
83
+ &[data-scheme='${$scheme}'][data-tone='${$tone}'] {
84
+ --input-fg-color: ${color.default.enabled.fg};
85
+ --input-placeholder-color: ${color.default.enabled.placeholder};
82
86
 
83
87
  /* enabled */
84
- '&:not(:invalid):not(:disabled):not(:read-only)': {
85
- '--input-fg-color': color.default.enabled.fg,
86
- '--input-placeholder-color': color.default.enabled.placeholder,
87
- },
88
+ &:not(:invalid):not(:disabled):not(:read-only) {
89
+ --input-fg-color: ${color.default.enabled.fg};
90
+ --input-placeholder-color: ${color.default.enabled.placeholder};
91
+ }
88
92
 
89
93
  /* disabled */
90
- '&:not(:invalid):disabled': {
91
- '--input-fg-color': color.default.disabled.fg,
92
- '--input-placeholder-color': color.default.disabled.placeholder,
93
- },
94
+ &:not(:invalid):disabled {
95
+ --input-fg-color: ${color.default.disabled.fg};
96
+ --input-placeholder-color: ${color.default.disabled.placeholder};
97
+ }
94
98
 
95
99
  /* invalid */
96
- '&:invalid': {
97
- '--input-fg-color': color.invalid.enabled.fg,
98
- '--input-placeholder-color': color.invalid.enabled.placeholder,
99
- },
100
+ &:invalid {
101
+ --input-fg-color: ${color.invalid.enabled.fg};
102
+ --input-placeholder-color: ${color.invalid.enabled.placeholder};
103
+ }
100
104
 
101
105
  /* readOnly */
102
- '&:read-only': {
103
- '--input-fg-color': color.default.readOnly.fg,
104
- '--input-placeholder-color': color.default.readOnly.placeholder,
105
- },
106
- },
107
- }
106
+ &:read-only {
107
+ --input-fg-color: ${color.default.readOnly.fg};
108
+ --input-placeholder-color: ${color.default.readOnly.placeholder};
109
+ }
110
+ }
111
+ `
108
112
  }
109
113
 
110
114
  export function textInputFontSizeStyle(props: TextInputInputStyleProps & ThemeProps): CSSObject[] {
@@ -123,103 +127,103 @@ export function textInputFontSizeStyle(props: TextInputInputStyleProps & ThemePr
123
127
 
124
128
  export function textInputRepresentationStyle(
125
129
  props: TextInputRepresentationStyleProps & ThemeProps
126
- ): CSSObject {
130
+ ): FlattenSimpleInterpolation {
127
131
  const {$hasPrefix, $hasSuffix, $scheme, $tone, theme} = props
128
132
  const {focusRing, input} = theme.sanity
129
133
  const color = theme.sanity.color.input
130
134
 
131
- return {
132
- '--input-box-shadow': 'none',
135
+ return css`
136
+ --input-box-shadow: none;
133
137
 
134
- position: 'absolute',
135
- top: 0,
136
- left: 0,
137
- right: 0,
138
- bottom: 0,
139
- display: 'block',
140
- pointerEvents: 'none',
141
- zIndex: 0,
138
+ position: absolute;
139
+ top: 0;
140
+ left: 0;
141
+ right: 0;
142
+ bottom: 0;
143
+ display: block;
144
+ pointer-events: none;
145
+ z-index: 0;
142
146
 
143
- backgroundColor: 'var(--card-bg-color)',
144
- boxShadow: 'var(--input-box-shadow)',
147
+ background-color: var(--card-bg-color);
148
+ box-shadow: var(--input-box-shadow);
145
149
 
146
- borderTopLeftRadius: $hasPrefix ? 0 : undefined,
147
- borderBottomLeftRadius: $hasPrefix ? 0 : undefined,
148
- borderTopRightRadius: $hasSuffix ? 0 : undefined,
149
- borderBottomRightRadius: $hasSuffix ? 0 : undefined,
150
+ border-top-left-radius: ${$hasPrefix ? 0 : undefined};
151
+ border-bottom-left-radius: ${$hasPrefix ? 0 : undefined};
152
+ border-top-right-radius: ${$hasSuffix ? 0 : undefined};
153
+ border-bottom-right-radius: ${$hasSuffix ? 0 : undefined};
150
154
 
151
- [`&[data-scheme="${$scheme}"][data-tone="${$tone}"]`]: {
152
- '--card-bg-color': color.default.enabled.bg,
153
- '--card-fg-color': color.default.enabled.fg,
155
+ &[data-scheme='${$scheme}'][data-tone='${$tone}'] {
156
+ --card-bg-color: ${color.default.enabled.bg};
157
+ --card-fg-color: ${color.default.enabled.fg};
154
158
 
155
159
  /* enabled */
156
- '*:not(:disabled) + &[data-border]': {
157
- '--input-box-shadow': focusRingBorderStyle({
160
+ *:not(:disabled) + &[data-border] {
161
+ --input-box-shadow: ${focusRingBorderStyle({
158
162
  color: color.default.enabled.border,
159
163
  width: input.border.width,
160
- }),
161
- },
164
+ })};
165
+ }
162
166
 
163
167
  /* invalid */
164
- '*:not(:disabled):invalid + &': {
165
- '--card-bg-color': color.invalid.enabled.bg,
166
- '--card-fg-color': color.invalid.enabled.fg,
168
+ *:not(:disabled):invalid + & {
169
+ --card-bg-color: ${color.invalid.enabled.bg};
170
+ --card-fg-color: ${color.invalid.enabled.fg};
167
171
 
168
- '&[data-border]': {
169
- '--input-box-shadow': focusRingBorderStyle({
172
+ &[data-border] {
173
+ --input-box-shadow: ${focusRingBorderStyle({
170
174
  color: color.invalid.enabled.border,
171
175
  width: input.border.width,
172
- }),
173
- },
174
- },
176
+ })};
177
+ }
178
+ }
175
179
 
176
180
  /* focused */
177
- '*:not(:disabled):focus + &': {
178
- '&[data-border]': {
179
- '--input-box-shadow': focusRingStyle({
181
+ *:not(:disabled):focus + & {
182
+ &[data-border] {
183
+ --input-box-shadow: ${focusRingStyle({
180
184
  border: {color: color.default.enabled.border, width: input.border.width},
181
185
  focusRing,
182
- }),
183
- },
186
+ })};
187
+ }
184
188
 
185
- '&:not([data-border])': {
186
- '--input-box-shadow': focusRingStyle({focusRing}),
187
- },
188
- },
189
+ &:not([data-border]) {
190
+ --input-box-shadow: ${focusRingStyle({focusRing})};
191
+ }
192
+ }
189
193
 
190
194
  /* disabled */
191
- '*:disabled + &': {
192
- '--card-bg-color': `${color.default.disabled.bg} !important`,
193
- '--card-fg-color': `${color.default.disabled.fg} !important`,
195
+ *:disabled + & {
196
+ --card-bg-color: ${color.default.disabled.bg} !important;
197
+ --card-fg-color: ${color.default.disabled.fg} !important;
194
198
 
195
- '&[data-border]': {
196
- '--input-box-shadow': focusRingBorderStyle({
199
+ &[data-border] {
200
+ --input-box-shadow: ${focusRingBorderStyle({
197
201
  color: color.default.disabled.border,
198
202
  width: input.border.width,
199
- }),
200
- },
201
- },
203
+ })};
204
+ }
205
+ }
202
206
 
203
207
  /* readOnly */
204
- '*:read-only + &': {
205
- '--card-bg-color': `${color.default.readOnly.bg} !important`,
206
- '--card-fg-color': `${color.default.readOnly.fg} !important`,
207
- },
208
+ *:read-only + & {
209
+ --card-bg-color: ${color.default.readOnly.bg} !important;
210
+ --card-fg-color: ${color.default.readOnly.fg} !important;
211
+ }
208
212
 
209
213
  /* hovered */
210
- '@media (hover: hover)': {
211
- '*:not(:disabled):not(:read-only):not(:invalid):hover + &': {
212
- '--card-bg-color': color.default.hovered.bg,
213
- '--card-fg-color': color.default.hovered.fg,
214
- },
215
-
216
- '*:not(:disabled):not(:read-only):not(:invalid):not(:focus):hover + &[data-border]': {
217
- '--input-box-shadow': focusRingBorderStyle({
214
+ @media (hover: hover) {
215
+ *:not(:disabled):not(:read-only):not(:invalid):hover + & {
216
+ --card-bg-color: ${color.default.hovered.bg};
217
+ --card-fg-color: ${color.default.hovered.fg};
218
+ }
219
+
220
+ *:not(:disabled):not(:read-only):not(:invalid):not(:focus):hover + &[data-border] {
221
+ --input-box-shadow: ${focusRingBorderStyle({
218
222
  color: color.default.hovered.border,
219
223
  width: input.border.width,
220
- }),
221
- },
222
- },
223
- },
224
- }
224
+ })};
225
+ }
226
+ }
227
+ }
228
+ `
225
229
  }
@@ -3,17 +3,18 @@ import {_getResponsiveSpace} from '../helpers'
3
3
  import {ThemeProps} from '../types'
4
4
  import {ResponsiveMarginStyleProps} from './types'
5
5
 
6
- // TODO: refactor this to separate style functions
7
- export function responsiveMarginStyle(props: ResponsiveMarginStyleProps & ThemeProps): CSSObject[] {
6
+ export function responsiveMarginStyle(
7
+ props: ResponsiveMarginStyleProps & ThemeProps
8
+ ): CSSObject[][] {
8
9
  const {theme} = props
9
10
 
10
11
  return [
11
- ..._getResponsiveSpace(theme, ['margin'], props.$margin),
12
- ..._getResponsiveSpace(theme, ['marginLeft', 'marginRight'], props.$marginX),
13
- ..._getResponsiveSpace(theme, ['marginTop', 'marginBottom'], props.$marginY),
14
- ..._getResponsiveSpace(theme, ['marginTop'], props.$marginTop),
15
- ..._getResponsiveSpace(theme, ['marginRight'], props.$marginRight),
16
- ..._getResponsiveSpace(theme, ['marginBottom'], props.$marginBottom),
17
- ..._getResponsiveSpace(theme, ['marginLeft'], props.$marginLeft),
18
- ]
12
+ _getResponsiveSpace(theme, ['margin'], props.$margin),
13
+ _getResponsiveSpace(theme, ['marginLeft', 'marginRight'], props.$marginX),
14
+ _getResponsiveSpace(theme, ['marginTop', 'marginBottom'], props.$marginY),
15
+ _getResponsiveSpace(theme, ['marginTop'], props.$marginTop),
16
+ _getResponsiveSpace(theme, ['marginRight'], props.$marginRight),
17
+ _getResponsiveSpace(theme, ['marginBottom'], props.$marginBottom),
18
+ _getResponsiveSpace(theme, ['marginLeft'], props.$marginLeft),
19
+ ].filter(Boolean) as CSSObject[][]
19
20
  }
@@ -10,22 +10,24 @@ describe('styles/margin', () => {
10
10
  it('should 1', () => {
11
11
  const styles = responsiveMarginStyle({$margin: [0], theme})
12
12
 
13
- expect(styles).toEqual([{margin: 0}])
13
+ expect(styles).toEqual([[{margin: 0}]])
14
14
  })
15
15
 
16
16
  it('should 2', () => {
17
17
  const styles = responsiveMarginStyle({$margin: [0, 1, 2], theme})
18
18
 
19
19
  expect(styles).toEqual([
20
- {
21
- margin: 0,
22
- },
23
- {
24
- '@media screen and (min-width: 360px)': {margin: '0.25rem'},
25
- },
26
- {
27
- '@media screen and (min-width: 600px)': {margin: '0.5rem'},
28
- },
20
+ [
21
+ {
22
+ margin: 0,
23
+ },
24
+ {
25
+ '@media screen and (min-width: 360px)': {margin: '0.25rem'},
26
+ },
27
+ {
28
+ '@media screen and (min-width: 600px)': {margin: '0.5rem'},
29
+ },
30
+ ],
29
31
  ])
30
32
  })
31
33
  })
@@ -10,22 +10,24 @@ describe('styles/padding', () => {
10
10
  it('should 1', () => {
11
11
  const styles = responsivePaddingStyle({$padding: [0], theme})
12
12
 
13
- expect(styles).toEqual([{padding: 0}])
13
+ expect(styles).toEqual([[{padding: 0}]])
14
14
  })
15
15
 
16
16
  it('should 2', () => {
17
17
  const styles = responsivePaddingStyle({$padding: [0, 1, 2], theme})
18
18
 
19
19
  expect(styles).toEqual([
20
- {
21
- padding: 0,
22
- },
23
- {
24
- '@media screen and (min-width: 360px)': {padding: '0.25rem'},
25
- },
26
- {
27
- '@media screen and (min-width: 600px)': {padding: '0.5rem'},
28
- },
20
+ [
21
+ {
22
+ padding: 0,
23
+ },
24
+ {
25
+ '@media screen and (min-width: 360px)': {padding: '0.25rem'},
26
+ },
27
+ {
28
+ '@media screen and (min-width: 600px)': {padding: '0.5rem'},
29
+ },
30
+ ],
29
31
  ])
30
32
  })
31
33
  })
@@ -3,19 +3,18 @@ import {_getResponsiveSpace} from '../helpers'
3
3
  import {ThemeProps} from '../types'
4
4
  import {ResponsivePaddingStyleProps} from './types'
5
5
 
6
- // TODO: refactor this to separate style functions
7
6
  export function responsivePaddingStyle(
8
7
  props: ResponsivePaddingStyleProps & ThemeProps
9
- ): CSSObject[] {
8
+ ): CSSObject[][] {
10
9
  const {theme} = props
11
10
 
12
11
  return [
13
- ..._getResponsiveSpace(theme, ['padding'], props.$padding),
14
- ..._getResponsiveSpace(theme, ['paddingLeft', 'paddingRight'], props.$paddingX),
15
- ..._getResponsiveSpace(theme, ['paddingTop', 'paddingBottom'], props.$paddingY),
16
- ..._getResponsiveSpace(theme, ['paddingTop'], props.$paddingTop),
17
- ..._getResponsiveSpace(theme, ['paddingRight'], props.$paddingRight),
18
- ..._getResponsiveSpace(theme, ['paddingBottom'], props.$paddingBottom),
19
- ..._getResponsiveSpace(theme, ['paddingLeft'], props.$paddingLeft),
20
- ]
12
+ _getResponsiveSpace(theme, ['padding'], props.$padding),
13
+ _getResponsiveSpace(theme, ['paddingLeft', 'paddingRight'], props.$paddingX),
14
+ _getResponsiveSpace(theme, ['paddingTop', 'paddingBottom'], props.$paddingY),
15
+ _getResponsiveSpace(theme, ['paddingTop'], props.$paddingTop),
16
+ _getResponsiveSpace(theme, ['paddingRight'], props.$paddingRight),
17
+ _getResponsiveSpace(theme, ['paddingBottom'], props.$paddingBottom),
18
+ _getResponsiveSpace(theme, ['paddingLeft'], props.$paddingLeft),
19
+ ].filter(Boolean) as CSSObject[][]
21
20
  }
@@ -1,25 +1,29 @@
1
1
  import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
- export default defineScope('theme', 'Theme', [
5
- {
6
- name: 'canvas',
7
- title: 'Canvas',
8
- component: lazy(() => import('./canvas')),
9
- },
10
- {
11
- name: 'nested-provider',
12
- title: 'Nested provider',
13
- component: lazy(() => import('./nestedProvider')),
14
- },
15
- {
16
- name: 'layer',
17
- title: 'Layer',
18
- component: lazy(() => import('./layer')),
19
- },
20
- {
21
- name: 'color',
22
- title: 'Color',
23
- component: lazy(() => import('./color')),
24
- },
25
- ])
4
+ export default defineScope({
5
+ name: 'theme',
6
+ title: 'Theme',
7
+ stories: [
8
+ {
9
+ name: 'canvas',
10
+ title: 'Canvas',
11
+ component: lazy(() => import('./canvas')),
12
+ },
13
+ {
14
+ name: 'nested-provider',
15
+ title: 'Nested provider',
16
+ component: lazy(() => import('./nestedProvider')),
17
+ },
18
+ {
19
+ name: 'layer',
20
+ title: 'Layer',
21
+ component: lazy(() => import('./layer')),
22
+ },
23
+ {
24
+ name: 'color',
25
+ title: 'Color',
26
+ component: lazy(() => import('./color')),
27
+ },
28
+ ],
29
+ })
File without changes
@@ -1,10 +1,14 @@
1
1
  import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
- export default defineScope('utils/boundaryElement', 'BoundaryElement', [
5
- {
6
- name: 'plain',
7
- title: 'Plain',
8
- component: lazy(() => import('./plain')),
9
- },
10
- ])
4
+ export default defineScope({
5
+ name: 'utils/boundaryElement',
6
+ title: 'BoundaryElement',
7
+ stories: [
8
+ {
9
+ name: 'plain',
10
+ title: 'Plain',
11
+ component: lazy(() => import('./plain')),
12
+ },
13
+ ],
14
+ })
@@ -1,10 +1,14 @@
1
1
  import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
- export default defineScope('utils/elementQuery', 'ElementQuery', [
5
- {
6
- name: 'custom-media',
7
- title: 'Custom media',
8
- component: lazy(() => import('./customMedia')),
9
- },
10
- ])
4
+ export default defineScope({
5
+ name: 'utils/elementQuery',
6
+ title: 'ElementQuery',
7
+ stories: [
8
+ {
9
+ name: 'custom-media',
10
+ title: 'Custom media',
11
+ component: lazy(() => import('./customMedia')),
12
+ },
13
+ ],
14
+ })
@@ -1,20 +1,24 @@
1
1
  import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
- export default defineScope('utils/layer', 'Layer', [
5
- {
6
- name: 'plain',
7
- title: 'Plain',
8
- component: lazy(() => import('./plain')),
9
- },
10
- {
11
- name: 'multiple-roots',
12
- title: 'Multiple roots',
13
- component: lazy(() => import('./multipleRoots')),
14
- },
15
- {
16
- name: 'responsive-z-offset',
17
- title: 'Responsive z-offset',
18
- component: lazy(() => import('./responsiveZOffset')),
19
- },
20
- ])
4
+ export default defineScope({
5
+ name: 'utils/layer',
6
+ title: 'Layer',
7
+ stories: [
8
+ {
9
+ name: 'plain',
10
+ title: 'Plain',
11
+ component: lazy(() => import('./plain')),
12
+ },
13
+ {
14
+ name: 'multiple-roots',
15
+ title: 'Multiple roots',
16
+ component: lazy(() => import('./multipleRoots')),
17
+ },
18
+ {
19
+ name: 'responsive-z-offset',
20
+ title: 'Responsive z-offset',
21
+ component: lazy(() => import('./responsiveZOffset')),
22
+ },
23
+ ],
24
+ })
@@ -1,4 +1,4 @@
1
- import {forwardRef, memo} from 'react'
1
+ import {forwardRef} from 'react'
2
2
  import styled from 'styled-components'
3
3
  import {EMPTY_RECORD} from '../../constants'
4
4
  import {LayerProvider} from './layerProvider'
@@ -16,11 +16,9 @@ interface LayerChildrenProps {
16
16
  as?: React.ElementType | keyof JSX.IntrinsicElements
17
17
  }
18
18
 
19
- const Root = memo(
20
- styled.div({
21
- position: 'relative',
22
- })
23
- )
19
+ const Root = styled.div`
20
+ position: relative;
21
+ `
24
22
 
25
23
  const LayerChildren = forwardRef(function LayerChildren(
26
24
  props: LayerChildrenProps & Omit<React.HTMLProps<HTMLDivElement>, 'as'>,
@@ -1,10 +1,14 @@
1
1
  import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
- export default defineScope('utils/portal', 'Portal', [
5
- {
6
- name: 'named',
7
- title: 'Named portals',
8
- component: lazy(() => import('./named')),
9
- },
10
- ])
4
+ export default defineScope({
5
+ name: 'utils/portal',
6
+ title: 'Portal',
7
+ stories: [
8
+ {
9
+ name: 'named',
10
+ title: 'Named portals',
11
+ component: lazy(() => import('./named')),
12
+ },
13
+ ],
14
+ })