@sanity/ui 2.0.0-beta.1 → 2.0.0-beta.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/LICENSE +1 -1
- package/README.md +6 -3
- package/dist/index.cjs.mjs +11 -36
- package/dist/index.d.ts +248 -268
- package/dist/index.esm.js +494 -354
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +503 -567
- package/dist/index.js.map +1 -1
- package/dist/theme.cjs.mjs +1 -1
- package/dist/theme.d.ts +81 -114
- package/dist/theme.esm.js +299 -252
- package/dist/theme.esm.js.map +1 -1
- package/dist/theme.js +299 -252
- package/dist/theme.js.map +1 -1
- package/package.json +6 -3
- package/src/core/__workshop__/constants.ts +3 -2
- package/src/core/_compat.ts +236 -87
- package/src/core/components/menu/__workshop__/selectedItem.tsx +7 -2
- package/src/core/components/menu/menuButton.tsx +12 -1
- package/src/core/constants.ts +18 -0
- package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +6 -3
- package/src/core/middleware/origin.ts +47 -0
- package/src/core/primitives/avatar/__workshop__/asButton.tsx +1 -1
- package/src/core/primitives/avatar/__workshop__/stack.tsx +1 -1
- package/src/core/primitives/avatar/avatar.tsx +14 -4
- package/src/core/primitives/avatar/avatarCounter.tsx +16 -5
- package/src/core/primitives/avatar/avatarStack.tsx +2 -2
- package/src/core/primitives/badge/badge.tsx +1 -3
- 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 +26 -15
- package/src/core/primitives/select/select.tsx +1 -1
- package/src/core/primitives/switch/styles.ts +6 -1
- package/src/core/primitives/tooltip/tooltip.tsx +47 -57
- package/src/core/primitives/tooltip/tooltipCard.tsx +104 -0
- package/src/core/styles/card/_cardColorStyle.ts +2 -0
- 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 +159 -0
- package/src/core/theme/__workshop__/index.ts +5 -0
- package/src/core/theme/theme.test.tsx +2 -2
- package/src/core/types/avatar.ts +1 -1
- 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.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 +219 -211
- package/src/theme/defaults/config.ts +2 -1
- package/src/theme/defaults/fonts.ts +13 -5
- 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 +2 -0
- 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/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/themeColor_v0_v2.ts +2 -2
- package/src/theme/versioning/v2_v0.ts +2 -2
- package/src/theme/build/colorToken.ts +0 -39
|
@@ -159,6 +159,7 @@ export const Root = styled.div((props) => {
|
|
|
159
159
|
--link-fg: var(--card-enabled-link-fg);
|
|
160
160
|
--code-bg: var(--card-enabled-code-bg);
|
|
161
161
|
--code-fg: var(--card-enabled-code-fg);
|
|
162
|
+
--kbd-bg: var(--card-enabled-kbd-bg);
|
|
162
163
|
--skeleton-from: var(--card-enabled-skeleton-from);
|
|
163
164
|
--skeleton-to: var(--card-enabled-skeleton-to);
|
|
164
165
|
|
|
@@ -322,15 +323,15 @@ export const Root = styled.div((props) => {
|
|
|
322
323
|
color: var(--icon);
|
|
323
324
|
}
|
|
324
325
|
|
|
325
|
-
.muted
|
|
326
|
+
.muted {
|
|
326
327
|
color: var(--muted-fg);
|
|
327
328
|
}
|
|
328
329
|
|
|
329
|
-
.accent
|
|
330
|
+
.accent {
|
|
330
331
|
color: var(--accent-fg);
|
|
331
332
|
}
|
|
332
333
|
|
|
333
|
-
.link
|
|
334
|
+
.link {
|
|
334
335
|
color: var(--link-fg);
|
|
335
336
|
}
|
|
336
337
|
|
|
@@ -339,6 +340,22 @@ export const Root = styled.div((props) => {
|
|
|
339
340
|
color: var(--code-fg);
|
|
340
341
|
}
|
|
341
342
|
|
|
343
|
+
.kbd {
|
|
344
|
+
background-color: var(--kbd-bg);
|
|
345
|
+
color: var(--kbd-fg);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.badge {
|
|
349
|
+
background-color: var(--badge-bg);
|
|
350
|
+
color: var(--badge-fg);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.badge--default {
|
|
354
|
+
--badge-bg: var(--badge-default-bg);
|
|
355
|
+
--badge-fg: var(--badge-default-fg);
|
|
356
|
+
--badge-border: var(--badge-default-border);
|
|
357
|
+
}
|
|
358
|
+
|
|
342
359
|
.skeleton-from {
|
|
343
360
|
color: var(--skeleton-from);
|
|
344
361
|
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
ThemeColorButtonTone_v2,
|
|
5
5
|
ThemeColorCard_v2,
|
|
6
|
-
|
|
6
|
+
ThemeColorInputMode_v2,
|
|
7
7
|
ThemeColorState_v2,
|
|
8
8
|
} from '@sanity/ui/theme'
|
|
9
9
|
import {
|
|
10
|
-
THEME_COLOR_CARD_TONES,
|
|
11
10
|
THEME_COLOR_BUTTON_MODES,
|
|
11
|
+
THEME_COLOR_CARD_TONES,
|
|
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 {buildTheme} from '@sanity/ui/theme'
|
|
18
18
|
import {ReactElement} from 'react'
|
|
19
19
|
import {rem} from '../../../styles'
|
|
20
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 = buildTheme()
|
|
25
25
|
|
|
26
26
|
export default function BuildStory(): ReactElement {
|
|
27
27
|
return (
|
|
@@ -268,7 +268,7 @@ function StatePreview(props: {theme: ThemeColorState_v2}) {
|
|
|
268
268
|
)
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
function ButtonPreview(props: {theme:
|
|
271
|
+
function ButtonPreview(props: {theme: ThemeColorButtonTone_v2}) {
|
|
272
272
|
const {theme: button} = props
|
|
273
273
|
|
|
274
274
|
return (
|
|
@@ -289,18 +289,24 @@ function ButtonPreview(props: {theme: ThemeColorButtonStates_v2}) {
|
|
|
289
289
|
<div className="icon" style={{flex: 'none'}}>
|
|
290
290
|
©
|
|
291
291
|
</div>
|
|
292
|
-
<div className="muted
|
|
292
|
+
<div className="muted" style={{flex: 'none'}}>
|
|
293
293
|
m
|
|
294
294
|
</div>
|
|
295
|
-
<div className="accent
|
|
295
|
+
<div className="accent" style={{flex: 'none'}}>
|
|
296
296
|
a
|
|
297
297
|
</div>
|
|
298
|
-
<div className="link
|
|
298
|
+
<div className="link" style={{flex: 'none'}}>
|
|
299
299
|
l
|
|
300
300
|
</div>
|
|
301
301
|
<div className="code" style={{flex: 'none'}}>
|
|
302
302
|
c
|
|
303
303
|
</div>
|
|
304
|
+
<div className="kbd" style={{flex: 'none'}}>
|
|
305
|
+
k
|
|
306
|
+
</div>
|
|
307
|
+
<div className="badge badge--default" style={{flex: 'none'}}>
|
|
308
|
+
b
|
|
309
|
+
</div>
|
|
304
310
|
<div style={{flex: 'none'}}>
|
|
305
311
|
<CheckeredBackground />
|
|
306
312
|
</div>
|
|
@@ -424,7 +430,7 @@ function Skeleton() {
|
|
|
424
430
|
)
|
|
425
431
|
}
|
|
426
432
|
|
|
427
|
-
function InputPreview(props: {mode: ThemeColorInputModeKey; theme:
|
|
433
|
+
function InputPreview(props: {mode: ThemeColorInputModeKey; theme: ThemeColorInputMode_v2}) {
|
|
428
434
|
const {mode, theme: input} = props
|
|
429
435
|
|
|
430
436
|
return (
|
|
@@ -10,14 +10,14 @@ import {
|
|
|
10
10
|
useRootTheme,
|
|
11
11
|
} from '@sanity/ui'
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
ThemeColorButtonMode_v2,
|
|
14
|
+
ThemeColorButtonTone_v2,
|
|
15
15
|
ThemeColorButton_v2,
|
|
16
|
+
ThemeColorCard_v2,
|
|
16
17
|
ThemeColorScheme_v2,
|
|
17
|
-
|
|
18
|
+
ThemeColorSelectableTone_v2,
|
|
18
19
|
ThemeColorSelectable_v2,
|
|
19
20
|
ThemeColorState_v2,
|
|
20
|
-
ThemeColorCard_v2,
|
|
21
21
|
getContrastRatio,
|
|
22
22
|
mix,
|
|
23
23
|
parseColor,
|
|
@@ -202,7 +202,7 @@ function ColorButton(props: {color: ThemeColorButton_v2}) {
|
|
|
202
202
|
)
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
function ColorButtonMode(props: {color:
|
|
205
|
+
function ColorButtonMode(props: {color: ThemeColorButtonMode_v2}) {
|
|
206
206
|
const {color} = props
|
|
207
207
|
|
|
208
208
|
return (
|
|
@@ -243,7 +243,7 @@ function ColorButtonMode(props: {color: ThemeColorButtonTones_v2}) {
|
|
|
243
243
|
)
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
function ColorGenericStates(props: {color:
|
|
246
|
+
function ColorGenericStates(props: {color: ThemeColorButtonTone_v2}) {
|
|
247
247
|
const {color} = props
|
|
248
248
|
|
|
249
249
|
return (
|
|
@@ -335,7 +335,7 @@ function ColorSelectable(props: {color: ThemeColorSelectable_v2}) {
|
|
|
335
335
|
)
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
function ColorSelectableTone(props: {color:
|
|
338
|
+
function ColorSelectableTone(props: {color: ThemeColorSelectableTone_v2}) {
|
|
339
339
|
const {color} = props
|
|
340
340
|
|
|
341
341
|
return (
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
THEME_COLOR_BUTTON_MODES,
|
|
3
|
+
THEME_COLOR_CARD_TONES,
|
|
4
|
+
THEME_COLOR_SCHEMES,
|
|
5
|
+
THEME_COLOR_STATES,
|
|
6
|
+
THEME_COLOR_STATE_TONES,
|
|
7
|
+
ThemeColorCard_v2,
|
|
8
|
+
ThemeColorScheme_v2,
|
|
9
|
+
ThemeColorState_v2,
|
|
10
|
+
} from '@sanity/ui/theme'
|
|
11
|
+
import {CSSProperties} from 'react'
|
|
12
|
+
import {Badge, Box, Flex, KBD, Stack, Text} from '../../../primitives'
|
|
13
|
+
import {useRootTheme} from '../../useRootTheme'
|
|
14
|
+
|
|
15
|
+
export default function DebugStory() {
|
|
16
|
+
const {color} = useRootTheme().theme.v2!
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Flex>
|
|
20
|
+
{THEME_COLOR_SCHEMES.map((scheme) => (
|
|
21
|
+
<DebugScheme key={scheme} scheme={color[scheme]} />
|
|
22
|
+
))}
|
|
23
|
+
</Flex>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function DebugScheme(props: {scheme: ThemeColorScheme_v2}) {
|
|
28
|
+
const {scheme} = props
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Box flex={1} style={{backgroundColor: scheme.default.bg}}>
|
|
32
|
+
{THEME_COLOR_CARD_TONES.map((tone) => (
|
|
33
|
+
<DebugCard card={scheme[tone]} key={tone} />
|
|
34
|
+
))}
|
|
35
|
+
</Box>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function DebugCard(props: {card: ThemeColorCard_v2}) {
|
|
40
|
+
const {card} = props
|
|
41
|
+
|
|
42
|
+
// card.avatar
|
|
43
|
+
// card.backdrop
|
|
44
|
+
// card.badge
|
|
45
|
+
// card.button
|
|
46
|
+
// card.focusRing
|
|
47
|
+
// card.icon
|
|
48
|
+
// card.input
|
|
49
|
+
// card.kbd
|
|
50
|
+
// card.link
|
|
51
|
+
// card.selectable
|
|
52
|
+
// card.shadow
|
|
53
|
+
// card.skeleton
|
|
54
|
+
// card.syntax
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Box style={getStateVars(card)}>
|
|
58
|
+
<DebugState />
|
|
59
|
+
<Stack padding={2} space={1}>
|
|
60
|
+
{THEME_COLOR_BUTTON_MODES.map((mode) => (
|
|
61
|
+
<Stack key={mode} space={1}>
|
|
62
|
+
{THEME_COLOR_STATE_TONES.map((stateTone) => (
|
|
63
|
+
<Flex key={stateTone} gap={1}>
|
|
64
|
+
{/* {mode} */}
|
|
65
|
+
{THEME_COLOR_STATES.map((state) => (
|
|
66
|
+
<Box
|
|
67
|
+
flex={1}
|
|
68
|
+
key={state}
|
|
69
|
+
style={getStateVars(card.button[mode][stateTone][state])}
|
|
70
|
+
>
|
|
71
|
+
<DebugState />
|
|
72
|
+
{/* {state} */}
|
|
73
|
+
</Box>
|
|
74
|
+
))}
|
|
75
|
+
</Flex>
|
|
76
|
+
))}
|
|
77
|
+
</Stack>
|
|
78
|
+
))}
|
|
79
|
+
</Stack>
|
|
80
|
+
</Box>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function DebugState() {
|
|
85
|
+
return (
|
|
86
|
+
<Stack
|
|
87
|
+
overflow="auto"
|
|
88
|
+
padding={4}
|
|
89
|
+
space={3}
|
|
90
|
+
style={{border: '1px solid var(--card-border-color)'}}
|
|
91
|
+
>
|
|
92
|
+
<Text size={1}>Text</Text>
|
|
93
|
+
<Text muted size={1}>
|
|
94
|
+
Muted
|
|
95
|
+
</Text>
|
|
96
|
+
<Text accent size={1}>
|
|
97
|
+
Accent
|
|
98
|
+
</Text>
|
|
99
|
+
<Text size={1}>
|
|
100
|
+
<code>Code</code>
|
|
101
|
+
</Text>
|
|
102
|
+
<div>
|
|
103
|
+
<KBD>Cmd</KBD>
|
|
104
|
+
</div>
|
|
105
|
+
<Flex gap={1}>
|
|
106
|
+
{THEME_COLOR_STATE_TONES.map((stateTone) => (
|
|
107
|
+
<Box flex="none" key={stateTone}>
|
|
108
|
+
<Badge tone={stateTone}>{stateTone}</Badge>
|
|
109
|
+
</Box>
|
|
110
|
+
))}
|
|
111
|
+
</Flex>
|
|
112
|
+
<div style={{borderBottom: '1px solid var(--card-border-color)'}} />
|
|
113
|
+
</Stack>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function getStateVars(state: ThemeColorState_v2) {
|
|
118
|
+
return {
|
|
119
|
+
'--card-bg-color': state.bg,
|
|
120
|
+
'--card-border-color': state.border,
|
|
121
|
+
'--card-fg-color': state.fg,
|
|
122
|
+
'--card-accent-fg-color': state.accent.fg,
|
|
123
|
+
'--card-muted-fg-color': state.muted.fg,
|
|
124
|
+
'--card-code-bg-color': state.code.bg,
|
|
125
|
+
'--card-code-fg-color': state.code.fg,
|
|
126
|
+
|
|
127
|
+
'--card-kbd-bg-color': state.kbd.bg,
|
|
128
|
+
'--card-kbd-border-color': state.kbd.border,
|
|
129
|
+
'--card-kbd-fg-color': state.kbd.fg,
|
|
130
|
+
|
|
131
|
+
'--card-badge-default-bg-color': state.badge.default.bg,
|
|
132
|
+
'--card-badge-default-dot-color': state.badge.default.dot,
|
|
133
|
+
'--card-badge-default-fg-color': state.badge.default.fg,
|
|
134
|
+
'--card-badge-default-icon-color': state.badge.default.icon,
|
|
135
|
+
|
|
136
|
+
'--card-badge-primary-bg-color': state.badge.primary.bg,
|
|
137
|
+
'--card-badge-primary-dot-color': state.badge.primary.dot,
|
|
138
|
+
'--card-badge-primary-fg-color': state.badge.primary.fg,
|
|
139
|
+
'--card-badge-primary-icon-color': state.badge.primary.icon,
|
|
140
|
+
|
|
141
|
+
'--card-badge-positive-bg-color': state.badge.positive.bg,
|
|
142
|
+
'--card-badge-positive-dot-color': state.badge.positive.dot,
|
|
143
|
+
'--card-badge-positive-fg-color': state.badge.positive.fg,
|
|
144
|
+
'--card-badge-positive-icon-color': state.badge.positive.icon,
|
|
145
|
+
|
|
146
|
+
'--card-badge-caution-bg-color': state.badge.caution.bg,
|
|
147
|
+
'--card-badge-caution-dot-color': state.badge.caution.dot,
|
|
148
|
+
'--card-badge-caution-fg-color': state.badge.caution.fg,
|
|
149
|
+
'--card-badge-caution-icon-color': state.badge.caution.icon,
|
|
150
|
+
|
|
151
|
+
'--card-badge-critical-bg-color': state.badge.critical.bg,
|
|
152
|
+
'--card-badge-critical-dot-color': state.badge.critical.dot,
|
|
153
|
+
'--card-badge-critical-fg-color': state.badge.critical.fg,
|
|
154
|
+
'--card-badge-critical-icon-color': state.badge.critical.icon,
|
|
155
|
+
|
|
156
|
+
backgroundColor: 'var(--card-bg-color)',
|
|
157
|
+
color: 'var(--card-fg-color)',
|
|
158
|
+
} as CSSProperties
|
|
159
|
+
}
|
|
@@ -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/avatar.ts
CHANGED
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 = {},
|
|
@@ -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
|
+
}
|