@sanity/ui 2.0.0-alpha.34 → 2.0.0-alpha.36
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.cjs.mjs +4 -3
- package/dist/index.d.ts +29 -22
- package/dist/index.esm.js +397 -518
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +413 -534
- package/dist/index.js.map +1 -1
- package/dist/theme.cjs.mjs +10 -4
- package/dist/theme.d.ts +489 -201
- package/dist/theme.esm.js +2934 -2748
- package/dist/theme.esm.js.map +1 -1
- package/dist/theme.js +2943 -2751
- package/dist/theme.js.map +1 -1
- package/package.json +3 -3
- package/src/core/_compat.ts +7 -7
- package/src/core/components/dialog/dialog.tsx +5 -5
- package/src/core/components/dialog/styles.ts +4 -5
- package/src/core/components/hotkeys/hotkeys.tsx +4 -2
- package/src/core/components/menu/__workshop__/avatarMenu.tsx +50 -0
- package/src/core/components/menu/__workshop__/index.ts +5 -0
- package/src/core/components/menu/menuItem.tsx +7 -1
- package/src/core/components/skeleton/textSkeleton.tsx +12 -14
- package/src/core/components/tree/style.ts +14 -17
- package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +3 -3
- package/src/core/hooks/useMediaIndex/useMediaIndex.ts +2 -3
- package/src/core/primitives/_selectable/style.ts +18 -18
- package/src/core/primitives/avatar/avatar.tsx +3 -3
- package/src/core/primitives/avatar/avatarCounter.tsx +4 -4
- package/src/core/primitives/avatar/avatarStack.tsx +2 -2
- package/src/core/primitives/avatar/styles.ts +7 -8
- package/src/core/primitives/avatar/types.ts +2 -2
- package/src/core/primitives/badge/__workshop__/props.tsx +1 -1
- package/src/core/primitives/badge/__workshop__/tones.tsx +1 -1
- package/src/core/primitives/badge/badge.tsx +1 -1
- package/src/core/primitives/badge/styles.ts +5 -6
- package/src/core/primitives/button/button.tsx +3 -4
- package/src/core/primitives/button/styles.ts +22 -23
- package/src/core/primitives/card/__workshop__/selected.tsx +15 -15
- package/src/core/primitives/card/card.tsx +1 -1
- package/src/core/primitives/card/styles.ts +22 -22
- package/src/core/primitives/checkbox/styles.ts +21 -22
- package/src/core/primitives/code/styles.ts +4 -1
- package/src/core/primitives/container/styles.ts +2 -3
- package/src/core/primitives/heading/styles.ts +4 -2
- package/src/core/primitives/inline/styles.ts +6 -6
- package/src/core/primitives/kbd/kbd.tsx +7 -11
- package/src/core/primitives/label/styles.ts +4 -3
- package/src/core/primitives/popover/helpers.ts +3 -4
- package/src/core/primitives/popover/popover.tsx +8 -4
- package/src/core/primitives/popover/types.ts +1 -1
- package/src/core/primitives/radio/styles.ts +17 -19
- package/src/core/primitives/select/styles.ts +27 -32
- package/src/core/primitives/stack/styles.ts +2 -3
- package/src/core/primitives/switch/__workshop__/props.tsx +11 -31
- package/src/core/primitives/switch/styles.ts +18 -21
- package/src/core/primitives/text/__workshop__/colored.tsx +10 -10
- package/src/core/primitives/text/styles.ts +9 -4
- package/src/core/primitives/tooltip/tooltip.tsx +3 -3
- package/src/core/styles/border/borderStyle.ts +6 -11
- package/src/core/styles/box/boxStyle.ts +5 -9
- package/src/core/styles/card/_cardColorStyle.ts +99 -0
- package/src/core/styles/card/index.ts +1 -0
- package/src/core/styles/flex/flexItemStyle.ts +2 -3
- package/src/core/styles/flex/flexStyle.ts +6 -11
- package/src/core/styles/font/responsiveFont.ts +4 -4
- package/src/core/styles/font/textAlignStyle.ts +3 -3
- package/src/core/styles/grid/gridItemStyle.ts +7 -13
- package/src/core/styles/grid/gridStyle.ts +9 -17
- package/src/core/styles/helpers.ts +5 -3
- package/src/core/styles/input/responsiveInputPaddingStyle.ts +6 -6
- package/src/core/styles/input/textInputStyle.ts +36 -40
- package/src/core/styles/margin/marginsStyle.test.ts +2 -3
- package/src/core/styles/padding/paddingStyle.test.ts +2 -3
- package/src/core/styles/radius/radiusStyle.ts +2 -3
- package/src/core/styles/shadow/shadowStyle.ts +4 -5
- package/src/core/theme/__workshop__/build/Root.tsx +24 -20
- package/src/core/theme/__workshop__/build/story.tsx +22 -26
- package/src/core/theme/__workshop__/canvas.tsx +21 -40
- package/src/core/theme/theme.test.tsx +2 -35
- package/src/core/theme/themeColorProvider.tsx +2 -2
- package/src/core/theme/themeContext.ts +2 -2
- package/src/core/theme/themeProvider.tsx +25 -25
- package/src/core/theme/types.ts +3 -2
- package/src/core/theme/useRootTheme.ts +1 -9
- package/src/core/theme/useTheme.ts +8 -1
- package/src/core/types/card.ts +2 -2
- package/src/core/utils/arrow/arrow.tsx +3 -3
- package/src/core/utils/elementQuery/elementQuery.tsx +3 -3
- package/src/core/utils/virtualList/virtualList.tsx +2 -2
- package/src/theme/build/_deprecated/color/muted/createMuted.ts +2 -2
- package/src/theme/build/buildColorTheme.test.ts +14 -15
- package/src/theme/build/buildColorTheme.ts +239 -292
- package/src/theme/build/buildTheme.test.ts +9 -7
- package/src/theme/build/buildTheme.ts +12 -9
- package/src/theme/build/colorToken.ts +3 -1
- package/src/theme/build/lib/color-fns/contrastRatio.ts +1 -0
- package/src/theme/build/lib/isRecord.ts +3 -0
- package/src/theme/build/merge.ts +18 -13
- package/src/theme/build/renderColorTheme.ts +205 -213
- package/src/theme/build/renderColorValue.ts +15 -8
- package/src/theme/build/resolveColorTokens.ts +177 -198
- package/src/theme/build/theme.test.ts +27 -0
- package/src/theme/config/helpers.ts +16 -8
- package/src/theme/config/system.ts +46 -17
- package/src/theme/config/tokens/color/types.ts +55 -32
- package/src/theme/config/tokens/types.ts +11 -4
- package/src/theme/config/types.ts +5 -11
- package/src/theme/{build/defaults → defaults}/colorPalette.ts +1 -1
- package/src/theme/{build/defaults → defaults}/colorTokens.ts +189 -136
- package/src/theme/{build/defaults → defaults}/config.ts +14 -12
- package/src/theme/{build/defaults → defaults}/fonts.ts +6 -6
- package/src/theme/getScopedTheme.ts +81 -0
- package/src/theme/index.ts +9 -1
- package/src/theme/system/avatar.ts +1 -1
- package/src/theme/system/color/_constants.ts +11 -11
- package/src/theme/system/color/_system.ts +10 -71
- package/src/theme/system/color/avatar.ts +22 -10
- package/src/theme/system/color/badge.ts +18 -7
- package/src/theme/system/color/button.ts +17 -23
- package/src/theme/system/color/color.ts +34 -0
- package/src/theme/system/color/index.ts +3 -10
- package/src/theme/system/color/input.ts +13 -11
- package/src/theme/system/color/kbd.ts +3 -3
- package/src/theme/system/color/selectable.ts +13 -19
- package/src/theme/system/color/shadow.ts +7 -0
- package/src/theme/system/color/state.ts +37 -0
- package/src/theme/system/css.ts +9 -0
- package/src/theme/system/focusRing.ts +7 -0
- package/src/theme/system/index.ts +5 -1
- package/src/theme/system/input.ts +1 -1
- package/src/theme/system/layer.ts +1 -2
- package/src/theme/system/shadow.ts +1 -0
- package/src/theme/system/styles.ts +19 -0
- package/src/theme/system/theme.ts +128 -0
- package/src/theme/system/{color → v0/color}/_generic.ts +2 -1
- package/src/theme/system/v0/color/_system.ts +13 -0
- package/src/theme/system/{color → v0/color}/base.ts +2 -0
- package/src/theme/system/v0/color/button.ts +42 -0
- package/src/theme/system/{color → v0/color}/card.ts +2 -1
- package/src/theme/system/v0/color/color.ts +40 -0
- package/src/theme/system/v0/color/index.ts +11 -0
- package/src/theme/system/v0/color/input.ts +34 -0
- package/src/theme/system/{color/_deprecated → v0/color}/muted.ts +1 -1
- package/src/theme/system/v0/color/selectable.ts +31 -0
- package/src/theme/system/{color/_deprecated → v0/color}/solid.ts +1 -1
- package/src/theme/system/v0/color/spot.ts +13 -0
- package/src/theme/system/v0/index.ts +1 -0
- package/src/theme/versioning/getTheme_v2.ts +38 -0
- package/src/theme/versioning/index.ts +5 -0
- package/src/theme/versioning/is_v0.ts +6 -0
- package/src/theme/versioning/is_v2.ts +6 -0
- package/src/theme/versioning/themeColor_v0_v2.ts +217 -0
- package/src/theme/versioning/v0_v2.ts +72 -0
- package/src/theme/versioning/v2_v0.ts +126 -0
- package/src/core/styles/colorVars/colorVarsStyle.ts +0 -43
- package/src/core/styles/colorVars/index.ts +0 -1
- package/src/core/theme/defaults.ts +0 -7
- package/src/theme/system/_system.ts +0 -95
- package/src/theme/system/color/_deprecated/spot.ts +0 -13
- package/src/theme/themes/studio/config.ts +0 -69
- package/src/theme/themes/studio/fonts.ts +0 -219
- package/src/theme/themes/studio/index.ts +0 -1
- package/src/theme/themes/studio/studioTheme.test.ts +0 -27
- package/src/theme/themes/studio/studioTheme.ts +0 -8
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {css, styled} from 'styled-components'
|
|
2
|
+
import {getTheme_v2} from '../../../../theme'
|
|
2
3
|
|
|
3
|
-
export const Root = styled.div(
|
|
4
|
-
|
|
4
|
+
export const Root = styled.div((props) => {
|
|
5
|
+
const {button, card, input} = getTheme_v2(props.theme)
|
|
6
|
+
|
|
7
|
+
return css`
|
|
5
8
|
background: #000;
|
|
6
9
|
font-family:
|
|
10
|
+
Inter,
|
|
7
11
|
system-ui,
|
|
8
12
|
-apple-system,
|
|
9
13
|
BlinkMacSystemFont,
|
|
@@ -34,13 +38,13 @@ export const Root = styled.div(
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
.button {
|
|
37
|
-
--border-width: ${
|
|
41
|
+
--border-width: ${button.border.width}px;
|
|
38
42
|
|
|
39
43
|
--bg: var(--button-enabled-bg);
|
|
40
|
-
--bg2: var(--button-enabled-bg2);
|
|
41
44
|
--fg: var(--button-enabled-fg);
|
|
42
45
|
--icon: var(--button-enabled-icon);
|
|
43
46
|
--border: var(--button-enabled-border);
|
|
47
|
+
--muted-bg: var(--button-enabled-muted-bg);
|
|
44
48
|
--muted-fg: var(--button-enabled-muted-fg);
|
|
45
49
|
--accent-fg: var(--button-enabled-accent-fg);
|
|
46
50
|
--link-fg: var(--button-enabled-link-fg);
|
|
@@ -63,10 +67,10 @@ export const Root = styled.div(
|
|
|
63
67
|
|
|
64
68
|
&:hover {
|
|
65
69
|
--bg: var(--button-hovered-bg);
|
|
66
|
-
--bg2: var(--button-hovered-bg2);
|
|
67
70
|
--fg: var(--button-hovered-fg);
|
|
68
71
|
--icon: var(--button-hovered-icon);
|
|
69
72
|
--border: var(--button-hovered-border);
|
|
73
|
+
--muted-bg: var(--button-hovered-muted-bg);
|
|
70
74
|
--muted-fg: var(--button-hovered-muted-fg);
|
|
71
75
|
--accent-fg: var(--button-hovered-accent-fg);
|
|
72
76
|
--link-fg: var(--button-hovered-link-fg);
|
|
@@ -83,10 +87,10 @@ export const Root = styled.div(
|
|
|
83
87
|
0 0 0 3px var(--focus-ring);
|
|
84
88
|
|
|
85
89
|
--bg: var(--button-hovered-bg);
|
|
86
|
-
--bg2: var(--button-hovered-bg2);
|
|
87
90
|
--fg: var(--button-hovered-fg);
|
|
88
91
|
--icon: var(--button-hovered-icon);
|
|
89
92
|
--border: var(--button-hovered-border);
|
|
93
|
+
--muted-bg: var(--button-hovered-muted-bg);
|
|
90
94
|
--muted-fg: var(--button-hovered-muted-fg);
|
|
91
95
|
--accent-fg: var(--button-hovered-accent-fg);
|
|
92
96
|
--link-fg: var(--button-hovered-link-fg);
|
|
@@ -98,10 +102,10 @@ export const Root = styled.div(
|
|
|
98
102
|
|
|
99
103
|
&:active {
|
|
100
104
|
--bg: var(--button-pressed-bg);
|
|
101
|
-
--bg2: var(--button-pressed-bg2);
|
|
102
105
|
--fg: var(--button-pressed-fg);
|
|
103
106
|
--icon: var(--button-pressed-icon);
|
|
104
107
|
--border: var(--button-pressed-border);
|
|
108
|
+
--muted-bg: var(--button-pressed-muted-bg);
|
|
105
109
|
--muted-fg: var(--button-pressed-muted-fg);
|
|
106
110
|
--accent-fg: var(--button-pressed-accent-fg);
|
|
107
111
|
--link-fg: var(--button-pressed-link-fg);
|
|
@@ -113,10 +117,10 @@ export const Root = styled.div(
|
|
|
113
117
|
|
|
114
118
|
&.selected {
|
|
115
119
|
--bg: var(--button-selected-bg);
|
|
116
|
-
--bg2: var(--button-selected-bg2);
|
|
117
120
|
--fg: var(--button-selected-fg);
|
|
118
121
|
--icon: var(--button-selected-icon);
|
|
119
122
|
--border: var(--button-selected-border);
|
|
123
|
+
--muted-bg: var(--button-selected-muted-bg);
|
|
120
124
|
--muted-fg: var(--button-selected-muted-fg);
|
|
121
125
|
--accent-fg: var(--button-selected-accent-fg);
|
|
122
126
|
--link-fg: var(--button-selected-link-fg);
|
|
@@ -128,10 +132,10 @@ export const Root = styled.div(
|
|
|
128
132
|
|
|
129
133
|
&.disabled {
|
|
130
134
|
--bg: var(--button-disabled-bg);
|
|
131
|
-
--bg2: var(--button-disabled-bg2);
|
|
132
135
|
--fg: var(--button-disabled-fg);
|
|
133
136
|
--icon: var(--button-disabled-icon);
|
|
134
137
|
--border: var(--button-disabled-border);
|
|
138
|
+
--muted-bg: var(--button-disabled-muted-bg);
|
|
135
139
|
--muted-fg: var(--button-disabled-muted-fg);
|
|
136
140
|
--accent-fg: var(--button-disabled-accent-fg);
|
|
137
141
|
--link-fg: var(--button-disabled-link-fg);
|
|
@@ -143,13 +147,13 @@ export const Root = styled.div(
|
|
|
143
147
|
}
|
|
144
148
|
|
|
145
149
|
.card {
|
|
146
|
-
--border-width: ${
|
|
150
|
+
--border-width: ${card.border.width}px;
|
|
147
151
|
|
|
148
152
|
--bg: var(--card-enabled-bg);
|
|
149
|
-
--bg2: var(--card-enabled-bg2);
|
|
150
153
|
--fg: var(--card-enabled-fg);
|
|
151
154
|
--icon: var(--card-enabled-icon);
|
|
152
155
|
--border: var(--card-enabled-border);
|
|
156
|
+
--muted-bg: var(--card-enabled-muted-bg);
|
|
153
157
|
--muted-fg: var(--card-enabled-muted-fg);
|
|
154
158
|
--accent-fg: var(--card-enabled-accent-fg);
|
|
155
159
|
--link-fg: var(--card-enabled-link-fg);
|
|
@@ -169,10 +173,10 @@ export const Root = styled.div(
|
|
|
169
173
|
|
|
170
174
|
&:hover {
|
|
171
175
|
--bg: var(--card-hovered-bg);
|
|
172
|
-
--bg2: var(--card-hovered-bg2);
|
|
173
176
|
--fg: var(--card-hovered-fg);
|
|
174
177
|
--icon: var(--card-hovered-icon);
|
|
175
178
|
--border: var(--card-hovered-border);
|
|
179
|
+
--muted-bg: var(--card-hovered-muted-bg);
|
|
176
180
|
--muted-fg: var(--card-hovered-muted-fg);
|
|
177
181
|
--accent-fg: var(--card-hovered-accent-fg);
|
|
178
182
|
--link-fg: var(--card-hovered-link-fg);
|
|
@@ -189,10 +193,10 @@ export const Root = styled.div(
|
|
|
189
193
|
0 0 0 3px var(--focus-ring);
|
|
190
194
|
|
|
191
195
|
/* --bg: var(--card-hovered-bg);
|
|
192
|
-
--bg2: var(--card-hovered-bg2);
|
|
193
196
|
--fg: var(--card-hovered-fg);
|
|
194
197
|
--icon: var(--card-hovered-icon);
|
|
195
198
|
--border: var(--card-hovered-border);
|
|
199
|
+
--muted-bg: var(--card-hovered-muted-bg);
|
|
196
200
|
--muted-fg: var(--card-hovered-muted-fg);
|
|
197
201
|
--accent-fg: var(--card-hovered-accent-fg);
|
|
198
202
|
--link-fg: var(--card-hovered-link-fg);
|
|
@@ -204,10 +208,10 @@ export const Root = styled.div(
|
|
|
204
208
|
|
|
205
209
|
&:active {
|
|
206
210
|
--bg: var(--card-pressed-bg);
|
|
207
|
-
--bg2: var(--card-pressed-bg2);
|
|
208
211
|
--fg: var(--card-pressed-fg);
|
|
209
212
|
--icon: var(--card-pressed-icon);
|
|
210
213
|
--border: var(--card-pressed-border);
|
|
214
|
+
--muted-bg: var(--card-pressed-muted-bg);
|
|
211
215
|
--muted-fg: var(--card-pressed-muted-fg);
|
|
212
216
|
--accent-fg: var(--card-pressed-accent-fg);
|
|
213
217
|
--link-fg: var(--card-pressed-link-fg);
|
|
@@ -219,10 +223,10 @@ export const Root = styled.div(
|
|
|
219
223
|
|
|
220
224
|
&.selected {
|
|
221
225
|
--bg: var(--card-selected-bg);
|
|
222
|
-
--bg2: var(--card-selected-bg2);
|
|
223
226
|
--fg: var(--card-selected-fg);
|
|
224
227
|
--icon: var(--card-selected-icon);
|
|
225
228
|
--border: var(--card-selected-border);
|
|
229
|
+
--muted-bg: var(--card-selected-muted-bg);
|
|
226
230
|
--muted-fg: var(--card-selected-muted-fg);
|
|
227
231
|
--accent-fg: var(--card-selected-accent-fg);
|
|
228
232
|
--link-fg: var(--card-selected-link-fg);
|
|
@@ -234,10 +238,10 @@ export const Root = styled.div(
|
|
|
234
238
|
|
|
235
239
|
&.disabled {
|
|
236
240
|
--bg: var(--card-disabled-bg);
|
|
237
|
-
--bg2: var(--card-disabled-bg2);
|
|
238
241
|
--fg: var(--card-disabled-fg);
|
|
239
242
|
--icon: var(--card-disabled-icon);
|
|
240
243
|
--border: var(--card-disabled-border);
|
|
244
|
+
--muted-bg: var(--card-disabled-muted-bg);
|
|
241
245
|
--muted-fg: var(--card-disabled-muted-fg);
|
|
242
246
|
--accent-fg: var(--card-disabled-accent-fg);
|
|
243
247
|
--link-fg: var(--card-disabled-link-fg);
|
|
@@ -252,7 +256,7 @@ export const Root = styled.div(
|
|
|
252
256
|
background-color: var(--bg);
|
|
253
257
|
color: var(--fg);
|
|
254
258
|
padding: var(--space-3);
|
|
255
|
-
box-shadow: inset 0 0 0 ${
|
|
259
|
+
box-shadow: inset 0 0 0 ${input.border.width}px var(--border);
|
|
256
260
|
font-size: 16px;
|
|
257
261
|
line-height: 11px;
|
|
258
262
|
border-radius: var(--radius-2);
|
|
@@ -307,7 +311,7 @@ export const Root = styled.div(
|
|
|
307
311
|
}
|
|
308
312
|
|
|
309
313
|
.bg2 {
|
|
310
|
-
background-color: var(--
|
|
314
|
+
background-color: var(--muted-bg);
|
|
311
315
|
}
|
|
312
316
|
|
|
313
317
|
.border {
|
|
@@ -342,5 +346,5 @@ export const Root = styled.div(
|
|
|
342
346
|
.skeleton-to {
|
|
343
347
|
color: var(--skeleton-to);
|
|
344
348
|
}
|
|
345
|
-
|
|
346
|
-
)
|
|
349
|
+
`
|
|
350
|
+
})
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
ThemeColorButtonStates_v2,
|
|
5
|
+
ThemeColorCard_v2,
|
|
6
|
+
ThemeColorInputStates_v2,
|
|
7
|
+
ThemeColorState_v2,
|
|
8
8
|
} from '@sanity/ui/theme'
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
THEME_COLOR_CARD_TONES,
|
|
11
11
|
THEME_COLOR_BUTTON_MODES,
|
|
12
12
|
THEME_COLOR_INPUT_MODES,
|
|
13
13
|
THEME_COLOR_STATE_TONES,
|
|
14
|
-
|
|
14
|
+
ThemeColorCardToneKey,
|
|
15
15
|
ThemeColorInputModeKey,
|
|
16
16
|
} from '@sanity/ui/theme'
|
|
17
|
-
import {
|
|
17
|
+
import {defaultTheme} from '@sanity/ui/theme'
|
|
18
18
|
import {ReactElement} from 'react'
|
|
19
19
|
import {rem} from '../../../styles'
|
|
20
|
-
import {
|
|
20
|
+
import {useTheme_v2} from '../../useTheme'
|
|
21
21
|
import {getCSSProps} from './helpers'
|
|
22
22
|
import {Root} from './Root'
|
|
23
23
|
|
|
24
|
-
const theme =
|
|
24
|
+
const theme = defaultTheme
|
|
25
25
|
|
|
26
26
|
export default function BuildStory(): ReactElement {
|
|
27
27
|
return (
|
|
@@ -45,22 +45,22 @@ export default function BuildStory(): ReactElement {
|
|
|
45
45
|
}}
|
|
46
46
|
>
|
|
47
47
|
<div style={{flex: 1}}>
|
|
48
|
-
{
|
|
48
|
+
{THEME_COLOR_CARD_TONES.map((baseTone) => (
|
|
49
49
|
<BaseTonePreview
|
|
50
50
|
baseTone={baseTone}
|
|
51
51
|
key={baseTone}
|
|
52
52
|
scheme="light"
|
|
53
|
-
theme={theme.color.light[baseTone]}
|
|
53
|
+
theme={theme.v2!.color.light[baseTone]}
|
|
54
54
|
/>
|
|
55
55
|
))}
|
|
56
56
|
</div>
|
|
57
57
|
<div style={{flex: 1}}>
|
|
58
|
-
{
|
|
58
|
+
{THEME_COLOR_CARD_TONES.map((baseTone) => (
|
|
59
59
|
<BaseTonePreview
|
|
60
60
|
baseTone={baseTone}
|
|
61
61
|
key={baseTone}
|
|
62
62
|
scheme="dark"
|
|
63
|
-
theme={theme.color.dark[baseTone]}
|
|
63
|
+
theme={theme.v2!.color.dark[baseTone]}
|
|
64
64
|
/>
|
|
65
65
|
))}
|
|
66
66
|
</div>
|
|
@@ -70,15 +70,15 @@ export default function BuildStory(): ReactElement {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
function BaseTonePreview(props: {
|
|
73
|
-
baseTone:
|
|
73
|
+
baseTone: ThemeColorCardToneKey
|
|
74
74
|
scheme: 'light' | 'dark'
|
|
75
|
-
theme:
|
|
75
|
+
theme: ThemeColorCard_v2
|
|
76
76
|
}) {
|
|
77
77
|
const {baseTone, scheme, theme: color} = props
|
|
78
|
-
const theme =
|
|
78
|
+
const theme = useTheme_v2()
|
|
79
79
|
|
|
80
80
|
return (
|
|
81
|
-
<div className="base" style={getCSSProps(color
|
|
81
|
+
<div className="base" style={getCSSProps(color as unknown as Record<string, unknown>)}>
|
|
82
82
|
<div
|
|
83
83
|
style={{
|
|
84
84
|
maxWidth: 600,
|
|
@@ -93,7 +93,7 @@ function BaseTonePreview(props: {
|
|
|
93
93
|
<div
|
|
94
94
|
style={{
|
|
95
95
|
boxShadow: [
|
|
96
|
-
`0 0 0 ${theme.
|
|
96
|
+
`0 0 0 ${theme.card.shadow.outline}px var(--shadow-outline)`,
|
|
97
97
|
`0 6px 8px -4px var(--shadow-umbra)`,
|
|
98
98
|
`0 12px 17px 2px var(--shadow-penumbra)`,
|
|
99
99
|
`0 5px 22px 4px var(--shadow-ambient)`,
|
|
@@ -106,7 +106,7 @@ function BaseTonePreview(props: {
|
|
|
106
106
|
</div>
|
|
107
107
|
</div>
|
|
108
108
|
<div style={{padding: 'var(--space-3)'}}>
|
|
109
|
-
<
|
|
109
|
+
<StatePreview theme={color.selectable.default.enabled} />
|
|
110
110
|
</div>
|
|
111
111
|
<div
|
|
112
112
|
style={{
|
|
@@ -145,7 +145,7 @@ function BaseTonePreview(props: {
|
|
|
145
145
|
)
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
function
|
|
148
|
+
function StatePreview(props: {theme: ThemeColorState_v2}) {
|
|
149
149
|
const {theme: card} = props
|
|
150
150
|
|
|
151
151
|
return (
|
|
@@ -268,11 +268,7 @@ function CardPreview(props: {theme: ThemeColorCard}) {
|
|
|
268
268
|
)
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
function ButtonPreview(props: {
|
|
272
|
-
// tone: ColorStateTone
|
|
273
|
-
// mode: ColorButtonMode
|
|
274
|
-
theme: ThemeColorButtonStates
|
|
275
|
-
}) {
|
|
271
|
+
function ButtonPreview(props: {theme: ThemeColorButtonStates_v2}) {
|
|
276
272
|
const {theme: button} = props
|
|
277
273
|
|
|
278
274
|
return (
|
|
@@ -428,7 +424,7 @@ function Skeleton() {
|
|
|
428
424
|
)
|
|
429
425
|
}
|
|
430
426
|
|
|
431
|
-
function InputPreview(props: {mode: ThemeColorInputModeKey; theme:
|
|
427
|
+
function InputPreview(props: {mode: ThemeColorInputModeKey; theme: ThemeColorInputStates_v2}) {
|
|
432
428
|
const {mode, theme: input} = props
|
|
433
429
|
|
|
434
430
|
return (
|
|
@@ -10,16 +10,14 @@ import {
|
|
|
10
10
|
useRootTheme,
|
|
11
11
|
} from '@sanity/ui'
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
ThemeColorSelectable,
|
|
22
|
-
ThemeColorSelectableStates,
|
|
13
|
+
ThemeColorButtonStates_v2,
|
|
14
|
+
ThemeColorButtonTones_v2,
|
|
15
|
+
ThemeColorButton_v2,
|
|
16
|
+
ThemeColorScheme_v2,
|
|
17
|
+
ThemeColorSelectableStates_v2,
|
|
18
|
+
ThemeColorSelectable_v2,
|
|
19
|
+
ThemeColorState_v2,
|
|
20
|
+
ThemeColorCard_v2,
|
|
23
21
|
getContrastRatio,
|
|
24
22
|
mix,
|
|
25
23
|
parseColor,
|
|
@@ -34,7 +32,6 @@ interface Features {
|
|
|
34
32
|
|
|
35
33
|
base: boolean
|
|
36
34
|
button: boolean
|
|
37
|
-
card: boolean
|
|
38
35
|
input: boolean
|
|
39
36
|
selectable: boolean
|
|
40
37
|
spot: boolean
|
|
@@ -46,7 +43,6 @@ const defaultFeatures: Features = {
|
|
|
46
43
|
|
|
47
44
|
base: false,
|
|
48
45
|
button: false,
|
|
49
|
-
card: false,
|
|
50
46
|
input: false,
|
|
51
47
|
selectable: false,
|
|
52
48
|
spot: false,
|
|
@@ -66,12 +62,9 @@ export default function CanvasStory() {
|
|
|
66
62
|
dark: useBoolean('Dark', defaultFeatures.dark, 'Props') ?? defaultFeatures.dark,
|
|
67
63
|
base: useBoolean('Base', defaultFeatures.base, 'Props') ?? defaultFeatures.base,
|
|
68
64
|
button: useBoolean('Button', defaultFeatures.button, 'Props') ?? defaultFeatures.button,
|
|
69
|
-
card: useBoolean('Card', defaultFeatures.card, 'Props') ?? defaultFeatures.card,
|
|
70
65
|
input: useBoolean('Input', defaultFeatures.input, 'Props') ?? defaultFeatures.input,
|
|
71
|
-
// muted: useBoolean('Muted', defaultFeatures.muted, 'Props') ?? defaultFeatures.muted,
|
|
72
66
|
selectable:
|
|
73
67
|
useBoolean('Selectable', defaultFeatures.selectable, 'Props') ?? defaultFeatures.selectable,
|
|
74
|
-
// solid: useBoolean('Solid', defaultFeatures.solid, 'Props') ?? defaultFeatures.solid,
|
|
75
68
|
spot: useBoolean('Avatar', defaultFeatures.spot, 'Props') ?? defaultFeatures.spot,
|
|
76
69
|
}
|
|
77
70
|
|
|
@@ -80,13 +73,13 @@ export default function CanvasStory() {
|
|
|
80
73
|
<Flex>
|
|
81
74
|
{features.light && (
|
|
82
75
|
<ThemeColorProvider scheme="light">
|
|
83
|
-
<ColorScheme scheme={theme.color.light} />
|
|
76
|
+
<ColorScheme scheme={theme.v2!.color.light} />
|
|
84
77
|
</ThemeColorProvider>
|
|
85
78
|
)}
|
|
86
79
|
|
|
87
80
|
{features.dark && (
|
|
88
81
|
<ThemeColorProvider scheme="dark">
|
|
89
|
-
<ColorScheme scheme={theme.color.dark} />
|
|
82
|
+
<ColorScheme scheme={theme.v2!.color.dark} />
|
|
90
83
|
</ThemeColorProvider>
|
|
91
84
|
)}
|
|
92
85
|
</Flex>
|
|
@@ -94,7 +87,7 @@ export default function CanvasStory() {
|
|
|
94
87
|
)
|
|
95
88
|
}
|
|
96
89
|
|
|
97
|
-
function ColorScheme(props: {scheme:
|
|
90
|
+
function ColorScheme(props: {scheme: ThemeColorScheme_v2}) {
|
|
98
91
|
const {scheme} = props
|
|
99
92
|
|
|
100
93
|
return (
|
|
@@ -109,7 +102,7 @@ function ColorScheme(props: {scheme: ThemeColorScheme}) {
|
|
|
109
102
|
)
|
|
110
103
|
}
|
|
111
104
|
|
|
112
|
-
function Color(props: {color:
|
|
105
|
+
function Color(props: {color: ThemeColorCard_v2; tone: CardTone}) {
|
|
113
106
|
const {color, tone} = props
|
|
114
107
|
const features = useFeatures()
|
|
115
108
|
|
|
@@ -119,12 +112,10 @@ function Color(props: {color: ThemeColor; tone: CardTone}) {
|
|
|
119
112
|
space={[3, 4]}
|
|
120
113
|
// style={{outline: '1px solid #ccc'}}
|
|
121
114
|
>
|
|
122
|
-
{features.base && <ColorBase color={color
|
|
115
|
+
{features.base && <ColorBase color={color} />}
|
|
123
116
|
|
|
124
117
|
{features.button && <ColorButton color={color.button} />}
|
|
125
118
|
|
|
126
|
-
{features.card && <ColorCard color={color.card} />}
|
|
127
|
-
|
|
128
119
|
{features.input && (
|
|
129
120
|
<Box padding={2} style={{backgroundColor: color.input.default.enabled.bg}}>
|
|
130
121
|
<Text style={{color: 'inherit'}}>Input</Text>
|
|
@@ -167,7 +158,7 @@ function Color(props: {color: ThemeColor; tone: CardTone}) {
|
|
|
167
158
|
)
|
|
168
159
|
}
|
|
169
160
|
|
|
170
|
-
function ColorBase(props: {color:
|
|
161
|
+
function ColorBase(props: {color: ThemeColorCard_v2}) {
|
|
171
162
|
const {color} = props
|
|
172
163
|
|
|
173
164
|
return (
|
|
@@ -199,17 +190,7 @@ function ColorBase(props: {color: ThemeColorBase}) {
|
|
|
199
190
|
)
|
|
200
191
|
}
|
|
201
192
|
|
|
202
|
-
function
|
|
203
|
-
const {color} = props
|
|
204
|
-
|
|
205
|
-
return (
|
|
206
|
-
<Box style={{backgroundColor: color.enabled.bg}}>
|
|
207
|
-
<ColorGenericStates color={color} />
|
|
208
|
-
</Box>
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function ColorButton(props: {color: ThemeColorButton}) {
|
|
193
|
+
function ColorButton(props: {color: ThemeColorButton_v2}) {
|
|
213
194
|
const {color} = props
|
|
214
195
|
|
|
215
196
|
return (
|
|
@@ -221,7 +202,7 @@ function ColorButton(props: {color: ThemeColorButton}) {
|
|
|
221
202
|
)
|
|
222
203
|
}
|
|
223
204
|
|
|
224
|
-
function ColorButtonMode(props: {color:
|
|
205
|
+
function ColorButtonMode(props: {color: ThemeColorButtonTones_v2}) {
|
|
225
206
|
const {color} = props
|
|
226
207
|
|
|
227
208
|
return (
|
|
@@ -262,7 +243,7 @@ function ColorButtonMode(props: {color: ThemeColorButtonTones}) {
|
|
|
262
243
|
)
|
|
263
244
|
}
|
|
264
245
|
|
|
265
|
-
function ColorGenericStates(props: {color:
|
|
246
|
+
function ColorGenericStates(props: {color: ThemeColorButtonStates_v2}) {
|
|
266
247
|
const {color} = props
|
|
267
248
|
|
|
268
249
|
return (
|
|
@@ -287,7 +268,7 @@ function _contrast(baseBg: string, bg: string, fg: string) {
|
|
|
287
268
|
return getContrastRatio(rgbToHex(bgRgb), fg)
|
|
288
269
|
}
|
|
289
270
|
|
|
290
|
-
function ColorGenericState(props: {color:
|
|
271
|
+
function ColorGenericState(props: {color: ThemeColorState_v2}) {
|
|
291
272
|
const {color} = props
|
|
292
273
|
|
|
293
274
|
return (
|
|
@@ -307,7 +288,7 @@ function ColorGenericState(props: {color: ThemeColorButtonState}) {
|
|
|
307
288
|
bg
|
|
308
289
|
</Text>
|
|
309
290
|
</Box>
|
|
310
|
-
<Box flex={1} padding={3} style={{backgroundColor: color.
|
|
291
|
+
<Box flex={1} padding={3} style={{backgroundColor: color.muted.bg}}>
|
|
311
292
|
<Text align="center" size={1} style={{color: 'inherit'}}>
|
|
312
293
|
bg2
|
|
313
294
|
</Text>
|
|
@@ -340,7 +321,7 @@ function ColorGenericState(props: {color: ThemeColorButtonState}) {
|
|
|
340
321
|
)
|
|
341
322
|
}
|
|
342
323
|
|
|
343
|
-
function ColorSelectable(props: {color:
|
|
324
|
+
function ColorSelectable(props: {color: ThemeColorSelectable_v2}) {
|
|
344
325
|
const {color} = props
|
|
345
326
|
|
|
346
327
|
return (
|
|
@@ -354,7 +335,7 @@ function ColorSelectable(props: {color: ThemeColorSelectable}) {
|
|
|
354
335
|
)
|
|
355
336
|
}
|
|
356
337
|
|
|
357
|
-
function ColorSelectableTone(props: {color:
|
|
338
|
+
function ColorSelectableTone(props: {color: ThemeColorSelectableStates_v2}) {
|
|
358
339
|
const {color} = props
|
|
359
340
|
|
|
360
341
|
return (
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @jest-environment jsdom */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {defaultTheme} from '@sanity/ui/theme'
|
|
5
5
|
import {render} from '../../../test'
|
|
6
6
|
import {ThemeContext} from './themeContext'
|
|
7
7
|
import {ThemeContextValue} from './types'
|
|
@@ -24,7 +24,7 @@ describe('theme', () => {
|
|
|
24
24
|
const value: ThemeContextValue = {
|
|
25
25
|
version: 0.0,
|
|
26
26
|
scheme: 'light',
|
|
27
|
-
theme:
|
|
27
|
+
theme: defaultTheme,
|
|
28
28
|
tone: 'default',
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -69,38 +69,5 @@ describe('theme', () => {
|
|
|
69
69
|
|
|
70
70
|
expect(log.mock.calls[0][0].message).toEqual('useRootTheme(): missing context value')
|
|
71
71
|
})
|
|
72
|
-
|
|
73
|
-
it('should fail when context value is not compatible', async () => {
|
|
74
|
-
const log = jest.fn()
|
|
75
|
-
|
|
76
|
-
function Debug() {
|
|
77
|
-
try {
|
|
78
|
-
useRootTheme()
|
|
79
|
-
} catch (err) {
|
|
80
|
-
log(err)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return null
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function Root() {
|
|
87
|
-
// NOTE: we’re testing this because the context value may be a function in the future
|
|
88
|
-
const value = () => {
|
|
89
|
-
return {version: 1}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<ThemeContext.Provider value={value as any}>
|
|
94
|
-
<Debug />
|
|
95
|
-
</ThemeContext.Provider>
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
render(<Root />)
|
|
100
|
-
|
|
101
|
-
expect(log.mock.calls[0][0].message).toEqual(
|
|
102
|
-
'useRootTheme(): the context value is not compatible',
|
|
103
|
-
)
|
|
104
|
-
})
|
|
105
72
|
})
|
|
106
73
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {ThemeColorCardToneKey, ThemeColorSchemeKey} from '@sanity/ui/theme'
|
|
2
2
|
import {ThemeProvider} from './themeProvider'
|
|
3
3
|
import {useRootTheme} from './useRootTheme'
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ import {useRootTheme} from './useRootTheme'
|
|
|
8
8
|
export interface ThemeColorProviderProps {
|
|
9
9
|
children?: React.ReactNode
|
|
10
10
|
scheme?: ThemeColorSchemeKey
|
|
11
|
-
tone?:
|
|
11
|
+
tone?: ThemeColorCardToneKey
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {createContext} from 'react'
|
|
1
|
+
import {Context, createContext} from 'react'
|
|
2
2
|
import {globalScope} from '../lib/globalScope'
|
|
3
3
|
import {ThemeContextValue} from './types'
|
|
4
4
|
|
|
@@ -9,4 +9,4 @@ globalScope[key] = globalScope[key] || createContext<ThemeContextValue | null>(n
|
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export const ThemeContext:
|
|
12
|
+
export const ThemeContext: Context<ThemeContextValue | null> = globalScope[key]
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
RootTheme,
|
|
3
|
+
ThemeColorCardToneKey,
|
|
4
|
+
ThemeColorSchemeKey,
|
|
5
|
+
Theme,
|
|
6
|
+
getScopedTheme,
|
|
7
|
+
} from '@sanity/ui/theme'
|
|
2
8
|
import {useContext, useMemo} from 'react'
|
|
3
9
|
import {ThemeProvider as StyledThemeProvider} from 'styled-components'
|
|
4
|
-
import {DEFAULT_THEME_LAYER} from './defaults'
|
|
5
10
|
import {ThemeContext} from './themeContext'
|
|
6
11
|
import {ThemeContextValue} from './types'
|
|
7
12
|
|
|
@@ -12,7 +17,7 @@ export interface ThemeProviderProps {
|
|
|
12
17
|
children?: React.ReactNode
|
|
13
18
|
scheme?: ThemeColorSchemeKey
|
|
14
19
|
theme?: RootTheme
|
|
15
|
-
tone?:
|
|
20
|
+
tone?: ThemeColorCardToneKey
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
/**
|
|
@@ -23,38 +28,33 @@ export function ThemeProvider(props: ThemeProviderProps): React.ReactElement {
|
|
|
23
28
|
const {
|
|
24
29
|
children,
|
|
25
30
|
scheme = parentTheme?.scheme || 'light',
|
|
26
|
-
theme:
|
|
31
|
+
theme: rootTheme = parentTheme?.theme || null,
|
|
27
32
|
tone = parentTheme?.tone || 'default',
|
|
28
33
|
} = props
|
|
29
34
|
|
|
35
|
+
const themeContext: ThemeContextValue | null = useMemo(() => {
|
|
36
|
+
if (!rootTheme) return null
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
version: 0.0,
|
|
40
|
+
theme: rootTheme,
|
|
41
|
+
scheme,
|
|
42
|
+
tone,
|
|
43
|
+
}
|
|
44
|
+
}, [rootTheme, scheme, tone])
|
|
45
|
+
|
|
30
46
|
const theme: Theme | null = useMemo(() => {
|
|
31
|
-
if (!
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const color = colorScheme[tone] || colorScheme.default
|
|
36
|
-
const layer = rootLayer || DEFAULT_THEME_LAYER
|
|
37
|
-
|
|
38
|
-
return {sanity: {...restTheme, color, layer}}
|
|
39
|
-
}, [scheme, themeProp, tone])
|
|
40
|
-
|
|
41
|
-
const value: ThemeContextValue | null = useMemo(
|
|
42
|
-
() =>
|
|
43
|
-
themeProp && {
|
|
44
|
-
version: 0.0,
|
|
45
|
-
theme: themeProp,
|
|
46
|
-
scheme,
|
|
47
|
-
tone,
|
|
48
|
-
},
|
|
49
|
-
[themeProp, scheme, tone],
|
|
50
|
-
)
|
|
47
|
+
if (!rootTheme) return null
|
|
48
|
+
|
|
49
|
+
return getScopedTheme(rootTheme, scheme, tone)
|
|
50
|
+
}, [scheme, rootTheme, tone])
|
|
51
51
|
|
|
52
52
|
if (!theme) {
|
|
53
53
|
return <pre>ThemeProvider: no "theme" property provided</pre>
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
return (
|
|
57
|
-
<ThemeContext.Provider value={
|
|
57
|
+
<ThemeContext.Provider value={themeContext}>
|
|
58
58
|
<StyledThemeProvider theme={theme}>{children}</StyledThemeProvider>
|
|
59
59
|
</ThemeContext.Provider>
|
|
60
60
|
)
|
package/src/core/theme/types.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {RootTheme,
|
|
1
|
+
import {RootTheme, ThemeColorCardToneKey, ThemeColorSchemeKey} from '@sanity/ui/theme'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
6
|
export interface ThemeContextValue {
|
|
7
|
+
/** @deprecated No longer used */
|
|
7
8
|
version: 0.0
|
|
8
9
|
scheme: ThemeColorSchemeKey
|
|
9
10
|
theme: RootTheme
|
|
10
|
-
tone:
|
|
11
|
+
tone: ThemeColorCardToneKey
|
|
11
12
|
}
|