@sanity/ui 2.0.0-beta.2 → 2.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +6 -3
- package/dist/index.cjs.mjs +11 -36
- package/dist/index.d.ts +247 -267
- package/dist/index.esm.js +477 -326
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +486 -539
- package/dist/index.js.map +1 -1
- package/dist/theme.cjs.mjs +1 -1
- package/dist/theme.d.ts +87 -115
- package/dist/theme.esm.js +348 -290
- package/dist/theme.esm.js.map +1 -1
- package/dist/theme.js +348 -290
- package/dist/theme.js.map +1 -1
- package/package.json +6 -3
- package/src/core/__workshop__/fontsPlugin.tsx +48 -8
- package/src/core/_compat.ts +236 -87
- package/src/core/components/dialog/dialog.tsx +1 -1
- package/src/core/components/dialog/styles.ts +2 -2
- package/src/core/components/menu/__workshop__/selectedItem.tsx +7 -2
- package/src/core/components/menu/menuButton.tsx +12 -1
- package/src/core/components/toast/toast.tsx +17 -2
- package/src/core/components/toast/toastProvider.tsx +20 -3
- package/src/core/constants.ts +37 -0
- package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +6 -3
- package/src/core/middleware/origin.ts +47 -0
- package/src/core/primitives/badge/badge.tsx +1 -3
- package/src/core/primitives/button/button.tsx +9 -11
- package/src/core/primitives/heading/styles.ts +4 -0
- package/src/core/primitives/kbd/kbd.tsx +2 -0
- package/src/core/primitives/popover/popover.tsx +67 -13
- package/src/core/primitives/popover/popoverCard.tsx +31 -15
- package/src/core/primitives/select/select.tsx +1 -1
- package/src/core/primitives/switch/styles.ts +6 -1
- package/src/core/primitives/textInput/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/states.tsx +10 -2
- package/src/core/primitives/tooltip/tooltip.tsx +46 -56
- package/src/core/primitives/tooltip/tooltipCard.tsx +110 -0
- package/src/core/styles/card/_cardColorStyle.ts +2 -0
- package/src/core/styles/input/textInputStyle.ts +33 -2
- package/src/core/styles/margin/marginsStyle.test.ts +2 -2
- package/src/core/styles/padding/paddingStyle.test.ts +2 -2
- package/src/core/theme/__workshop__/build/Root.tsx +20 -3
- package/src/core/theme/__workshop__/build/story.tsx +16 -10
- package/src/core/theme/__workshop__/canvas.tsx +7 -7
- package/src/core/theme/__workshop__/debug/story.tsx +196 -0
- package/src/core/theme/__workshop__/index.ts +5 -0
- package/src/core/theme/theme.test.tsx +2 -2
- package/src/core/types/button.ts +1 -2
- package/src/core/{primitives/tooltip → utils/conditionalWrapper}/conditionalWrapper.tsx +3 -0
- package/src/core/utils/conditionalWrapper/index.ts +1 -0
- package/src/core/utils/index.ts +1 -0
- package/src/theme/build/_deprecated/color/factory.ts +3 -3
- package/src/theme/build/buildColorTheme.test.ts +2 -2
- package/src/theme/build/buildColorTheme.ts +16 -16
- package/src/theme/build/colorToken/colorToken.ts +19 -0
- package/src/theme/build/colorToken/compileColorToken.ts +21 -0
- package/src/theme/build/colorToken/index.ts +2 -0
- package/src/theme/build/colorToken/types.ts +6 -0
- package/src/theme/build/renderColorTheme.ts +14 -15
- package/src/theme/build/renderColorValue.ts +9 -2
- package/src/theme/config/system.ts +12 -10
- package/src/theme/config/tokens/color/types.ts +12 -1
- package/src/theme/config/tokens/parseTokenKey.ts +1 -0
- package/src/theme/config/tokens/parseTokenValue.test.ts +13 -16
- package/src/theme/config/tokens/parseTokenValue.ts +45 -14
- package/src/theme/config/tokens/types.ts +3 -2
- package/src/theme/defaults/colorTokens.ts +279 -253
- package/src/theme/defaults/config.ts +2 -2
- package/src/theme/getScopedTheme.ts +1 -0
- package/src/theme/index.ts +0 -7
- package/src/theme/system/color/_constants.ts +5 -2
- package/src/theme/system/color/_system.ts +2 -1
- package/src/theme/system/color/avatar.ts +2 -12
- package/src/theme/system/color/button.ts +4 -20
- package/src/theme/system/color/input.ts +3 -11
- package/src/theme/system/color/selectable.ts +3 -14
- package/src/theme/system/shadow.ts +0 -6
- package/src/theme/system/styles.ts +0 -6
- package/src/theme/system/theme.ts +11 -1
- package/src/theme/system/v0/avatar.ts +1 -1
- package/src/theme/system/v0/color/button.ts +4 -4
- package/src/theme/system/v0/color/card.ts +2 -2
- package/src/theme/system/v0/color/color.ts +0 -1
- package/src/theme/system/v0/color/input.ts +3 -3
- package/src/theme/system/v0/color/muted.ts +2 -2
- package/src/theme/system/v0/color/solid.ts +2 -2
- package/src/theme/versioning/getTheme_v2.ts +2 -1
- package/src/theme/versioning/themeColor_v0_v2.ts +2 -2
- package/src/theme/versioning/v2_v0.ts +3 -2
- package/src/theme/build/colorToken.ts +0 -39
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import {CropIcon} from '@sanity/icons'
|
|
2
|
+
import {
|
|
3
|
+
THEME_COLOR_BUTTON_MODES,
|
|
4
|
+
THEME_COLOR_CARD_TONES,
|
|
5
|
+
THEME_COLOR_SCHEMES,
|
|
6
|
+
THEME_COLOR_STATES,
|
|
7
|
+
THEME_COLOR_STATE_TONES,
|
|
8
|
+
ThemeColorCard_v2,
|
|
9
|
+
ThemeColorScheme_v2,
|
|
10
|
+
ThemeColorState_v2,
|
|
11
|
+
} from '@sanity/ui/theme'
|
|
12
|
+
import {useBoolean} from '@sanity/ui-workshop'
|
|
13
|
+
import {CSSProperties} from 'react'
|
|
14
|
+
import {Badge, Box, Flex, KBD, Stack, Text} from '../../../primitives'
|
|
15
|
+
import {useRootTheme} from '../../useRootTheme'
|
|
16
|
+
|
|
17
|
+
export default function DebugStory() {
|
|
18
|
+
const {color} = useRootTheme().theme.v2!
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Flex>
|
|
22
|
+
{THEME_COLOR_SCHEMES.map((scheme) => (
|
|
23
|
+
<DebugScheme key={scheme} scheme={color[scheme]} />
|
|
24
|
+
))}
|
|
25
|
+
</Flex>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function DebugScheme(props: {scheme: ThemeColorScheme_v2}) {
|
|
30
|
+
const {scheme} = props
|
|
31
|
+
|
|
32
|
+
const button = useBoolean('Button', false, 'Props') || false
|
|
33
|
+
const selectable = useBoolean('Selectable', false, 'Props') || false
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<Box flex={1} style={{backgroundColor: scheme.default.bg}}>
|
|
37
|
+
{THEME_COLOR_CARD_TONES.map((tone) => (
|
|
38
|
+
<DebugCard card={scheme[tone]} features={{button, selectable}} key={tone} />
|
|
39
|
+
))}
|
|
40
|
+
</Box>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function DebugCard(props: {
|
|
45
|
+
card: ThemeColorCard_v2
|
|
46
|
+
features: {button: boolean; selectable: boolean}
|
|
47
|
+
}) {
|
|
48
|
+
const {card, features} = props
|
|
49
|
+
|
|
50
|
+
// card.avatar
|
|
51
|
+
// card.backdrop
|
|
52
|
+
// card.badge
|
|
53
|
+
// card.button
|
|
54
|
+
// card.focusRing
|
|
55
|
+
// card.icon
|
|
56
|
+
// card.input
|
|
57
|
+
// card.kbd
|
|
58
|
+
// card.link
|
|
59
|
+
// card.selectable
|
|
60
|
+
// card.shadow
|
|
61
|
+
// card.skeleton
|
|
62
|
+
// card.syntax
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Box style={getStateVars(card)}>
|
|
66
|
+
<DebugState />
|
|
67
|
+
|
|
68
|
+
{features.button && (
|
|
69
|
+
<Stack padding={2} space={1}>
|
|
70
|
+
{THEME_COLOR_BUTTON_MODES.map((mode) => (
|
|
71
|
+
<Stack key={mode} space={1}>
|
|
72
|
+
{THEME_COLOR_STATE_TONES.map((stateTone) => (
|
|
73
|
+
<Flex key={stateTone} gap={1}>
|
|
74
|
+
{/* {mode} */}
|
|
75
|
+
{THEME_COLOR_STATES.map((state) => (
|
|
76
|
+
<Box
|
|
77
|
+
flex={1}
|
|
78
|
+
key={state}
|
|
79
|
+
style={getStateVars(card.button[mode][stateTone][state])}
|
|
80
|
+
>
|
|
81
|
+
<DebugState />
|
|
82
|
+
</Box>
|
|
83
|
+
))}
|
|
84
|
+
</Flex>
|
|
85
|
+
))}
|
|
86
|
+
</Stack>
|
|
87
|
+
))}
|
|
88
|
+
</Stack>
|
|
89
|
+
)}
|
|
90
|
+
|
|
91
|
+
{features.selectable && (
|
|
92
|
+
<Stack padding={2} space={1}>
|
|
93
|
+
{THEME_COLOR_STATE_TONES.map((stateTone) => (
|
|
94
|
+
<Flex key={stateTone} gap={1}>
|
|
95
|
+
{/* {mode} */}
|
|
96
|
+
{THEME_COLOR_STATES.map((state) => (
|
|
97
|
+
<Box flex={1} key={state} style={getStateVars(card.selectable[stateTone][state])}>
|
|
98
|
+
<DebugState />
|
|
99
|
+
</Box>
|
|
100
|
+
))}
|
|
101
|
+
</Flex>
|
|
102
|
+
))}
|
|
103
|
+
</Stack>
|
|
104
|
+
)}
|
|
105
|
+
</Box>
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function DebugState() {
|
|
110
|
+
return (
|
|
111
|
+
<Stack
|
|
112
|
+
overflow="auto"
|
|
113
|
+
padding={4}
|
|
114
|
+
space={3}
|
|
115
|
+
style={{border: '1px solid var(--card-border-color)'}}
|
|
116
|
+
>
|
|
117
|
+
<Flex gap={3}>
|
|
118
|
+
<Text size={1}>Text</Text>
|
|
119
|
+
<Text size={1}>
|
|
120
|
+
<CropIcon />
|
|
121
|
+
</Text>
|
|
122
|
+
</Flex>
|
|
123
|
+
<Text muted size={1}>
|
|
124
|
+
Muted
|
|
125
|
+
</Text>
|
|
126
|
+
<Text accent size={1}>
|
|
127
|
+
Accent
|
|
128
|
+
</Text>
|
|
129
|
+
<Text size={1}>
|
|
130
|
+
<code>Code</code>
|
|
131
|
+
</Text>
|
|
132
|
+
<div>
|
|
133
|
+
<KBD>Cmd</KBD>
|
|
134
|
+
</div>
|
|
135
|
+
<Flex gap={1}>
|
|
136
|
+
{THEME_COLOR_STATE_TONES.map((stateTone) => (
|
|
137
|
+
<Box flex="none" key={stateTone}>
|
|
138
|
+
<Badge tone={stateTone}>{stateTone}</Badge>
|
|
139
|
+
</Box>
|
|
140
|
+
))}
|
|
141
|
+
</Flex>
|
|
142
|
+
<div style={{borderBottom: '1px solid var(--card-border-color)'}} />
|
|
143
|
+
</Stack>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function getStateVars(state: ThemeColorState_v2) {
|
|
148
|
+
return {
|
|
149
|
+
'--card-accent-fg-color': state.accent.fg,
|
|
150
|
+
|
|
151
|
+
'--card-code-bg-color': state.code.bg,
|
|
152
|
+
'--card-code-fg-color': state.code.fg,
|
|
153
|
+
|
|
154
|
+
'--card-bg-color': state.bg,
|
|
155
|
+
|
|
156
|
+
'--card-border-color': state.border,
|
|
157
|
+
|
|
158
|
+
'--card-fg-color': state.fg,
|
|
159
|
+
|
|
160
|
+
'--card-icon-color': state.icon,
|
|
161
|
+
|
|
162
|
+
'--card-muted-fg-color': state.muted.fg,
|
|
163
|
+
|
|
164
|
+
'--card-kbd-bg-color': state.kbd.bg,
|
|
165
|
+
'--card-kbd-border-color': state.kbd.border,
|
|
166
|
+
'--card-kbd-fg-color': state.kbd.fg,
|
|
167
|
+
|
|
168
|
+
'--card-badge-default-bg-color': state.badge.default.bg,
|
|
169
|
+
'--card-badge-default-dot-color': state.badge.default.dot,
|
|
170
|
+
'--card-badge-default-fg-color': state.badge.default.fg,
|
|
171
|
+
'--card-badge-default-icon-color': state.badge.default.icon,
|
|
172
|
+
|
|
173
|
+
'--card-badge-primary-bg-color': state.badge.primary.bg,
|
|
174
|
+
'--card-badge-primary-dot-color': state.badge.primary.dot,
|
|
175
|
+
'--card-badge-primary-fg-color': state.badge.primary.fg,
|
|
176
|
+
'--card-badge-primary-icon-color': state.badge.primary.icon,
|
|
177
|
+
|
|
178
|
+
'--card-badge-positive-bg-color': state.badge.positive.bg,
|
|
179
|
+
'--card-badge-positive-dot-color': state.badge.positive.dot,
|
|
180
|
+
'--card-badge-positive-fg-color': state.badge.positive.fg,
|
|
181
|
+
'--card-badge-positive-icon-color': state.badge.positive.icon,
|
|
182
|
+
|
|
183
|
+
'--card-badge-caution-bg-color': state.badge.caution.bg,
|
|
184
|
+
'--card-badge-caution-dot-color': state.badge.caution.dot,
|
|
185
|
+
'--card-badge-caution-fg-color': state.badge.caution.fg,
|
|
186
|
+
'--card-badge-caution-icon-color': state.badge.caution.icon,
|
|
187
|
+
|
|
188
|
+
'--card-badge-critical-bg-color': state.badge.critical.bg,
|
|
189
|
+
'--card-badge-critical-dot-color': state.badge.critical.dot,
|
|
190
|
+
'--card-badge-critical-fg-color': state.badge.critical.fg,
|
|
191
|
+
'--card-badge-critical-icon-color': state.badge.critical.icon,
|
|
192
|
+
|
|
193
|
+
backgroundColor: 'var(--card-bg-color)',
|
|
194
|
+
color: 'var(--card-fg-color)',
|
|
195
|
+
} as CSSProperties
|
|
196
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @jest-environment jsdom */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {buildTheme} 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: buildTheme(),
|
|
28
28
|
tone: 'default',
|
|
29
29
|
}
|
|
30
30
|
|
package/src/core/types/button.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './conditionalWrapper'
|
package/src/core/utils/index.ts
CHANGED
|
@@ -27,7 +27,7 @@ import {createSpot} from './spot/createSpot'
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* @public
|
|
30
|
-
* @deprecated
|
|
30
|
+
* @deprecated Use `buildColorTheme` instead.
|
|
31
31
|
*/
|
|
32
32
|
export interface ThemeColorBuilderOpts {
|
|
33
33
|
base: (opts: {dark: boolean; name: ThemeColorName}) => ThemeColorBase
|
|
@@ -82,13 +82,13 @@ export interface ThemeColorBuilderOpts {
|
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* @public
|
|
85
|
-
* @deprecated
|
|
85
|
+
* @deprecated Use `ThemeConfig` instead.
|
|
86
86
|
*/
|
|
87
87
|
export type PartialThemeColorBuilderOpts = Partial<ThemeColorBuilderOpts>
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* @public
|
|
91
|
-
* @deprecated Use `
|
|
91
|
+
* @deprecated Use `buildColorTheme` instead.
|
|
92
92
|
*/
|
|
93
93
|
export function createColorTheme(
|
|
94
94
|
partialOpts: PartialThemeColorBuilderOpts = {},
|
|
@@ -65,7 +65,7 @@ test('buildColorTheme: base', () => {
|
|
|
65
65
|
light: {
|
|
66
66
|
transparent: {
|
|
67
67
|
bg: 'gray/50',
|
|
68
|
-
fg: 'gray/
|
|
68
|
+
fg: 'gray/800',
|
|
69
69
|
},
|
|
70
70
|
default: {
|
|
71
71
|
bg: 'white',
|
|
@@ -79,7 +79,7 @@ test('buildColorTheme: base', () => {
|
|
|
79
79
|
dark: {
|
|
80
80
|
transparent: {
|
|
81
81
|
bg: 'black',
|
|
82
|
-
fg: 'gray/
|
|
82
|
+
fg: 'gray/200',
|
|
83
83
|
},
|
|
84
84
|
default: {
|
|
85
85
|
bg: 'gray/950',
|
|
@@ -18,11 +18,11 @@ import {
|
|
|
18
18
|
ThemeColorShadow,
|
|
19
19
|
ThemeColorState_v2,
|
|
20
20
|
ThemeColorButton_v2,
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
ThemeColorButtonMode_v2,
|
|
22
|
+
ThemeColorButtonTone_v2,
|
|
23
23
|
ThemeColorAvatarHue_v2,
|
|
24
24
|
ThemeColorInput_v2,
|
|
25
|
-
|
|
25
|
+
ThemeColorInputMode_v2,
|
|
26
26
|
ThemeColorInputState_v2,
|
|
27
27
|
} from '../system'
|
|
28
28
|
import {ColorTokenContext, resolveColorTokenValue as _color} from './colorToken'
|
|
@@ -215,16 +215,16 @@ function buildButtonTonesColorTheme(
|
|
|
215
215
|
mode: ThemeColorButtonModeKey
|
|
216
216
|
},
|
|
217
217
|
config?: ThemeConfig,
|
|
218
|
-
):
|
|
218
|
+
): ThemeColorButtonMode_v2 {
|
|
219
219
|
const {mode, scheme} = options
|
|
220
220
|
|
|
221
|
-
const tones: Partial<
|
|
221
|
+
const tones: Partial<ThemeColorButtonMode_v2> = {}
|
|
222
222
|
|
|
223
223
|
for (const tone of THEME_COLOR_STATE_TONES) {
|
|
224
224
|
tones[tone] = buildButtonStatesColorTheme({mode, scheme, tone}, config)
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
return tones as
|
|
227
|
+
return tones as ThemeColorButtonMode_v2
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
function buildButtonStatesColorTheme(
|
|
@@ -234,16 +234,16 @@ function buildButtonStatesColorTheme(
|
|
|
234
234
|
tone: ThemeColorStateToneKey
|
|
235
235
|
},
|
|
236
236
|
config?: ThemeConfig,
|
|
237
|
-
):
|
|
237
|
+
): ThemeColorButtonTone_v2 {
|
|
238
238
|
const {mode, scheme, tone} = options
|
|
239
239
|
|
|
240
|
-
const states: Partial<
|
|
240
|
+
const states: Partial<ThemeColorButtonTone_v2> = {}
|
|
241
241
|
|
|
242
242
|
for (const state of THEME_COLOR_STATES) {
|
|
243
243
|
states[state] = buildButtonStateColorTheme({mode, tone, scheme, state}, config)
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
return states as
|
|
246
|
+
return states as ThemeColorButtonTone_v2
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
function buildButtonStateColorTheme(
|
|
@@ -314,7 +314,7 @@ function buildInputStatesColorTheme(
|
|
|
314
314
|
tone: ThemeColorCardToneKey
|
|
315
315
|
},
|
|
316
316
|
config?: ThemeConfig,
|
|
317
|
-
):
|
|
317
|
+
): ThemeColorInputMode_v2 {
|
|
318
318
|
const {mode, scheme, tone} = options
|
|
319
319
|
|
|
320
320
|
return {
|
|
@@ -357,16 +357,16 @@ function buildSelectableColorTheme(
|
|
|
357
357
|
scheme: ThemeColorSchemeKey
|
|
358
358
|
},
|
|
359
359
|
config?: ThemeConfig,
|
|
360
|
-
):
|
|
360
|
+
): ThemeColorButtonMode_v2 {
|
|
361
361
|
const {scheme} = options
|
|
362
362
|
|
|
363
|
-
const tones: Partial<
|
|
363
|
+
const tones: Partial<ThemeColorButtonMode_v2> = {}
|
|
364
364
|
|
|
365
365
|
for (const tone of THEME_COLOR_STATE_TONES) {
|
|
366
366
|
tones[tone] = buildSelectableStatesColorTheme({scheme, tone}, config)
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
return tones as
|
|
369
|
+
return tones as ThemeColorButtonMode_v2
|
|
370
370
|
}
|
|
371
371
|
|
|
372
372
|
function buildSelectableStatesColorTheme(
|
|
@@ -375,16 +375,16 @@ function buildSelectableStatesColorTheme(
|
|
|
375
375
|
tone: ThemeColorStateToneKey
|
|
376
376
|
},
|
|
377
377
|
config?: ThemeConfig,
|
|
378
|
-
):
|
|
378
|
+
): ThemeColorButtonTone_v2 {
|
|
379
379
|
const {scheme, tone} = options
|
|
380
380
|
|
|
381
|
-
const states: Partial<
|
|
381
|
+
const states: Partial<ThemeColorButtonTone_v2> = {}
|
|
382
382
|
|
|
383
383
|
for (const state of THEME_COLOR_STATES) {
|
|
384
384
|
states[state] = buildSelectableStateColorTheme({tone, scheme, state}, config)
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
return states as
|
|
387
|
+
return states as ThemeColorButtonTone_v2
|
|
388
388
|
}
|
|
389
389
|
|
|
390
390
|
function buildSelectableStateColorTheme(
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {ThemeColorTokenValue, parseTokenValue} from '../../config'
|
|
2
|
+
import {compileColorTokenValue} from './compileColorToken'
|
|
3
|
+
import {ColorTokenContext} from './types'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_COLOR_TOKEN_VALUE: ThemeColorTokenValue = ['500', '500']
|
|
6
|
+
|
|
7
|
+
export function resolveColorTokenValue(
|
|
8
|
+
context: ColorTokenContext,
|
|
9
|
+
value: ThemeColorTokenValue = DEFAULT_COLOR_TOKEN_VALUE,
|
|
10
|
+
): string {
|
|
11
|
+
const {hue, scheme} = context
|
|
12
|
+
const node = parseTokenValue(value[scheme === 'light' ? 0 : 1])
|
|
13
|
+
|
|
14
|
+
if (!node || node.type !== 'color') {
|
|
15
|
+
throw new Error(`Invalid color token: ${value[0]}`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return compileColorTokenValue({...node, hue: node.hue || hue})
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {TokenColorValueNode} from '../../config'
|
|
2
|
+
|
|
3
|
+
export function compileColorTokenValue(node: TokenColorValueNode): string {
|
|
4
|
+
let key = ''
|
|
5
|
+
|
|
6
|
+
if (node.key === 'black' || node.key === 'white') {
|
|
7
|
+
key = node.key
|
|
8
|
+
} else {
|
|
9
|
+
key = `${node.hue}/${node.tint}`
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (node.mix !== undefined) {
|
|
13
|
+
return `${key} ${node.mix * 100}%`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (node.opacity !== undefined) {
|
|
17
|
+
key += `/${node.opacity}`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return key
|
|
21
|
+
}
|
|
@@ -5,18 +5,18 @@ import {
|
|
|
5
5
|
ThemeColorBadgeTone_v2,
|
|
6
6
|
ThemeColorBadge_v2,
|
|
7
7
|
ThemeColorBlendModeKey,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
ThemeColorButtonMode_v2,
|
|
9
|
+
ThemeColorButtonTone_v2,
|
|
10
10
|
ThemeColorButton_v2,
|
|
11
11
|
ThemeColorCardToneKey,
|
|
12
12
|
ThemeColorCard_v2,
|
|
13
|
+
ThemeColorInputMode_v2,
|
|
13
14
|
ThemeColorInputState_v2,
|
|
14
|
-
ThemeColorInputStates_v2,
|
|
15
15
|
ThemeColorInput_v2,
|
|
16
16
|
ThemeColorKBD,
|
|
17
17
|
ThemeColorScheme_v2,
|
|
18
18
|
ThemeColorSchemes_v2,
|
|
19
|
-
|
|
19
|
+
ThemeColorSelectableTone_v2,
|
|
20
20
|
ThemeColorSelectable_v2,
|
|
21
21
|
ThemeColorShadow,
|
|
22
22
|
ThemeColorState_v2,
|
|
@@ -278,10 +278,9 @@ function renderThemeColorBadgeColor(
|
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
return {
|
|
281
|
-
// _blend: blendMode,
|
|
282
281
|
bg,
|
|
283
|
-
fg: renderColorValue(value.fg, colorOptions),
|
|
284
282
|
dot: renderColorValue(value.dot, colorOptions),
|
|
283
|
+
fg: renderColorValue(value.fg, colorOptions),
|
|
285
284
|
icon: renderColorValue(value.icon, colorOptions),
|
|
286
285
|
}
|
|
287
286
|
}
|
|
@@ -302,13 +301,13 @@ function renderThemeColorButton(
|
|
|
302
301
|
}
|
|
303
302
|
|
|
304
303
|
function renderThemeColorButtonTones(
|
|
305
|
-
value:
|
|
304
|
+
value: ThemeColorButtonMode_v2,
|
|
306
305
|
options: {
|
|
307
306
|
baseBg: string
|
|
308
307
|
blendMode: ThemeColorBlendModeKey
|
|
309
308
|
colorPalette: ThemeColorPalette
|
|
310
309
|
},
|
|
311
|
-
):
|
|
310
|
+
): ThemeColorButtonMode_v2 {
|
|
312
311
|
return {
|
|
313
312
|
default: renderThemeColorButtonStates(value.default, options),
|
|
314
313
|
primary: renderThemeColorButtonStates(value.primary, options),
|
|
@@ -319,13 +318,13 @@ function renderThemeColorButtonTones(
|
|
|
319
318
|
}
|
|
320
319
|
|
|
321
320
|
function renderThemeColorButtonStates(
|
|
322
|
-
value:
|
|
321
|
+
value: ThemeColorButtonTone_v2,
|
|
323
322
|
options: {
|
|
324
323
|
baseBg: string
|
|
325
324
|
blendMode: ThemeColorBlendModeKey
|
|
326
325
|
colorPalette: ThemeColorPalette
|
|
327
326
|
},
|
|
328
|
-
):
|
|
327
|
+
): ThemeColorButtonTone_v2 {
|
|
329
328
|
return {
|
|
330
329
|
enabled: renderThemeColorState(value.enabled, options),
|
|
331
330
|
hovered: renderThemeColorState(value.hovered, options),
|
|
@@ -366,7 +365,7 @@ function renderThemeColorState(
|
|
|
366
365
|
fg: renderColorValue(value.accent.fg, colorOptions),
|
|
367
366
|
},
|
|
368
367
|
avatar: renderThemeColorAvatar(value.avatar, {baseBg, colorPalette, blendMode}),
|
|
369
|
-
badge: renderThemeColorBadge(value.badge, {baseBg, colorPalette, blendMode}),
|
|
368
|
+
badge: renderThemeColorBadge(value.badge, {baseBg: bg, colorPalette, blendMode}),
|
|
370
369
|
bg,
|
|
371
370
|
border: renderColorValue(value.border, colorOptions),
|
|
372
371
|
code: {
|
|
@@ -409,13 +408,13 @@ function renderThemeColorInput(
|
|
|
409
408
|
}
|
|
410
409
|
|
|
411
410
|
function renderInputStatesColorTheme(
|
|
412
|
-
value:
|
|
411
|
+
value: ThemeColorInputMode_v2,
|
|
413
412
|
options: {
|
|
414
413
|
baseBg: string
|
|
415
414
|
blendMode: ThemeColorBlendModeKey
|
|
416
415
|
colorPalette: ThemeColorPalette
|
|
417
416
|
},
|
|
418
|
-
):
|
|
417
|
+
): ThemeColorInputMode_v2 {
|
|
419
418
|
return {
|
|
420
419
|
enabled: renderInputStateColorTheme(value.enabled, options),
|
|
421
420
|
hovered: renderInputStateColorTheme(value.hovered, options),
|
|
@@ -468,13 +467,13 @@ function renderThemeColorSelectable(
|
|
|
468
467
|
}
|
|
469
468
|
|
|
470
469
|
function renderThemeColorSelectableStates(
|
|
471
|
-
value:
|
|
470
|
+
value: ThemeColorSelectableTone_v2,
|
|
472
471
|
options: {
|
|
473
472
|
baseBg: string
|
|
474
473
|
blendMode: ThemeColorBlendModeKey
|
|
475
474
|
colorPalette: ThemeColorPalette
|
|
476
475
|
},
|
|
477
|
-
):
|
|
476
|
+
): ThemeColorSelectableTone_v2 {
|
|
478
477
|
return {
|
|
479
478
|
enabled: renderThemeColorState(value.enabled, options),
|
|
480
479
|
hovered: renderThemeColorState(value.hovered, options),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ColorTint as ColorPaletteValue} from '@sanity/color'
|
|
2
2
|
import {ThemeColorPalette, parseTokenValue} from '../config'
|
|
3
3
|
import {ThemeColorBlendModeKey} from '../system'
|
|
4
|
-
import {rgba} from './lib/color-fns'
|
|
4
|
+
import {hexToRgb, mix, rgbToHex, rgba} from './lib/color-fns'
|
|
5
5
|
import {mixThemeColor} from './mixThemeColor'
|
|
6
6
|
|
|
7
7
|
export interface RenderColorValueOptions {
|
|
@@ -53,9 +53,16 @@ export function renderColorValue(str: string, options: RenderColorValueOptions):
|
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
55
|
hex = mixThemeColor(hex, mixOptions)
|
|
56
|
+
|
|
57
|
+
if (bg && node.mix !== undefined) {
|
|
58
|
+
const from = hexToRgb(bg)
|
|
59
|
+
const to = hexToRgb(hex)
|
|
60
|
+
|
|
61
|
+
hex = rgbToHex(mix(from, to, node.mix))
|
|
62
|
+
}
|
|
56
63
|
} catch (err) {
|
|
57
64
|
// eslint-disable-next-line no-console
|
|
58
|
-
console.
|
|
65
|
+
console.warn('could not blend', hex, mixOptions)
|
|
59
66
|
throw err
|
|
60
67
|
}
|
|
61
68
|
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ThemeColorBlendModeKey,
|
|
10
10
|
} from '../system'
|
|
11
11
|
|
|
12
|
-
/** @
|
|
12
|
+
/** @public */
|
|
13
13
|
export const COLOR_CONFIG_STATE_KEYS = [
|
|
14
14
|
'_hue',
|
|
15
15
|
'bg',
|
|
@@ -30,7 +30,7 @@ export const COLOR_CONFIG_STATE_KEYS = [
|
|
|
30
30
|
/** @public */
|
|
31
31
|
export type ColorConfigStateKey = (typeof COLOR_CONFIG_STATE_KEYS)[number]
|
|
32
32
|
|
|
33
|
-
/** @
|
|
33
|
+
/** @public */
|
|
34
34
|
export const COLOR_CONFIG_CARD_KEYS = [
|
|
35
35
|
...COLOR_CONFIG_STATE_KEYS,
|
|
36
36
|
'_hue',
|
|
@@ -47,7 +47,7 @@ export const COLOR_CONFIG_CARD_KEYS = [
|
|
|
47
47
|
/** @public */
|
|
48
48
|
export type ColorConfigCardKey = (typeof COLOR_CONFIG_CARD_KEYS)[number]
|
|
49
49
|
|
|
50
|
-
/** @
|
|
50
|
+
/** @public */
|
|
51
51
|
export const COLOR_CONFIG_BLEND_KEYS = ['_blend'] as const
|
|
52
52
|
|
|
53
53
|
/** @public */
|
|
@@ -63,11 +63,13 @@ export type ColorConfigValue =
|
|
|
63
63
|
| `black/${ColorConfigOpacityValue}`
|
|
64
64
|
| `white/${ColorConfigOpacityValue}`
|
|
65
65
|
| `${ColorHueKey}`
|
|
66
|
+
| `${ColorHueKey} ${number}%`
|
|
66
67
|
| `${ColorHueKey}/${ColorTintKey}`
|
|
68
|
+
| `${ColorHueKey}/${ColorTintKey} ${number}%`
|
|
67
69
|
| `${ColorHueKey}/${ColorTintKey}/${ColorConfigOpacityValue}`
|
|
68
70
|
| `${ColorTintKey}`
|
|
71
|
+
| `${ColorTintKey} ${number}%`
|
|
69
72
|
| `${ColorTintKey}/${ColorConfigOpacityValue}`
|
|
70
|
-
| ThemeColorBlendModeKey
|
|
71
73
|
|
|
72
74
|
/** @public */
|
|
73
75
|
export type ThemeColorTokenValue = [ColorConfigValue, ColorConfigValue]
|
|
@@ -75,37 +77,37 @@ export type ThemeColorTokenValue = [ColorConfigValue, ColorConfigValue]
|
|
|
75
77
|
/** @public */
|
|
76
78
|
export type ColorBlendModeTokenValue = [ThemeColorBlendModeKey, ThemeColorBlendModeKey]
|
|
77
79
|
|
|
78
|
-
/** @
|
|
80
|
+
/** @public */
|
|
79
81
|
export const COLOR_CONFIG_AVATAR_COLORS = ['*', ...THEME_COLOR_AVATAR_COLORS] as const
|
|
80
82
|
|
|
81
83
|
/** @public */
|
|
82
84
|
export type ColorConfigAvatarColor = (typeof COLOR_CONFIG_AVATAR_COLORS)[number]
|
|
83
85
|
|
|
84
|
-
/** @
|
|
86
|
+
/** @public */
|
|
85
87
|
export const COLOR_CONFIG_CARD_TONES = ['*', ...THEME_COLOR_CARD_TONES] as const
|
|
86
88
|
|
|
87
89
|
/** @public */
|
|
88
90
|
export type ColorConfigCardTone = (typeof COLOR_CONFIG_CARD_TONES)[number]
|
|
89
91
|
|
|
90
|
-
/** @
|
|
92
|
+
/** @public */
|
|
91
93
|
export const COLOR_CONFIG_STATE_TONES = ['*', ...THEME_COLOR_STATE_TONES] as const
|
|
92
94
|
|
|
93
95
|
/** @public */
|
|
94
96
|
export type ColorConfigStateTone = (typeof COLOR_CONFIG_STATE_TONES)[number]
|
|
95
97
|
|
|
96
|
-
/** @
|
|
98
|
+
/** @public */
|
|
97
99
|
export const COLOR_CONFIG_STATES = ['*', ...THEME_COLOR_STATES] as const
|
|
98
100
|
|
|
99
101
|
/** @public */
|
|
100
102
|
export type ColorConfigState = (typeof COLOR_CONFIG_STATES)[number]
|
|
101
103
|
|
|
102
|
-
/** @
|
|
104
|
+
/** @public */
|
|
103
105
|
export const COLOR_CONFIG_INPUT_MODES = ['*', ...THEME_COLOR_INPUT_MODES] as const
|
|
104
106
|
|
|
105
107
|
/** @public */
|
|
106
108
|
export type ColorConfigInputMode = (typeof COLOR_CONFIG_INPUT_MODES)[number]
|
|
107
109
|
|
|
108
|
-
/** @
|
|
110
|
+
/** @public */
|
|
109
111
|
export const COLOR_CONFIG_INPUT_STATES = ['*', ...THEME_COLOR_INPUT_STATES] as const
|
|
110
112
|
|
|
111
113
|
/** @public */
|