@sanity/ui 2.0.0-alpha.14 → 2.0.0-alpha.16
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.d.ts +22 -0
- package/dist/index.esm.js +256 -142
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +256 -142
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/dialog/dialog.tsx +10 -10
- package/src/theme/_internal/__workshop__/build/story.tsx +141 -31
- package/src/theme/_internal/build/buildTheme.ts +6 -5
- package/src/theme/_internal/build/colorTheme/buildColorTheme.ts +49 -107
- package/src/theme/_internal/build/colorTheme/renderColorTheme.ts +51 -35
- package/src/theme/_internal/build/colorTheme/resolveColorTokens.ts +121 -0
- package/src/theme/_internal/build/defaults/colorTokens.ts +28 -5
- package/src/theme/_internal/build/helpers.ts +5 -4
- package/src/theme/_internal/config/types.ts +11 -0
- package/src/theme/_internal/types.ts +19 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseColorTokens,
|
|
3
|
+
ButtonColorTokens,
|
|
4
|
+
ButtonModeColorTokens,
|
|
5
|
+
ColorConfigStateTone,
|
|
6
|
+
ColorTokens,
|
|
7
|
+
StateColorTokens,
|
|
8
|
+
} from '../../config'
|
|
9
|
+
import {
|
|
10
|
+
COLOR_BASE_TONES,
|
|
11
|
+
COLOR_BUTTON_MODES,
|
|
12
|
+
COLOR_STATES,
|
|
13
|
+
COLOR_STATE_TONES,
|
|
14
|
+
} from '../../constants'
|
|
15
|
+
import {ColorBaseTone, ColorButtonMode, ColorState, ColorStateTone} from '../../types'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Convert a tree of color tokens from a sparse format to a dense format.
|
|
19
|
+
*/
|
|
20
|
+
export function resolveColorTokens(sparseTokens: ColorTokens): ColorTokens {
|
|
21
|
+
const denseTokens: ColorTokens = {...sparseTokens}
|
|
22
|
+
|
|
23
|
+
// base tones
|
|
24
|
+
for (const tone of COLOR_BASE_TONES) {
|
|
25
|
+
denseTokens[tone] = resolveBaseColorTones(sparseTokens, tone)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// button
|
|
29
|
+
denseTokens.button = resolveButtonColorTokens(sparseTokens)
|
|
30
|
+
|
|
31
|
+
return denseTokens
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function resolveBaseColorTones(sparseTokens: ColorTokens, tone: ColorBaseTone): BaseColorTokens {
|
|
35
|
+
const spec0 = sparseTokens?.[tone]
|
|
36
|
+
const spec1 = sparseTokens?.['*']
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
...spec1,
|
|
40
|
+
...spec0,
|
|
41
|
+
shadow: {...spec1?.shadow, ...spec0?.shadow},
|
|
42
|
+
skeleton: {...spec1?.skeleton, ...spec0?.skeleton},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function resolveButtonColorTokens(
|
|
47
|
+
sparseTokens: ColorTokens,
|
|
48
|
+
): Partial<Record<ColorConfigStateTone, ButtonColorTokens>> {
|
|
49
|
+
const tokens: Partial<Record<ColorConfigStateTone, ButtonColorTokens>> = {}
|
|
50
|
+
|
|
51
|
+
for (const tone of COLOR_STATE_TONES) {
|
|
52
|
+
tokens[tone] = resolveButtonToneColorTokens(sparseTokens, tone)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return tokens
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function resolveButtonToneColorTokens(
|
|
59
|
+
sparseTokens: ColorTokens,
|
|
60
|
+
tone: ColorStateTone,
|
|
61
|
+
): ButtonColorTokens {
|
|
62
|
+
const tokens: ButtonColorTokens = {
|
|
63
|
+
...sparseTokens.button?.[tone],
|
|
64
|
+
...sparseTokens.button?.['*'],
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (const mode of COLOR_BUTTON_MODES) {
|
|
68
|
+
tokens[mode] = resolveButtonModeColorTokens(sparseTokens, tone, mode)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return tokens
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveButtonModeColorTokens(
|
|
75
|
+
sparseTokens: ColorTokens,
|
|
76
|
+
tone: ColorStateTone,
|
|
77
|
+
mode: ColorButtonMode,
|
|
78
|
+
): ButtonModeColorTokens {
|
|
79
|
+
const spec0 = sparseTokens.button?.[tone]?.[mode]
|
|
80
|
+
const spec1 = sparseTokens.button?.['*']?.[mode]
|
|
81
|
+
const tokens = {...spec1, ...spec0}
|
|
82
|
+
|
|
83
|
+
for (const state of COLOR_STATES) {
|
|
84
|
+
tokens[state] = resolveButtonStateColorTokens(sparseTokens, tone, mode, state)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return tokens
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function resolveButtonStateColorTokens(
|
|
91
|
+
tokens: ColorTokens,
|
|
92
|
+
tone: ColorStateTone,
|
|
93
|
+
mode: ColorButtonMode,
|
|
94
|
+
state: ColorState,
|
|
95
|
+
): StateColorTokens {
|
|
96
|
+
const spec0 = tokens?.button?.[tone]?.[mode]?.[state]
|
|
97
|
+
const spec1 = tokens?.button?.[tone]?.[mode]?.['*']
|
|
98
|
+
const spec2 = tokens?.button?.['*']?.[mode]?.[state]
|
|
99
|
+
const spec3 = tokens?.button?.['*']?.[mode]?.['*']
|
|
100
|
+
|
|
101
|
+
const hue =
|
|
102
|
+
spec0?._hue ||
|
|
103
|
+
spec1?._hue ||
|
|
104
|
+
spec2?._hue ||
|
|
105
|
+
spec3?._hue ||
|
|
106
|
+
tokens?.button?.[tone]?._hue ||
|
|
107
|
+
tokens?.[tone]?._hue
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
...spec3,
|
|
111
|
+
...spec2,
|
|
112
|
+
...spec1,
|
|
113
|
+
...spec0,
|
|
114
|
+
_hue: hue,
|
|
115
|
+
muted: {...spec3?.muted, ...spec2?.muted, ...spec1?.muted, ...spec0?.muted},
|
|
116
|
+
accent: {...spec3?.accent, ...spec2?.accent, ...spec1?.accent, ...spec0?.accent},
|
|
117
|
+
link: {...spec3?.link, ...spec2?.link, ...spec1?.link, ...spec0?.link},
|
|
118
|
+
code: {...spec3?.code, ...spec2?.code, ...spec1?.code, ...spec0?.code},
|
|
119
|
+
skeleton: {...spec3?.skeleton, ...spec2?.skeleton, ...spec1?.skeleton, ...spec0?.skeleton},
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -6,6 +6,17 @@ export const defaultColorTokens: ColorTokens = {
|
|
|
6
6
|
bg: ['50', '950'],
|
|
7
7
|
fg: ['800', '200'],
|
|
8
8
|
border: ['200', '800'],
|
|
9
|
+
focusRing: ['cyan/500', 'cyan/500'],
|
|
10
|
+
shadow: {
|
|
11
|
+
outline: ['500/0.25', '400/0.3'],
|
|
12
|
+
umbra: ['500/0.1', 'black/0.4'],
|
|
13
|
+
penumbra: ['500/0.07', 'black/0.28'],
|
|
14
|
+
ambient: ['500/0.06', 'black/0.24'],
|
|
15
|
+
},
|
|
16
|
+
skeleton: {
|
|
17
|
+
from: ['100', '900'],
|
|
18
|
+
to: ['100/0.5', '900/0.5'],
|
|
19
|
+
},
|
|
9
20
|
},
|
|
10
21
|
transparent: {
|
|
11
22
|
bg: ['50', 'black'],
|
|
@@ -33,7 +44,11 @@ export const defaultColorTokens: ColorTokens = {
|
|
|
33
44
|
'*': {
|
|
34
45
|
_blend: ['screen', 'multiply'],
|
|
35
46
|
bg: ['500', '400'],
|
|
47
|
+
bg2: ['950', '50'],
|
|
36
48
|
border: ['500/0', '400/0'],
|
|
49
|
+
muted: {
|
|
50
|
+
fg: ['200', '700'],
|
|
51
|
+
},
|
|
37
52
|
},
|
|
38
53
|
hovered: {
|
|
39
54
|
bg: ['600', '300'],
|
|
@@ -47,15 +62,19 @@ export const defaultColorTokens: ColorTokens = {
|
|
|
47
62
|
},
|
|
48
63
|
disabled: {
|
|
49
64
|
_hue: 'gray',
|
|
50
|
-
bg: ['
|
|
65
|
+
bg: ['200', '900'],
|
|
51
66
|
},
|
|
52
67
|
},
|
|
53
68
|
ghost: {
|
|
54
69
|
'*': {
|
|
55
70
|
_blend: ['multiply', 'screen'],
|
|
56
71
|
bg: ['white', 'black'],
|
|
72
|
+
bg2: ['50', '950'],
|
|
57
73
|
fg: ['600', '400'],
|
|
58
74
|
border: ['200', '800'],
|
|
75
|
+
muted: {
|
|
76
|
+
fg: ['600/0.6', '400/0.6'],
|
|
77
|
+
},
|
|
59
78
|
},
|
|
60
79
|
hovered: {
|
|
61
80
|
bg: ['50', '950'],
|
|
@@ -71,16 +90,20 @@ export const defaultColorTokens: ColorTokens = {
|
|
|
71
90
|
},
|
|
72
91
|
disabled: {
|
|
73
92
|
_hue: 'gray',
|
|
74
|
-
fg: ['
|
|
75
|
-
border: ['100', '
|
|
93
|
+
fg: ['200', '900'],
|
|
94
|
+
border: ['100', '950'],
|
|
76
95
|
},
|
|
77
96
|
},
|
|
78
97
|
bleed: {
|
|
79
98
|
'*': {
|
|
80
99
|
_blend: ['multiply', 'screen'],
|
|
81
100
|
bg: ['white', 'black'],
|
|
101
|
+
bg2: ['50', '950'],
|
|
82
102
|
fg: ['600', '400'],
|
|
83
103
|
border: ['white/0', 'black/0'],
|
|
104
|
+
muted: {
|
|
105
|
+
fg: ['600/0.6', '400/0.6'],
|
|
106
|
+
},
|
|
84
107
|
},
|
|
85
108
|
hovered: {
|
|
86
109
|
bg: ['50', '950'],
|
|
@@ -96,7 +119,7 @@ export const defaultColorTokens: ColorTokens = {
|
|
|
96
119
|
},
|
|
97
120
|
disabled: {
|
|
98
121
|
_hue: 'gray',
|
|
99
|
-
fg: ['
|
|
122
|
+
fg: ['200', '900'],
|
|
100
123
|
},
|
|
101
124
|
},
|
|
102
125
|
},
|
|
@@ -116,7 +139,7 @@ export const defaultColorTokens: ColorTokens = {
|
|
|
116
139
|
},
|
|
117
140
|
disabled: {
|
|
118
141
|
_hue: 'gray',
|
|
119
|
-
bg: ['
|
|
142
|
+
bg: ['200', '900'],
|
|
120
143
|
},
|
|
121
144
|
},
|
|
122
145
|
},
|
|
@@ -8,12 +8,13 @@ import {
|
|
|
8
8
|
import {ColorTokenValue, parseTokenValue, TokenColorValueNode} from '../config'
|
|
9
9
|
import {ColorHueValue} from '../types'
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export interface ColorTokenContext {
|
|
12
12
|
hue: ColorHueValue
|
|
13
13
|
scheme: 'light' | 'dark'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function resolveColorTokenValue(context: ColorTokenContext, value: ColorTokenValue): string {
|
|
17
|
+
const {hue, scheme} = context
|
|
17
18
|
const node = parseTokenValue(value[scheme === 'light' ? 0 : 1])
|
|
18
19
|
|
|
19
20
|
if (!node || node.type !== 'color') {
|
|
@@ -21,6 +21,17 @@ export interface BaseColorTokens {
|
|
|
21
21
|
bg?: ColorTokenValue
|
|
22
22
|
fg?: ColorTokenValue
|
|
23
23
|
border?: ColorTokenValue
|
|
24
|
+
focusRing?: ColorTokenValue
|
|
25
|
+
shadow?: {
|
|
26
|
+
outline?: ColorTokenValue
|
|
27
|
+
umbra?: ColorTokenValue
|
|
28
|
+
penumbra?: ColorTokenValue
|
|
29
|
+
ambient?: ColorTokenValue
|
|
30
|
+
}
|
|
31
|
+
skeleton?: {
|
|
32
|
+
from?: ColorTokenValue
|
|
33
|
+
to?: ColorTokenValue
|
|
34
|
+
}
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
export interface StateColorTokens {
|
|
@@ -54,12 +54,31 @@ export type TMP_ButtonColorTheme = Record<ColorStateTone, TMP_ButtonModesColorTh
|
|
|
54
54
|
export interface TMP_BaseColorTheme {
|
|
55
55
|
_blend: ColorBlendModeValue
|
|
56
56
|
dark: boolean
|
|
57
|
+
// base: ThemeColorBase
|
|
57
58
|
base: {
|
|
58
59
|
bg: string
|
|
59
60
|
fg: string
|
|
60
61
|
border: string
|
|
62
|
+
focusRing: string
|
|
63
|
+
shadow: {
|
|
64
|
+
outline: string
|
|
65
|
+
umbra: string
|
|
66
|
+
penumbra: string
|
|
67
|
+
ambient: string
|
|
68
|
+
}
|
|
69
|
+
skeleton: {
|
|
70
|
+
from: string
|
|
71
|
+
to: string
|
|
72
|
+
}
|
|
61
73
|
}
|
|
62
74
|
button: TMP_ButtonColorTheme
|
|
75
|
+
// card: ThemeColorCard
|
|
76
|
+
// input: ThemeColorInput
|
|
77
|
+
// selectable?: ThemeColorSelectable
|
|
78
|
+
// spot: ThemeColorSpot
|
|
79
|
+
// syntax: ThemeColorSyntax
|
|
80
|
+
// solid: ThemeColorSolid
|
|
81
|
+
// muted: ThemeColorMuted
|
|
63
82
|
}
|
|
64
83
|
|
|
65
84
|
export type TMP_ColorTheme = Record<ColorBaseTone, TMP_BaseColorTheme>
|