@sanity/ui 1.8.3 → 2.0.0-alpha.10
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 +3 -0
- package/dist/index.d.ts +339 -415
- package/dist/index.esm.js +5374 -2489
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5375 -2487
- package/dist/index.js.map +1 -1
- package/package.json +21 -3
- package/src/components/autocomplete/autocomplete.tsx +2 -1
- package/src/components/dialog/constants.ts +4 -0
- package/src/components/dialog/dialog.tsx +89 -27
- package/src/components/dialog/styles.ts +3 -4
- package/src/components/hotkeys/hotkeys.tsx +2 -1
- package/src/components/menu/__workshop__/closableMenuButton.tsx +2 -2
- package/src/components/menu/menuButton.tsx +2 -2
- package/src/components/menu/menuDivider.ts +2 -1
- package/src/components/menu/menuGroup.tsx +24 -25
- package/src/components/menu/menuItem.tsx +31 -37
- package/src/components/skeleton/styles.ts +8 -7
- package/src/components/tab/tab.tsx +2 -1
- package/src/components/tree/style.ts +19 -20
- package/src/primitives/_selectable/style.ts +25 -23
- package/src/primitives/avatar/avatar.tsx +8 -3
- package/src/primitives/avatar/avatarCounter.tsx +5 -4
- package/src/primitives/avatar/spotColors.ts +53 -0
- package/src/primitives/avatar/styles.ts +6 -8
- package/src/primitives/avatar/types.ts +14 -0
- package/src/primitives/badge/badge.tsx +5 -3
- package/src/primitives/badge/styles.ts +7 -8
- package/src/primitives/box/__workshop__/responsive.tsx +2 -2
- package/src/primitives/button/__workshop__/sanityUploadButton.tsx +1 -2
- package/src/primitives/button/button.tsx +8 -9
- package/src/primitives/button/styles.ts +100 -17
- package/src/primitives/card/__workshop__/selected.tsx +8 -9
- package/src/primitives/card/card.tsx +43 -7
- package/src/primitives/card/styles.ts +31 -24
- package/src/primitives/card/types.ts +3 -1
- package/src/primitives/checkbox/checkbox.tsx +1 -0
- package/src/primitives/checkbox/styles.ts +53 -23
- package/src/primitives/code/code.tsx +15 -3
- package/src/primitives/code/styles.ts +51 -42
- package/src/primitives/heading/styles.ts +6 -5
- package/src/primitives/kbd/kbd.tsx +7 -6
- package/src/primitives/label/styles.ts +3 -2
- package/src/primitives/popover/popoverArrow.tsx +3 -2
- package/src/primitives/popover/popoverCard.tsx +8 -4
- package/src/primitives/radio/radio.tsx +1 -0
- package/src/primitives/radio/styles.ts +26 -13
- package/src/primitives/select/select.tsx +3 -2
- package/src/primitives/select/styles.ts +22 -24
- package/src/primitives/switch/__workshop__/props.tsx +4 -4
- package/src/primitives/switch/styles.ts +19 -12
- package/src/primitives/text/__workshop__/colored.tsx +10 -11
- package/src/primitives/text/styles.ts +10 -8
- package/src/primitives/textArea/textArea.tsx +8 -12
- package/src/primitives/textInput/textInput.tsx +15 -14
- package/src/primitives/tooltip/__workshop__/props.tsx +20 -3
- package/src/primitives/tooltip/tooltip.tsx +2 -2
- package/src/primitives/tooltip/tooltipArrow.tsx +3 -2
- package/src/primitives/types.ts +3 -2
- package/src/styles/border/borderStyle.ts +2 -1
- package/src/styles/colorVars/colorVarsStyle.ts +73 -30
- package/src/styles/focusRing/index.ts +8 -4
- package/src/styles/input/textInputStyle.ts +78 -94
- package/src/styles/margin/marginsStyle.test.ts +1 -2
- package/src/styles/padding/paddingStyle.test.ts +1 -2
- package/src/styles/radius/radiusStyle.ts +14 -4
- package/src/styles/radius/types.ts +3 -1
- package/src/styles/shadow/shadowStyle.ts +5 -5
- package/src/theme/__workshop__/color.tsx +2 -2
- package/src/theme/__workshop__/index.ts +0 -5
- package/src/theme/lib/color-fns/blend/multiply.ts +2 -2
- package/src/theme/lib/color-fns/blend/screen.ts +2 -2
- package/src/theme/lib/color-fns/convert.ts +15 -1
- package/src/theme/lib/color-fns/parse.ts +7 -3
- package/src/theme/lib/color-fns/types.ts +11 -0
- package/src/theme/lib/theme/avatar.ts +3 -0
- package/src/theme/lib/theme/color/_legacy/createColorTheme.ts +7 -0
- package/src/theme/lib/theme/color/_legacy/index.ts +1 -0
- package/src/theme/lib/theme/color/_legacy/legacyColor.ts +3997 -0
- package/src/theme/lib/theme/color/cssVariables/cardVariables.ts +88 -0
- package/src/theme/lib/theme/color/cssVariables/createCssVars.ts +31 -0
- package/src/theme/lib/theme/color/cssVariables/cssVars.test.ts +262 -0
- package/src/theme/lib/theme/color/cssVariables/index.ts +1 -0
- package/src/theme/lib/theme/color/cssVariables/tints.ts +312 -0
- package/src/theme/lib/theme/color/cssVariables/tones.ts +67 -0
- package/src/theme/lib/theme/color/cssVariables/utils.test.ts +15 -0
- package/src/theme/lib/theme/color/cssVariables/utils.ts +9 -0
- package/src/theme/lib/theme/color/index.ts +3 -12
- package/src/theme/lib/theme/color/types.ts +6 -37
- package/src/theme/lib/theme/input.ts +11 -0
- package/src/theme/lib/theme/theme.ts +7 -1
- package/src/theme/studioTheme/color.ts +6 -633
- package/src/theme/studioTheme/fonts.ts +3 -3
- package/src/theme/studioTheme/helpers.ts +15 -1
- package/src/theme/studioTheme/theme.ts +26 -6
- package/src/theme/themeColorProvider.tsx +2 -0
- package/src/theme/themeProvider.tsx +28 -8
- package/src/theme/toneContext/toneContext.ts +12 -0
- package/src/theme/toneContext/toneProvider.tsx +31 -0
- package/src/theme/toneContext/types.ts +10 -0
- package/src/theme/toneContext/useToneContext.tsx +26 -0
- package/src/theme/types.ts +10 -4
- package/src/types/index.ts +1 -0
- package/src/types/radius.ts +4 -0
- package/src/utils/elementQuery/__workshop__/customMedia.tsx +4 -3
- package/src/theme/__workshop__/canvas.tsx +0 -395
- package/src/theme/lib/theme/color/_generic/index.ts +0 -1
- package/src/theme/lib/theme/color/_generic/types.ts +0 -29
- package/src/theme/lib/theme/color/base/index.ts +0 -1
- package/src/theme/lib/theme/color/base/types.ts +0 -19
- package/src/theme/lib/theme/color/button/createButtonModes.ts +0 -20
- package/src/theme/lib/theme/color/button/createButtonTones.ts +0 -52
- package/src/theme/lib/theme/color/button/index.ts +0 -1
- package/src/theme/lib/theme/color/button/types.ts +0 -44
- package/src/theme/lib/theme/color/card/createCardStates.ts +0 -58
- package/src/theme/lib/theme/color/card/index.ts +0 -1
- package/src/theme/lib/theme/color/card/types.ts +0 -18
- package/src/theme/lib/theme/color/color.test.ts +0 -62
- package/src/theme/lib/theme/color/defaults.ts +0 -382
- package/src/theme/lib/theme/color/factory.ts +0 -138
- package/src/theme/lib/theme/color/input/createInputModes.ts +0 -84
- package/src/theme/lib/theme/color/input/index.ts +0 -1
- package/src/theme/lib/theme/color/input/types.ts +0 -27
- package/src/theme/lib/theme/color/muted/createMuted.ts +0 -56
- package/src/theme/lib/theme/color/muted/index.ts +0 -1
- package/src/theme/lib/theme/color/muted/types.ts +0 -24
- package/src/theme/lib/theme/color/selectable/createSelectableTones.ts +0 -73
- package/src/theme/lib/theme/color/selectable/index.ts +0 -1
- package/src/theme/lib/theme/color/selectable/types.ts +0 -29
- package/src/theme/lib/theme/color/solid/createSolidTones.ts +0 -56
- package/src/theme/lib/theme/color/solid/index.ts +0 -1
- package/src/theme/lib/theme/color/solid/types.ts +0 -24
- package/src/theme/lib/theme/color/spot/createSpot.ts +0 -21
- package/src/theme/lib/theme/color/spot/index.ts +0 -1
- package/src/theme/lib/theme/color/spot/types.ts +0 -28
- package/src/theme/lib/theme/color/syntax/index.ts +0 -1
- package/src/theme/lib/theme/color/syntax/types.ts +0 -41
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file creates a translation between the tints and the studio colors
|
|
3
|
+
* Providing readable names, and allowing to mix colors and tints in the same ThemeColor.
|
|
4
|
+
* e.g. for positive theme: `{"bg_base": "white", ""bg-base-hover"": "gray/50", ""bg-base-active"": "cyan/50"}
|
|
5
|
+
* This is not possible in the previous configuration, as each ThemeColor uses only one tint.
|
|
6
|
+
*/
|
|
7
|
+
import {ColorTintKey, ColorTints, ColorTint, black, hues, white} from '@sanity/color'
|
|
8
|
+
import {rgba} from '../../../color-fns'
|
|
9
|
+
import {ThemeColorName, ThemeColorSchemeKey} from '../types'
|
|
10
|
+
|
|
11
|
+
export const colorKeys = [
|
|
12
|
+
'text-primary',
|
|
13
|
+
'text-secondary',
|
|
14
|
+
'text-inactive',
|
|
15
|
+
// TODO: Can this be replaced by other of the text colors? It's used by the code html element if it's inside a text
|
|
16
|
+
'text-code',
|
|
17
|
+
'text-muted',
|
|
18
|
+
'text-link',
|
|
19
|
+
'text-accent',
|
|
20
|
+
'bg-base',
|
|
21
|
+
'bg-base-hover',
|
|
22
|
+
'bg-base-active',
|
|
23
|
+
'bg-accent',
|
|
24
|
+
'bg-accent-hover',
|
|
25
|
+
'bg-accent-active',
|
|
26
|
+
'bg-tint',
|
|
27
|
+
// TODO: Can we replace this with bg_tint? It's used by the code html element if it's inside a text
|
|
28
|
+
'bg-tint-code',
|
|
29
|
+
|
|
30
|
+
'icon-default',
|
|
31
|
+
'icon-inverted',
|
|
32
|
+
'border-base',
|
|
33
|
+
'border-base-hover',
|
|
34
|
+
'border-accent',
|
|
35
|
+
'border-accent-inverted',
|
|
36
|
+
|
|
37
|
+
// Colors starting with -base won't be affected by the mix function
|
|
38
|
+
'base-bg-card', // This is used by the card when a tone is defined, it will also override the bg-base in the rest of the components.
|
|
39
|
+
'base-bg-raw', // This is the same color as bg-base, but it won't be overridden by the card bg color, used in selectable items.
|
|
40
|
+
|
|
41
|
+
'base-shadow-outline-color',
|
|
42
|
+
'base-shadow-umbra-color',
|
|
43
|
+
'base-shadow-penumbra-color',
|
|
44
|
+
'base-shadow-ambient-color',
|
|
45
|
+
'base-text-color', // Color used by the buttons for default mode text
|
|
46
|
+
|
|
47
|
+
'skeleton-from',
|
|
48
|
+
'skeleton-to',
|
|
49
|
+
] as const
|
|
50
|
+
|
|
51
|
+
export type ColorKey = (typeof colorKeys)[number]
|
|
52
|
+
|
|
53
|
+
type ColorWithOpacity = {
|
|
54
|
+
type: 'colorWithOpacity'
|
|
55
|
+
tint: ColorTintKey
|
|
56
|
+
/**
|
|
57
|
+
* Number between 0 and 1
|
|
58
|
+
*/
|
|
59
|
+
opacity: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type DefaultColor = {
|
|
63
|
+
type: 'colorTint'
|
|
64
|
+
value: ColorTint
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type ColorTintsDictionary = Record<ColorKey, ColorTintKey | DefaultColor | ColorWithOpacity>
|
|
68
|
+
const defaultTints: Record<ThemeColorSchemeKey, ColorTintsDictionary> = {
|
|
69
|
+
light: {
|
|
70
|
+
'text-primary': '900',
|
|
71
|
+
'text-secondary': '600',
|
|
72
|
+
'text-inactive': '500',
|
|
73
|
+
'text-code': '600',
|
|
74
|
+
'text-muted': '600',
|
|
75
|
+
'text-link': {
|
|
76
|
+
type: 'colorTint',
|
|
77
|
+
value: hues.blue['600'],
|
|
78
|
+
},
|
|
79
|
+
'text-accent': {
|
|
80
|
+
type: 'colorTint',
|
|
81
|
+
value: hues.red['500'],
|
|
82
|
+
},
|
|
83
|
+
'bg-base': {
|
|
84
|
+
type: 'colorTint',
|
|
85
|
+
value: white,
|
|
86
|
+
},
|
|
87
|
+
'bg-base-hover': '50',
|
|
88
|
+
'bg-base-active': '100',
|
|
89
|
+
'bg-accent': '500',
|
|
90
|
+
'bg-accent-hover': '600',
|
|
91
|
+
'bg-accent-active': '700',
|
|
92
|
+
'bg-tint': '50',
|
|
93
|
+
'bg-tint-code': '50',
|
|
94
|
+
'icon-default': '500',
|
|
95
|
+
'icon-inverted': {
|
|
96
|
+
type: 'colorTint',
|
|
97
|
+
value: white,
|
|
98
|
+
},
|
|
99
|
+
'border-base': '100',
|
|
100
|
+
'border-base-hover': '200',
|
|
101
|
+
'border-accent': '500',
|
|
102
|
+
'border-accent-inverted': {
|
|
103
|
+
type: 'colorTint',
|
|
104
|
+
value: white,
|
|
105
|
+
},
|
|
106
|
+
'base-bg-card': '50',
|
|
107
|
+
'base-bg-raw': {
|
|
108
|
+
type: 'colorTint',
|
|
109
|
+
value: white,
|
|
110
|
+
},
|
|
111
|
+
'base-text-color': {type: 'colorTint', value: white},
|
|
112
|
+
'base-shadow-outline-color': {
|
|
113
|
+
type: 'colorWithOpacity',
|
|
114
|
+
tint: '500',
|
|
115
|
+
opacity: 0.2,
|
|
116
|
+
},
|
|
117
|
+
'base-shadow-umbra-color': {
|
|
118
|
+
type: 'colorWithOpacity',
|
|
119
|
+
tint: '500',
|
|
120
|
+
opacity: 0.1,
|
|
121
|
+
},
|
|
122
|
+
'base-shadow-penumbra-color': {
|
|
123
|
+
type: 'colorWithOpacity',
|
|
124
|
+
tint: '500',
|
|
125
|
+
opacity: 0.07,
|
|
126
|
+
},
|
|
127
|
+
'base-shadow-ambient-color': {
|
|
128
|
+
type: 'colorWithOpacity',
|
|
129
|
+
tint: '500',
|
|
130
|
+
opacity: 0.06,
|
|
131
|
+
},
|
|
132
|
+
'skeleton-from': '100',
|
|
133
|
+
'skeleton-to': {
|
|
134
|
+
type: 'colorWithOpacity',
|
|
135
|
+
tint: '50',
|
|
136
|
+
opacity: 0.5,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
dark: {
|
|
140
|
+
'text-primary': '50',
|
|
141
|
+
'text-secondary': '300',
|
|
142
|
+
'text-inactive': '400',
|
|
143
|
+
'text-code': '400',
|
|
144
|
+
'text-muted': '400',
|
|
145
|
+
'text-link': {
|
|
146
|
+
type: 'colorTint',
|
|
147
|
+
value: hues.blue['400'],
|
|
148
|
+
},
|
|
149
|
+
'text-accent': {
|
|
150
|
+
type: 'colorTint',
|
|
151
|
+
value: hues.red['400'],
|
|
152
|
+
},
|
|
153
|
+
'bg-base': {type: 'colorTint', value: black},
|
|
154
|
+
'bg-base-hover': '900',
|
|
155
|
+
'bg-base-active': '800',
|
|
156
|
+
'bg-accent': '500',
|
|
157
|
+
'bg-accent-hover': '400',
|
|
158
|
+
'bg-accent-active': '300',
|
|
159
|
+
'bg-tint': '900',
|
|
160
|
+
'bg-tint-code': '950',
|
|
161
|
+
'icon-default': '300',
|
|
162
|
+
'icon-inverted': {type: 'colorTint', value: hues.gray[900]},
|
|
163
|
+
'border-base': '800',
|
|
164
|
+
'border-base-hover': '700',
|
|
165
|
+
'border-accent': '300',
|
|
166
|
+
'border-accent-inverted': {type: 'colorTint', value: hues.gray[900]},
|
|
167
|
+
'base-bg-card': '950',
|
|
168
|
+
'base-text-color': {type: 'colorTint', value: black},
|
|
169
|
+
'base-shadow-outline-color': {
|
|
170
|
+
type: 'colorWithOpacity',
|
|
171
|
+
tint: '500',
|
|
172
|
+
opacity: 0.4,
|
|
173
|
+
},
|
|
174
|
+
'base-shadow-umbra-color': {
|
|
175
|
+
type: 'colorWithOpacity',
|
|
176
|
+
tint: '900',
|
|
177
|
+
opacity: 0.4,
|
|
178
|
+
},
|
|
179
|
+
'base-shadow-penumbra-color': {
|
|
180
|
+
type: 'colorWithOpacity',
|
|
181
|
+
tint: '900',
|
|
182
|
+
opacity: 0.28,
|
|
183
|
+
},
|
|
184
|
+
'base-shadow-ambient-color': {
|
|
185
|
+
type: 'colorWithOpacity',
|
|
186
|
+
tint: '900',
|
|
187
|
+
opacity: 0.24,
|
|
188
|
+
},
|
|
189
|
+
'base-bg-raw': {
|
|
190
|
+
type: 'colorTint',
|
|
191
|
+
value: black,
|
|
192
|
+
},
|
|
193
|
+
'skeleton-from': '900',
|
|
194
|
+
'skeleton-to': {
|
|
195
|
+
type: 'colorWithOpacity',
|
|
196
|
+
tint: '50',
|
|
197
|
+
opacity: 0.5,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export const colorTints: Record<
|
|
203
|
+
ThemeColorSchemeKey,
|
|
204
|
+
Record<ThemeColorName, ColorTintsDictionary>
|
|
205
|
+
> = {
|
|
206
|
+
light: {
|
|
207
|
+
default: {
|
|
208
|
+
...defaultTints.light,
|
|
209
|
+
'base-bg-card': {type: 'colorTint', value: white},
|
|
210
|
+
'bg-accent': '900',
|
|
211
|
+
'bg-accent-hover': '950',
|
|
212
|
+
'bg-accent-active': {type: 'colorTint', value: black},
|
|
213
|
+
'border-accent': '600',
|
|
214
|
+
},
|
|
215
|
+
primary: {
|
|
216
|
+
...defaultTints.light,
|
|
217
|
+
'bg-accent': '900',
|
|
218
|
+
'bg-accent-hover': '950',
|
|
219
|
+
'bg-accent-active': {type: 'colorTint', value: black},
|
|
220
|
+
'border-accent': '600',
|
|
221
|
+
},
|
|
222
|
+
positive: {
|
|
223
|
+
...defaultTints.light,
|
|
224
|
+
'bg-base-hover': {type: 'colorTint', value: hues.gray[50]},
|
|
225
|
+
'bg-base-active': '50',
|
|
226
|
+
'bg-accent': '400',
|
|
227
|
+
'bg-accent-hover': '500',
|
|
228
|
+
'bg-accent-active': '600',
|
|
229
|
+
'border-accent': '400',
|
|
230
|
+
},
|
|
231
|
+
transparent: defaultTints.light,
|
|
232
|
+
caution: defaultTints.light,
|
|
233
|
+
critical: {...defaultTints.light, 'text-inactive': '300'},
|
|
234
|
+
},
|
|
235
|
+
dark: {
|
|
236
|
+
default: {
|
|
237
|
+
...defaultTints.dark,
|
|
238
|
+
'base-bg-card': {type: 'colorTint', value: black},
|
|
239
|
+
'text-primary': {type: 'colorTint', value: white},
|
|
240
|
+
'bg-accent': {type: 'colorTint', value: white},
|
|
241
|
+
'bg-accent-hover': '50',
|
|
242
|
+
'bg-accent-active': '100',
|
|
243
|
+
'base-shadow-umbra-color': {
|
|
244
|
+
type: 'colorWithOpacity',
|
|
245
|
+
tint: '950',
|
|
246
|
+
opacity: 0.4,
|
|
247
|
+
},
|
|
248
|
+
'base-shadow-penumbra-color': {
|
|
249
|
+
type: 'colorWithOpacity',
|
|
250
|
+
tint: '950',
|
|
251
|
+
opacity: 0.28,
|
|
252
|
+
},
|
|
253
|
+
'base-shadow-ambient-color': {
|
|
254
|
+
type: 'colorWithOpacity',
|
|
255
|
+
tint: '950',
|
|
256
|
+
opacity: 0.24,
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
primary: {
|
|
260
|
+
...defaultTints.dark,
|
|
261
|
+
'text-primary': {type: 'colorTint', value: white},
|
|
262
|
+
'bg-accent': {type: 'colorTint', value: white},
|
|
263
|
+
'bg-accent-hover': '50',
|
|
264
|
+
'bg-accent-active': '100',
|
|
265
|
+
},
|
|
266
|
+
positive: {
|
|
267
|
+
...defaultTints.dark,
|
|
268
|
+
'bg-base-hover': {type: 'colorTint', value: hues.gray[900]},
|
|
269
|
+
'bg-base-active': '900',
|
|
270
|
+
'bg-accent': '400',
|
|
271
|
+
'bg-accent-hover': '300',
|
|
272
|
+
'bg-accent-active': '200',
|
|
273
|
+
'border-accent': '400',
|
|
274
|
+
},
|
|
275
|
+
transparent: defaultTints.dark,
|
|
276
|
+
caution: defaultTints.dark,
|
|
277
|
+
critical: {...defaultTints.dark, 'text-inactive': '700'},
|
|
278
|
+
},
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export const getColorValue = (
|
|
282
|
+
tints: ColorTints,
|
|
283
|
+
scheme: ThemeColorSchemeKey,
|
|
284
|
+
tone: ThemeColorName,
|
|
285
|
+
key: ColorKey,
|
|
286
|
+
): ColorTint => {
|
|
287
|
+
const value = colorTints[scheme][tone][key]
|
|
288
|
+
|
|
289
|
+
if (typeof value === 'string') {
|
|
290
|
+
return tints[value]
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (value.type === 'colorWithOpacity') {
|
|
294
|
+
const base = tints[value.tint]
|
|
295
|
+
|
|
296
|
+
return {
|
|
297
|
+
hex: rgba(base.hex, value.opacity),
|
|
298
|
+
title: `${base.title} ${Math.round(value.opacity * 100)}%`,
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return value.value
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export const getColorHex = (
|
|
306
|
+
tints: ColorTints,
|
|
307
|
+
scheme: ThemeColorSchemeKey,
|
|
308
|
+
tone: ThemeColorName,
|
|
309
|
+
key: ColorKey,
|
|
310
|
+
): string => {
|
|
311
|
+
return getColorValue(tints, scheme, tone, key).hex
|
|
312
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {ColorTints} from '@sanity/color'
|
|
2
|
+
import {multiply, screen} from '../../../../studioTheme/helpers'
|
|
3
|
+
import {ThemeColorName, ThemeColorSchemeKey} from '../types'
|
|
4
|
+
import {ColorKey, colorKeys, getColorHex} from './tints'
|
|
5
|
+
|
|
6
|
+
export const getToneCssVar = (tone: ThemeColorName, key: ColorKey): string => `--${tone}-${key}`
|
|
7
|
+
|
|
8
|
+
export const createTonesVariables = (
|
|
9
|
+
scheme: ThemeColorSchemeKey,
|
|
10
|
+
tones: Record<ThemeColorName, ColorTints>,
|
|
11
|
+
defaultTone: ThemeColorName = 'default',
|
|
12
|
+
baseBg: string,
|
|
13
|
+
): Record<string, string> => {
|
|
14
|
+
const tonesVariables: Record<string, string> = {}
|
|
15
|
+
const keys = Object.keys(tones) as ThemeColorName[]
|
|
16
|
+
const mix = scheme === 'dark' ? screen : multiply
|
|
17
|
+
const needsMixing = defaultTone !== 'default'
|
|
18
|
+
|
|
19
|
+
keys.forEach((_tone: ThemeColorName) => {
|
|
20
|
+
const tone = _tone == 'default' ? defaultTone : _tone
|
|
21
|
+
const tint = tones[tone]
|
|
22
|
+
|
|
23
|
+
colorKeys.forEach((key) => {
|
|
24
|
+
const colorHex = getColorHex(tint, scheme, tone, key)
|
|
25
|
+
const varName = getToneCssVar(_tone, key)
|
|
26
|
+
const willBeMixed = needsMixing && !key.startsWith('base-')
|
|
27
|
+
|
|
28
|
+
tonesVariables[varName] = willBeMixed ? mix(baseBg, colorHex) : colorHex
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// If we are changing the default tone, we need to update the bg-base to match with the new base bg color.
|
|
33
|
+
// As components are using this bg-base for the background color, and it needs to match with the card bg color.
|
|
34
|
+
if (defaultTone !== 'default') {
|
|
35
|
+
tonesVariables[getToneCssVar('default', 'bg-base')] = tonesCssVariables.default['base-bg-card']
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return tonesVariables
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const themeNames: ThemeColorName[] = [
|
|
42
|
+
'default',
|
|
43
|
+
'transparent',
|
|
44
|
+
'primary',
|
|
45
|
+
'positive',
|
|
46
|
+
'caution',
|
|
47
|
+
'critical',
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
export const tonesCssVariables: Record<
|
|
51
|
+
ThemeColorName,
|
|
52
|
+
Record<ColorKey, string>
|
|
53
|
+
> = themeNames.reduce(
|
|
54
|
+
(acc, tone) => {
|
|
55
|
+
acc[tone] = colorKeys.reduce(
|
|
56
|
+
(acc, key) => {
|
|
57
|
+
acc[key] = `var(${getToneCssVar(tone, key)})`
|
|
58
|
+
|
|
59
|
+
return acc
|
|
60
|
+
},
|
|
61
|
+
{} as Record<ColorKey, string>,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
return acc
|
|
65
|
+
},
|
|
66
|
+
{} as Record<ThemeColorName, Record<ColorKey, string>>,
|
|
67
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {cssObjectToCssString} from './utils'
|
|
2
|
+
|
|
3
|
+
describe('cssObjectToCssString', () => {
|
|
4
|
+
it('should transform css variables object to a style declaration type string', () => {
|
|
5
|
+
const cssObject = {
|
|
6
|
+
'--default-text-primary': '#007bff',
|
|
7
|
+
'--default-text-secondary': '#6c757d',
|
|
8
|
+
'--default-text-inactive': '#28a745',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const expectedCssString = `--default-text-primary: #007bff; --default-text-secondary: #6c757d; --default-text-inactive: #28a745; `
|
|
12
|
+
|
|
13
|
+
expect(cssObjectToCssString(cssObject)).toEqual(expectedCssString)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* Transform css variables object to a style declaration type string
|
|
4
|
+
*/
|
|
5
|
+
export function cssObjectToCssString(rules: Record<string, string>): string {
|
|
6
|
+
return Object.keys(rules).reduce((acc, key) => {
|
|
7
|
+
return `${acc}${key}: ${rules[key]}; `
|
|
8
|
+
}, '')
|
|
9
|
+
}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
export * from './factory'
|
|
2
|
-
export * from './syntax'
|
|
3
1
|
export * from './types'
|
|
4
2
|
|
|
5
|
-
//
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './button'
|
|
9
|
-
export * from './card'
|
|
10
|
-
export * from './input'
|
|
11
|
-
export * from './selectable'
|
|
12
|
-
export * from './muted'
|
|
13
|
-
export * from './solid'
|
|
14
|
-
export * from './spot'
|
|
3
|
+
// Css Variables
|
|
4
|
+
export * from './cssVariables'
|
|
5
|
+
export * from './_legacy'
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {ThemeColorButton} from './button'
|
|
3
|
-
import {ThemeColorCard} from './card'
|
|
4
|
-
import {ThemeColorInput} from './input'
|
|
5
|
-
import {ThemeColorMuted} from './muted'
|
|
6
|
-
import {ThemeColorSelectable} from './selectable'
|
|
7
|
-
import {ThemeColorSolid} from './solid'
|
|
8
|
-
import {ThemeColorSpot} from './spot'
|
|
9
|
-
import {ThemeColorSyntax} from './syntax'
|
|
1
|
+
import {ColorTints} from '@sanity/color'
|
|
10
2
|
|
|
11
3
|
/**
|
|
12
4
|
* @public
|
|
@@ -38,35 +30,12 @@ export type ThemeColorToneKey =
|
|
|
38
30
|
/**
|
|
39
31
|
* @public
|
|
40
32
|
*/
|
|
41
|
-
export interface
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
button: ThemeColorButton
|
|
45
|
-
card: ThemeColorCard
|
|
46
|
-
input: ThemeColorInput
|
|
47
|
-
selectable?: ThemeColorSelectable
|
|
48
|
-
spot: ThemeColorSpot
|
|
49
|
-
syntax: ThemeColorSyntax
|
|
50
|
-
solid: ThemeColorSolid
|
|
51
|
-
muted: ThemeColorMuted
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @public
|
|
56
|
-
*/
|
|
57
|
-
export interface ThemeColorScheme {
|
|
58
|
-
default: ThemeColor
|
|
59
|
-
transparent: ThemeColor
|
|
60
|
-
primary: ThemeColor
|
|
61
|
-
positive: ThemeColor
|
|
62
|
-
caution: ThemeColor
|
|
63
|
-
critical: ThemeColor
|
|
33
|
+
export interface ThemeColorSchemes {
|
|
34
|
+
// Could we update this to only return Record<ThemeColorName , keyof typeof hues> ? Then the function that assigns the color would search the ColorTint
|
|
35
|
+
tones: Record<ThemeColorName, ColorTints>
|
|
64
36
|
}
|
|
65
37
|
|
|
66
38
|
/**
|
|
67
|
-
* @
|
|
39
|
+
* @beta
|
|
68
40
|
*/
|
|
69
|
-
export
|
|
70
|
-
dark: ThemeColorScheme
|
|
71
|
-
light: ThemeColorScheme
|
|
72
|
-
}
|
|
41
|
+
export type CSSVariableKey = ThemeColorName & ('spot' | 'syntax' | 'mutable')
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import {FocusRing} from '../../types'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @public
|
|
3
5
|
*/
|
|
4
6
|
export interface ThemeInput {
|
|
5
7
|
checkbox: {
|
|
6
8
|
size: number
|
|
9
|
+
focusRing: FocusRing
|
|
7
10
|
}
|
|
8
11
|
radio: {
|
|
9
12
|
size: number
|
|
10
13
|
markSize: number
|
|
14
|
+
focusRing: FocusRing
|
|
11
15
|
}
|
|
12
16
|
switch: {
|
|
13
17
|
width: number
|
|
@@ -15,8 +19,15 @@ export interface ThemeInput {
|
|
|
15
19
|
padding: number
|
|
16
20
|
transitionDurationMs: number
|
|
17
21
|
transitionTimingFunction: string
|
|
22
|
+
focusRing: FocusRing
|
|
18
23
|
}
|
|
19
24
|
border: {
|
|
20
25
|
width: number
|
|
21
26
|
}
|
|
27
|
+
select: {
|
|
28
|
+
focusRing: FocusRing
|
|
29
|
+
}
|
|
30
|
+
text: {
|
|
31
|
+
focusRing: FocusRing
|
|
32
|
+
}
|
|
22
33
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {FocusRing} from '../../types'
|
|
1
2
|
import {ThemeAvatar} from './avatar'
|
|
2
3
|
import {ThemeColorSchemes} from './color'
|
|
3
4
|
import {ThemeFonts, ThemeFontWeightKey} from './fonts'
|
|
@@ -15,14 +16,20 @@ export interface BaseTheme<
|
|
|
15
16
|
avatar: ThemeAvatar
|
|
16
17
|
button: {
|
|
17
18
|
textWeight: ThemeFontWeightKey
|
|
19
|
+
focusRing: FocusRing
|
|
20
|
+
}
|
|
21
|
+
card: {
|
|
22
|
+
focusRing: FocusRing
|
|
18
23
|
}
|
|
19
24
|
color: ThemeColorSchemes
|
|
20
25
|
container: number[]
|
|
26
|
+
/** @deprecated Use component-specific `focusRing` values instead */
|
|
21
27
|
focusRing: {
|
|
22
28
|
offset: number
|
|
23
29
|
width: number
|
|
24
30
|
}
|
|
25
31
|
fonts: ThemeFonts
|
|
32
|
+
input: ThemeInput
|
|
26
33
|
/**
|
|
27
34
|
* THIS API MAY BE UNSTABLE. DO NOT USE IN PRODUCTION.
|
|
28
35
|
* @beta
|
|
@@ -32,6 +39,5 @@ export interface BaseTheme<
|
|
|
32
39
|
radius: number[]
|
|
33
40
|
shadows: Array<ThemeShadow | null>
|
|
34
41
|
space: number[]
|
|
35
|
-
input: ThemeInput
|
|
36
42
|
styles?: Styles
|
|
37
43
|
}
|