@sanity/ui 2.0.0-alpha.10 → 2.0.0-alpha.11
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 +0 -2
- package/dist/index.d.ts +404 -281
- package/dist/index.esm.js +2305 -5015
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2332 -5044
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/dialog/dialog.tsx +3 -3
- package/src/components/dialog/styles.ts +4 -3
- package/src/components/menu/__workshop__/closableMenuButton.tsx +2 -2
- package/src/components/menu/menuDivider.ts +1 -2
- package/src/components/menu/menuGroup.tsx +2 -2
- package/src/components/menu/menuItem.tsx +4 -4
- package/src/components/skeleton/styles.ts +7 -8
- package/src/components/tree/style.ts +20 -19
- package/src/primitives/_selectable/style.ts +21 -25
- package/src/primitives/avatar/avatar.tsx +3 -8
- package/src/primitives/avatar/avatarCounter.tsx +4 -5
- package/src/primitives/avatar/styles.ts +7 -5
- package/src/primitives/avatar/types.ts +0 -14
- package/src/primitives/badge/styles.ts +8 -7
- package/src/primitives/box/__workshop__/responsive.tsx +2 -2
- package/src/primitives/button/button.tsx +2 -2
- package/src/primitives/button/styles.ts +16 -82
- package/src/primitives/card/__workshop__/selected.tsx +9 -8
- package/src/primitives/card/card.tsx +8 -43
- package/src/primitives/card/styles.ts +22 -30
- package/src/primitives/card/types.ts +1 -3
- package/src/primitives/checkbox/styles.ts +20 -20
- package/src/primitives/code/code.tsx +3 -15
- package/src/primitives/code/styles.ts +42 -51
- package/src/primitives/heading/styles.ts +5 -6
- package/src/primitives/kbd/kbd.tsx +1 -2
- package/src/primitives/label/styles.ts +2 -3
- package/src/primitives/popover/popoverArrow.tsx +2 -3
- package/src/primitives/popover/popoverCard.tsx +2 -6
- package/src/primitives/radio/styles.ts +15 -15
- package/src/primitives/select/styles.ts +22 -20
- package/src/primitives/switch/styles.ts +13 -13
- package/src/primitives/text/__workshop__/colored.tsx +11 -10
- package/src/primitives/text/styles.ts +9 -10
- package/src/primitives/textArea/textArea.tsx +11 -7
- package/src/primitives/textInput/textInput.tsx +12 -12
- package/src/primitives/tooltip/__workshop__/props.tsx +3 -20
- package/src/primitives/tooltip/tooltipArrow.tsx +2 -3
- package/src/styles/border/borderStyle.ts +1 -2
- package/src/styles/colorVars/colorVarsStyle.ts +32 -73
- package/src/styles/focusRing/index.ts +4 -6
- package/src/styles/input/textInputStyle.ts +93 -76
- package/src/styles/margin/marginsStyle.test.ts +2 -1
- package/src/styles/padding/paddingStyle.test.ts +2 -1
- package/src/styles/shadow/shadowStyle.ts +5 -5
- package/src/theme/__workshop__/canvas.tsx +395 -0
- package/src/theme/__workshop__/color.tsx +2 -2
- package/src/theme/__workshop__/index.ts +5 -0
- package/src/theme/lib/theme/color/_generic/index.ts +1 -0
- package/src/theme/lib/theme/color/_generic/types.ts +30 -0
- package/src/theme/lib/theme/color/base/index.ts +1 -0
- package/src/theme/lib/theme/color/base/types.ts +19 -0
- package/src/theme/lib/theme/color/button/createButtonModes.ts +20 -0
- package/src/theme/lib/theme/color/button/createButtonTones.ts +52 -0
- package/src/theme/lib/theme/color/button/index.ts +1 -0
- package/src/theme/lib/theme/color/button/types.ts +44 -0
- package/src/theme/lib/theme/color/card/createCardStates.ts +58 -0
- package/src/theme/lib/theme/color/card/index.ts +1 -0
- package/src/theme/lib/theme/color/card/types.ts +18 -0
- package/src/theme/lib/theme/color/color.test.ts +63 -0
- package/src/theme/lib/theme/color/defaults.ts +390 -0
- package/src/theme/lib/theme/color/factory.ts +138 -0
- package/src/theme/lib/theme/color/index.ts +12 -3
- package/src/theme/lib/theme/color/input/createInputModes.ts +84 -0
- package/src/theme/lib/theme/color/input/index.ts +1 -0
- package/src/theme/lib/theme/color/input/types.ts +28 -0
- package/src/theme/lib/theme/color/muted/createMuted.ts +56 -0
- package/src/theme/lib/theme/color/muted/index.ts +1 -0
- package/src/theme/lib/theme/color/muted/types.ts +24 -0
- package/src/theme/lib/theme/color/selectable/createSelectableTones.ts +73 -0
- package/src/theme/lib/theme/color/selectable/index.ts +1 -0
- package/src/theme/lib/theme/color/selectable/types.ts +29 -0
- package/src/theme/lib/theme/color/solid/createSolidTones.ts +56 -0
- package/src/theme/lib/theme/color/solid/index.ts +1 -0
- package/src/theme/lib/theme/color/solid/types.ts +24 -0
- package/src/theme/lib/theme/color/spot/createSpot.ts +21 -0
- package/src/theme/lib/theme/color/spot/index.ts +1 -0
- package/src/theme/lib/theme/color/spot/types.ts +28 -0
- package/src/theme/lib/theme/color/syntax/index.ts +1 -0
- package/src/theme/lib/theme/color/syntax/types.ts +41 -0
- package/src/theme/lib/theme/color/types.ts +37 -6
- package/src/theme/studioTheme/color.ts +661 -6
- package/src/theme/studioTheme/theme.ts +2 -8
- package/src/theme/{lib/theme/color/cssVariables → studioTheme}/tints.ts +2 -2
- package/src/theme/themeColorProvider.tsx +0 -2
- package/src/theme/themeProvider.tsx +8 -28
- package/src/theme/types.ts +4 -2
- package/src/utils/elementQuery/__workshop__/customMedia.tsx +3 -4
- package/src/primitives/avatar/spotColors.ts +0 -53
- package/src/theme/lib/theme/color/cssVariables/cardVariables.ts +0 -88
- package/src/theme/lib/theme/color/cssVariables/createCssVars.ts +0 -31
- package/src/theme/lib/theme/color/cssVariables/cssVars.test.ts +0 -262
- package/src/theme/lib/theme/color/cssVariables/index.ts +0 -1
- package/src/theme/lib/theme/color/cssVariables/tones.ts +0 -67
- package/src/theme/lib/theme/color/cssVariables/utils.test.ts +0 -15
- package/src/theme/lib/theme/color/cssVariables/utils.ts +0 -9
- package/src/theme/toneContext/toneContext.ts +0 -12
- package/src/theme/toneContext/toneProvider.tsx +0 -31
- package/src/theme/toneContext/types.ts +0 -10
- package/src/theme/toneContext/useToneContext.tsx +0 -26
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import {useContext, useMemo} from 'react'
|
|
2
|
-
import {ThemeProvider as StyledThemeProvider
|
|
2
|
+
import {ThemeProvider as StyledThemeProvider} from 'styled-components'
|
|
3
3
|
import {DEFAULT_THEME_LAYER} from './defaults'
|
|
4
|
-
import {
|
|
5
|
-
import {legacyColors} from './lib/theme/color/_legacy/legacyColor'
|
|
6
|
-
import {createCssVars} from './lib/theme/color/cssVariables'
|
|
7
|
-
import {cssObjectToCssString} from './lib/theme/color/cssVariables/utils'
|
|
4
|
+
import {ThemeColorSchemeKey, ThemeColorName} from './lib/theme'
|
|
8
5
|
import {ThemeContext} from './themeContext'
|
|
9
|
-
import {ToneProvider} from './toneContext/toneProvider'
|
|
10
6
|
import {RootTheme, Theme, ThemeContextValue} from './types'
|
|
11
7
|
|
|
12
|
-
const GlobalVariables = createGlobalStyle<{$vars?: string}>`
|
|
13
|
-
:root {
|
|
14
|
-
${({$vars}) => $vars}
|
|
15
|
-
}
|
|
16
|
-
`
|
|
17
|
-
|
|
18
8
|
/**
|
|
19
9
|
* @public
|
|
20
10
|
*/
|
|
@@ -40,12 +30,13 @@ export function ThemeProvider(props: ThemeProviderProps): React.ReactElement {
|
|
|
40
30
|
const theme: Theme | null = useMemo(() => {
|
|
41
31
|
if (!themeProp) return null
|
|
42
32
|
|
|
43
|
-
const {layer: rootLayer, ...restTheme} = themeProp
|
|
44
|
-
|
|
33
|
+
const {color: rootColor, layer: rootLayer, ...restTheme} = themeProp
|
|
34
|
+
const colorScheme = rootColor[scheme] || rootColor.light
|
|
35
|
+
const color = colorScheme[tone] || colorScheme.default
|
|
45
36
|
const layer = rootLayer || DEFAULT_THEME_LAYER
|
|
46
37
|
|
|
47
|
-
return {sanity: {...restTheme,
|
|
48
|
-
}, [themeProp])
|
|
38
|
+
return {sanity: {...restTheme, color, layer}}
|
|
39
|
+
}, [scheme, themeProp, tone])
|
|
49
40
|
|
|
50
41
|
const value: ThemeContextValue | null = useMemo(
|
|
51
42
|
() =>
|
|
@@ -58,24 +49,13 @@ export function ThemeProvider(props: ThemeProviderProps): React.ReactElement {
|
|
|
58
49
|
[themeProp, scheme, tone],
|
|
59
50
|
)
|
|
60
51
|
|
|
61
|
-
const cssVariables = useMemo(() => {
|
|
62
|
-
if (!themeProp?.color.tones) return
|
|
63
|
-
|
|
64
|
-
return cssObjectToCssString(createCssVars(scheme, themeProp?.color.tones))
|
|
65
|
-
}, [scheme, themeProp?.color.tones])
|
|
66
|
-
|
|
67
52
|
if (!theme) {
|
|
68
53
|
return <pre>ThemeProvider: no "theme" property provided</pre>
|
|
69
54
|
}
|
|
70
55
|
|
|
71
56
|
return (
|
|
72
57
|
<ThemeContext.Provider value={value}>
|
|
73
|
-
<
|
|
74
|
-
<StyledThemeProvider theme={theme}>
|
|
75
|
-
<ToneProvider tone={tone} scheme={scheme}>
|
|
76
|
-
{children}
|
|
77
|
-
</ToneProvider>
|
|
78
|
-
</StyledThemeProvider>
|
|
58
|
+
<StyledThemeProvider theme={theme}>{children}</StyledThemeProvider>
|
|
79
59
|
</ThemeContext.Provider>
|
|
80
60
|
)
|
|
81
61
|
}
|
package/src/theme/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {CSSObject} from '../types/styled'
|
|
2
|
-
import {BaseTheme, ThemeColorName, ThemeColorSchemeKey} from './lib/theme'
|
|
2
|
+
import {BaseTheme, ThemeColor, ThemeColorName, ThemeColorSchemeKey} from './lib/theme'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
@@ -23,7 +23,9 @@ export interface Styles {
|
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
25
|
export interface Theme {
|
|
26
|
-
sanity: RootTheme
|
|
26
|
+
sanity: Omit<RootTheme, 'color'> & {
|
|
27
|
+
color: ThemeColor
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/**
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import {Box, Card, ElementQuery, Text} from '@sanity/ui'
|
|
2
2
|
import styled from 'styled-components'
|
|
3
|
-
import {mutableCardVariables} from '../../../theme/lib/theme/color/cssVariables/cardVariables'
|
|
4
3
|
|
|
5
4
|
const TestCard = styled(Card)`
|
|
6
|
-
|
|
5
|
+
--card-fg-color: orange;
|
|
7
6
|
|
|
8
7
|
[data-eq-min~='0'] > & {
|
|
9
|
-
|
|
8
|
+
--card-fg-color: green;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
[data-eq-min~='1'] > & {
|
|
13
|
-
|
|
12
|
+
--card-fg-color: blue;
|
|
14
13
|
}
|
|
15
14
|
`
|
|
16
15
|
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
gray,
|
|
3
|
-
blue,
|
|
4
|
-
purple,
|
|
5
|
-
magenta,
|
|
6
|
-
red,
|
|
7
|
-
orange,
|
|
8
|
-
yellow,
|
|
9
|
-
green,
|
|
10
|
-
cyan,
|
|
11
|
-
ColorTint,
|
|
12
|
-
} from '@sanity/color'
|
|
13
|
-
import {ThemeColorSchemeKey} from '../../theme'
|
|
14
|
-
import {ThemeColorSpotKey} from './types'
|
|
15
|
-
|
|
16
|
-
export const spotColor: Record<ThemeColorSpotKey, Record<ThemeColorSchemeKey, ColorTint>> = {
|
|
17
|
-
gray: {
|
|
18
|
-
dark: gray['400'],
|
|
19
|
-
light: gray['500'],
|
|
20
|
-
},
|
|
21
|
-
blue: {
|
|
22
|
-
dark: blue['400'],
|
|
23
|
-
light: blue['500'],
|
|
24
|
-
},
|
|
25
|
-
purple: {
|
|
26
|
-
dark: purple['400'],
|
|
27
|
-
light: purple['500'],
|
|
28
|
-
},
|
|
29
|
-
magenta: {
|
|
30
|
-
dark: magenta['400'],
|
|
31
|
-
light: magenta['500'],
|
|
32
|
-
},
|
|
33
|
-
red: {
|
|
34
|
-
dark: red['400'],
|
|
35
|
-
light: red['500'],
|
|
36
|
-
},
|
|
37
|
-
orange: {
|
|
38
|
-
dark: orange['400'],
|
|
39
|
-
light: orange['500'],
|
|
40
|
-
},
|
|
41
|
-
yellow: {
|
|
42
|
-
dark: yellow['400'],
|
|
43
|
-
light: yellow['500'],
|
|
44
|
-
},
|
|
45
|
-
green: {
|
|
46
|
-
dark: green['400'],
|
|
47
|
-
light: green['500'],
|
|
48
|
-
},
|
|
49
|
-
cyan: {
|
|
50
|
-
dark: cyan['400'],
|
|
51
|
-
light: cyan['500'],
|
|
52
|
-
},
|
|
53
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import {tonesCssVariables} from './tones'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
* This variables can be changed by other components besides the `Card` component itself.
|
|
6
|
-
*/
|
|
7
|
-
export const mutableCardVariables = {
|
|
8
|
-
'bg-color': '--card-bg-color',
|
|
9
|
-
'muted-fg-color': '--card-muted-fg-color',
|
|
10
|
-
'icon-color': '--card-icon-color',
|
|
11
|
-
'fg-color': '--card-fg-color',
|
|
12
|
-
'bg-image': '--card-bg-image',
|
|
13
|
-
'accent-color': '--card-accent-fg-color',
|
|
14
|
-
} as const
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @internal
|
|
18
|
-
* This are the only variables that are exposed, as they can be updated and used by other components.
|
|
19
|
-
*/
|
|
20
|
-
export const mutableVariables: Record<keyof typeof mutableCardVariables, string> = Object.keys(
|
|
21
|
-
mutableCardVariables,
|
|
22
|
-
).reduce(
|
|
23
|
-
(acc, key) => {
|
|
24
|
-
const item = key as keyof typeof mutableCardVariables
|
|
25
|
-
|
|
26
|
-
acc[item] = `var(${mutableCardVariables[item]})`
|
|
27
|
-
|
|
28
|
-
return acc
|
|
29
|
-
},
|
|
30
|
-
{} as Record<keyof typeof mutableCardVariables, string>,
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @internal
|
|
35
|
-
* This variables can not be changed by other components, they are here for backwards compatibility.
|
|
36
|
-
* Shouldn't be used inside any component in @sanity/ui
|
|
37
|
-
*/
|
|
38
|
-
const legacyFixedVariables = [
|
|
39
|
-
'--card-shadow-outline-color',
|
|
40
|
-
'--card-shadow-umbra-color',
|
|
41
|
-
'--card-shadow-penumbra-color',
|
|
42
|
-
'--card-shadow-ambient-color',
|
|
43
|
-
'--card-focus-ring-color',
|
|
44
|
-
'--card-link-fg-color',
|
|
45
|
-
'--card-code-bg-color',
|
|
46
|
-
'--card-code-fg-color',
|
|
47
|
-
'--card-skeleton-color-from',
|
|
48
|
-
'--card-skeleton-color-to',
|
|
49
|
-
'--card-link-color',
|
|
50
|
-
'--card-hairline-soft-color',
|
|
51
|
-
'--card-hairline-hard-color',
|
|
52
|
-
'--card-border-color',
|
|
53
|
-
] as const
|
|
54
|
-
|
|
55
|
-
const allVariables = [...Object.values(mutableCardVariables), ...legacyFixedVariables] as const
|
|
56
|
-
|
|
57
|
-
type CardCssVariable = (typeof allVariables)[number]
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @internal
|
|
61
|
-
*/
|
|
62
|
-
export const cardVariables: Record<CardCssVariable, string> = {
|
|
63
|
-
'--card-shadow-outline-color': tonesCssVariables.default['base-shadow-outline-color'],
|
|
64
|
-
'--card-shadow-umbra-color': tonesCssVariables.default['base-shadow-umbra-color'],
|
|
65
|
-
'--card-shadow-penumbra-color': tonesCssVariables.default['base-shadow-penumbra-color'],
|
|
66
|
-
'--card-shadow-ambient-color': tonesCssVariables.default['base-shadow-ambient-color'],
|
|
67
|
-
'--card-focus-ring-color': tonesCssVariables.positive['bg-accent'],
|
|
68
|
-
|
|
69
|
-
'--card-icon-color': tonesCssVariables.default['icon-default'],
|
|
70
|
-
|
|
71
|
-
// Card
|
|
72
|
-
'--card-bg-color': tonesCssVariables.default['bg-base'],
|
|
73
|
-
'--card-bg-image': 'inherit',
|
|
74
|
-
'--card-fg-color': tonesCssVariables.default['text-primary'],
|
|
75
|
-
'--card-border-color': tonesCssVariables.default['border-base'],
|
|
76
|
-
'--card-muted-fg-color': tonesCssVariables.default['text-secondary'],
|
|
77
|
-
'--card-accent-fg-color': tonesCssVariables.default['text-accent'],
|
|
78
|
-
'--card-link-fg-color': tonesCssVariables.default['text-link'],
|
|
79
|
-
'--card-code-bg-color': tonesCssVariables.default['bg-tint-code'],
|
|
80
|
-
'--card-code-fg-color': tonesCssVariables.default['text-code'],
|
|
81
|
-
'--card-skeleton-color-from': tonesCssVariables.default['skeleton-from'],
|
|
82
|
-
'--card-skeleton-color-to': tonesCssVariables.default['skeleton-to'],
|
|
83
|
-
|
|
84
|
-
// @todo: deprecate
|
|
85
|
-
'--card-link-color': tonesCssVariables.default['text-link'],
|
|
86
|
-
'--card-hairline-soft-color': tonesCssVariables.default['border-base'],
|
|
87
|
-
'--card-hairline-hard-color': tonesCssVariables.default['border-base'],
|
|
88
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {ColorTints} from '@sanity/color'
|
|
2
|
-
import {ThemeColorName, ThemeColorSchemeKey} from '../types'
|
|
3
|
-
import {cardVariables, mutableVariables} from './cardVariables'
|
|
4
|
-
import {getColorHex} from './tints'
|
|
5
|
-
import {createTonesVariables, tonesCssVariables} from './tones'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @beta
|
|
9
|
-
*/
|
|
10
|
-
export const createCssVars = (
|
|
11
|
-
scheme: ThemeColorSchemeKey,
|
|
12
|
-
tones: Record<ThemeColorName, ColorTints>,
|
|
13
|
-
defaultTone: ThemeColorName = 'default',
|
|
14
|
-
): Record<string, string> => {
|
|
15
|
-
const baseBg = getColorHex(tones[defaultTone], scheme, defaultTone, 'base-bg-card')
|
|
16
|
-
const tonesVars = createTonesVariables(scheme, tones, defaultTone, baseBg)
|
|
17
|
-
|
|
18
|
-
return {...tonesVars, ...cardVariables}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @beta
|
|
23
|
-
*/
|
|
24
|
-
export const cssVars = {
|
|
25
|
-
...tonesCssVariables,
|
|
26
|
-
/**
|
|
27
|
-
* This variables are mutable, they can be updated by other components.
|
|
28
|
-
* The main component that updates them is the card, these are the only ones that should be exposed for use from the cards.
|
|
29
|
-
*/
|
|
30
|
-
mutable: mutableVariables,
|
|
31
|
-
}
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import {ColorTints, hues} from '@sanity/color'
|
|
2
|
-
import {ThemeColorName} from '../types'
|
|
3
|
-
import {createCssVars} from './createCssVars'
|
|
4
|
-
|
|
5
|
-
export const tones: Record<ThemeColorName, ColorTints> = {
|
|
6
|
-
default: hues.gray,
|
|
7
|
-
transparent: hues.gray,
|
|
8
|
-
primary: hues.gray,
|
|
9
|
-
positive: hues.cyan,
|
|
10
|
-
caution: hues.yellow,
|
|
11
|
-
critical: hues.red,
|
|
12
|
-
} as const
|
|
13
|
-
|
|
14
|
-
describe('css variables', () => {
|
|
15
|
-
it('Should create the variables when no default tone is provided', () => {
|
|
16
|
-
const result = createCssVars('light', tones)
|
|
17
|
-
|
|
18
|
-
const expected = {
|
|
19
|
-
'--default-text-primary': '#1f2228',
|
|
20
|
-
'--default-text-secondary': '#5e6573',
|
|
21
|
-
'--default-text-inactive': '#788191',
|
|
22
|
-
'--default-text-code': '#5e6573',
|
|
23
|
-
'--default-text-muted': '#5e6573',
|
|
24
|
-
'--default-text-link': '#0661fe',
|
|
25
|
-
'--default-text-accent': '#ec4636',
|
|
26
|
-
'--default-bg-base': '#ffffff',
|
|
27
|
-
'--default-bg-base-hover': '#f9f9fa',
|
|
28
|
-
'--default-bg-base-active': '#f3f4f6',
|
|
29
|
-
'--default-bg-accent': '#1f2228',
|
|
30
|
-
'--default-bg-accent-hover': '#17191c',
|
|
31
|
-
'--default-bg-accent-active': '#111213',
|
|
32
|
-
'--default-bg-tint': '#f9f9fa',
|
|
33
|
-
'--default-bg-tint-code': '#f9f9fa',
|
|
34
|
-
'--default-icon-default': '#788191',
|
|
35
|
-
'--default-icon-inverted': '#ffffff',
|
|
36
|
-
'--default-border-base': '#f3f4f6',
|
|
37
|
-
'--default-border-base-hover': '#e2e6e9',
|
|
38
|
-
'--default-border-accent': '#5e6573',
|
|
39
|
-
'--default-border-accent-inverted': '#ffffff',
|
|
40
|
-
'--default-base-bg-card': '#ffffff',
|
|
41
|
-
'--default-base-bg-raw': '#ffffff',
|
|
42
|
-
'--default-base-shadow-outline-color': 'rgba(120,129,145,0.2)',
|
|
43
|
-
'--default-base-shadow-umbra-color': 'rgba(120,129,145,0.1)',
|
|
44
|
-
'--default-base-shadow-penumbra-color': 'rgba(120,129,145,0.07)',
|
|
45
|
-
'--default-base-shadow-ambient-color': 'rgba(120,129,145,0.06)',
|
|
46
|
-
'--default-base-text-color': '#ffffff',
|
|
47
|
-
'--default-skeleton-from': '#f3f4f6',
|
|
48
|
-
'--default-skeleton-to': 'rgba(249,249,250,0.5)',
|
|
49
|
-
'--transparent-text-primary': '#1f2228',
|
|
50
|
-
'--transparent-text-secondary': '#5e6573',
|
|
51
|
-
'--transparent-text-inactive': '#788191',
|
|
52
|
-
'--transparent-text-code': '#5e6573',
|
|
53
|
-
'--transparent-text-muted': '#5e6573',
|
|
54
|
-
'--transparent-text-link': '#0661fe',
|
|
55
|
-
'--transparent-text-accent': '#ec4636',
|
|
56
|
-
'--transparent-bg-base': '#ffffff',
|
|
57
|
-
'--transparent-bg-base-hover': '#f9f9fa',
|
|
58
|
-
'--transparent-bg-base-active': '#f3f4f6',
|
|
59
|
-
'--transparent-bg-accent': '#788191',
|
|
60
|
-
'--transparent-bg-accent-hover': '#5e6573',
|
|
61
|
-
'--transparent-bg-accent-active': '#464c58',
|
|
62
|
-
'--transparent-bg-tint': '#f9f9fa',
|
|
63
|
-
'--transparent-bg-tint-code': '#f9f9fa',
|
|
64
|
-
'--transparent-icon-default': '#788191',
|
|
65
|
-
'--transparent-icon-inverted': '#ffffff',
|
|
66
|
-
'--transparent-border-base': '#f3f4f6',
|
|
67
|
-
'--transparent-border-base-hover': '#e2e6e9',
|
|
68
|
-
'--transparent-border-accent': '#788191',
|
|
69
|
-
'--transparent-border-accent-inverted': '#ffffff',
|
|
70
|
-
'--transparent-base-bg-card': '#f9f9fa',
|
|
71
|
-
'--transparent-base-bg-raw': '#ffffff',
|
|
72
|
-
'--transparent-base-shadow-outline-color': 'rgba(120,129,145,0.2)',
|
|
73
|
-
'--transparent-base-shadow-umbra-color': 'rgba(120,129,145,0.1)',
|
|
74
|
-
'--transparent-base-shadow-penumbra-color': 'rgba(120,129,145,0.07)',
|
|
75
|
-
'--transparent-base-shadow-ambient-color': 'rgba(120,129,145,0.06)',
|
|
76
|
-
'--transparent-base-text-color': '#ffffff',
|
|
77
|
-
'--transparent-skeleton-from': '#f3f4f6',
|
|
78
|
-
'--transparent-skeleton-to': 'rgba(249,249,250,0.5)',
|
|
79
|
-
'--primary-text-primary': '#1f2228',
|
|
80
|
-
'--primary-text-secondary': '#5e6573',
|
|
81
|
-
'--primary-text-inactive': '#788191',
|
|
82
|
-
'--primary-text-code': '#5e6573',
|
|
83
|
-
'--primary-text-muted': '#5e6573',
|
|
84
|
-
'--primary-text-link': '#0661fe',
|
|
85
|
-
'--primary-text-accent': '#ec4636',
|
|
86
|
-
'--primary-bg-base': '#ffffff',
|
|
87
|
-
'--primary-bg-base-hover': '#f9f9fa',
|
|
88
|
-
'--primary-bg-base-active': '#f3f4f6',
|
|
89
|
-
'--primary-bg-accent': '#1f2228',
|
|
90
|
-
'--primary-bg-accent-hover': '#17191c',
|
|
91
|
-
'--primary-bg-accent-active': '#111213',
|
|
92
|
-
'--primary-bg-tint': '#f9f9fa',
|
|
93
|
-
'--primary-bg-tint-code': '#f9f9fa',
|
|
94
|
-
'--primary-icon-default': '#788191',
|
|
95
|
-
'--primary-icon-inverted': '#ffffff',
|
|
96
|
-
'--primary-border-base': '#f3f4f6',
|
|
97
|
-
'--primary-border-base-hover': '#e2e6e9',
|
|
98
|
-
'--primary-border-accent': '#5e6573',
|
|
99
|
-
'--primary-border-accent-inverted': '#ffffff',
|
|
100
|
-
'--primary-base-bg-card': '#f9f9fa',
|
|
101
|
-
'--primary-base-bg-raw': '#ffffff',
|
|
102
|
-
'--primary-base-shadow-outline-color': 'rgba(120,129,145,0.2)',
|
|
103
|
-
'--primary-base-shadow-umbra-color': 'rgba(120,129,145,0.1)',
|
|
104
|
-
'--primary-base-shadow-penumbra-color': 'rgba(120,129,145,0.07)',
|
|
105
|
-
'--primary-base-shadow-ambient-color': 'rgba(120,129,145,0.06)',
|
|
106
|
-
'--primary-base-text-color': '#ffffff',
|
|
107
|
-
'--primary-skeleton-from': '#f3f4f6',
|
|
108
|
-
'--primary-skeleton-to': 'rgba(249,249,250,0.5)',
|
|
109
|
-
'--positive-text-primary': '#0b2a32',
|
|
110
|
-
'--positive-text-secondary': '#0e9ebe',
|
|
111
|
-
'--positive-text-inactive': '#0ecff1',
|
|
112
|
-
'--positive-text-code': '#0e9ebe',
|
|
113
|
-
'--positive-text-muted': '#0e9ebe',
|
|
114
|
-
'--positive-text-link': '#0661fe',
|
|
115
|
-
'--positive-text-accent': '#ec4636',
|
|
116
|
-
'--positive-bg-base': '#ffffff',
|
|
117
|
-
'--positive-bg-base-hover': '#f9f9fa',
|
|
118
|
-
'--positive-bg-base-active': '#ebfdff',
|
|
119
|
-
'--positive-bg-accent': '#41e1f6',
|
|
120
|
-
'--positive-bg-accent-hover': '#0ecff1',
|
|
121
|
-
'--positive-bg-accent-active': '#0e9ebe',
|
|
122
|
-
'--positive-bg-tint': '#ebfdff',
|
|
123
|
-
'--positive-bg-tint-code': '#ebfdff',
|
|
124
|
-
'--positive-icon-default': '#0ecff1',
|
|
125
|
-
'--positive-icon-inverted': '#ffffff',
|
|
126
|
-
'--positive-border-base': '#d2fcfe',
|
|
127
|
-
'--positive-border-base-hover': '#aaf8fd',
|
|
128
|
-
'--positive-border-accent': '#41e1f6',
|
|
129
|
-
'--positive-border-accent-inverted': '#ffffff',
|
|
130
|
-
'--positive-base-bg-card': '#ebfdff',
|
|
131
|
-
'--positive-base-bg-raw': '#ffffff',
|
|
132
|
-
'--positive-base-shadow-outline-color': 'rgba(14,207,241,0.2)',
|
|
133
|
-
'--positive-base-shadow-umbra-color': 'rgba(14,207,241,0.1)',
|
|
134
|
-
'--positive-base-shadow-penumbra-color': 'rgba(14,207,241,0.07)',
|
|
135
|
-
'--positive-base-shadow-ambient-color': 'rgba(14,207,241,0.06)',
|
|
136
|
-
'--positive-base-text-color': '#ffffff',
|
|
137
|
-
'--positive-skeleton-from': '#d2fcfe',
|
|
138
|
-
'--positive-skeleton-to': 'rgba(235,253,255,0.5)',
|
|
139
|
-
'--caution-text-primary': '#331f0a',
|
|
140
|
-
'--caution-text-secondary': '#cb920b',
|
|
141
|
-
'--caution-text-inactive': '#f3bc16',
|
|
142
|
-
'--caution-text-code': '#cb920b',
|
|
143
|
-
'--caution-text-muted': '#cb920b',
|
|
144
|
-
'--caution-text-link': '#0661fe',
|
|
145
|
-
'--caution-text-accent': '#ec4636',
|
|
146
|
-
'--caution-bg-base': '#ffffff',
|
|
147
|
-
'--caution-bg-base-hover': '#fffdf0',
|
|
148
|
-
'--caution-bg-base-active': '#fef7cd',
|
|
149
|
-
'--caution-bg-accent': '#f3bc16',
|
|
150
|
-
'--caution-bg-accent-hover': '#cb920b',
|
|
151
|
-
'--caution-bg-accent-active': '#98670b',
|
|
152
|
-
'--caution-bg-tint': '#fffdf0',
|
|
153
|
-
'--caution-bg-tint-code': '#fffdf0',
|
|
154
|
-
'--caution-icon-default': '#f3bc16',
|
|
155
|
-
'--caution-icon-inverted': '#ffffff',
|
|
156
|
-
'--caution-border-base': '#fef7cd',
|
|
157
|
-
'--caution-border-base-hover': '#fbf1a7',
|
|
158
|
-
'--caution-border-accent': '#f3bc16',
|
|
159
|
-
'--caution-border-accent-inverted': '#ffffff',
|
|
160
|
-
'--caution-base-bg-card': '#fffdf0',
|
|
161
|
-
'--caution-base-bg-raw': '#ffffff',
|
|
162
|
-
'--caution-base-shadow-outline-color': 'rgba(243,188,22,0.2)',
|
|
163
|
-
'--caution-base-shadow-umbra-color': 'rgba(243,188,22,0.1)',
|
|
164
|
-
'--caution-base-shadow-penumbra-color': 'rgba(243,188,22,0.07)',
|
|
165
|
-
'--caution-base-shadow-ambient-color': 'rgba(243,188,22,0.06)',
|
|
166
|
-
'--caution-base-text-color': '#ffffff',
|
|
167
|
-
'--caution-skeleton-from': '#fef7cd',
|
|
168
|
-
'--caution-skeleton-to': 'rgba(255,253,240,0.5)',
|
|
169
|
-
'--critical-text-primary': '#421410',
|
|
170
|
-
'--critical-text-secondary': '#d72414',
|
|
171
|
-
'--critical-text-inactive': '#f6a098',
|
|
172
|
-
'--critical-text-code': '#d72414',
|
|
173
|
-
'--critical-text-muted': '#d72414',
|
|
174
|
-
'--critical-text-link': '#0661fe',
|
|
175
|
-
'--critical-text-accent': '#ec4636',
|
|
176
|
-
'--critical-bg-base': '#ffffff',
|
|
177
|
-
'--critical-bg-base-hover': '#fff5f5',
|
|
178
|
-
'--critical-bg-base-active': '#fee8e7',
|
|
179
|
-
'--critical-bg-accent': '#ec4636',
|
|
180
|
-
'--critical-bg-accent-hover': '#d72414',
|
|
181
|
-
'--critical-bg-accent-active': '#a52112',
|
|
182
|
-
'--critical-bg-tint': '#fff5f5',
|
|
183
|
-
'--critical-bg-tint-code': '#fff5f5',
|
|
184
|
-
'--critical-icon-default': '#ec4636',
|
|
185
|
-
'--critical-icon-inverted': '#ffffff',
|
|
186
|
-
'--critical-border-base': '#fee8e7',
|
|
187
|
-
'--critical-border-base-hover': '#fbccc6',
|
|
188
|
-
'--critical-border-accent': '#ec4636',
|
|
189
|
-
'--critical-border-accent-inverted': '#ffffff',
|
|
190
|
-
'--critical-base-bg-card': '#fff5f5',
|
|
191
|
-
'--critical-base-bg-raw': '#ffffff',
|
|
192
|
-
'--critical-base-shadow-outline-color': 'rgba(236,70,54,0.2)',
|
|
193
|
-
'--critical-base-shadow-umbra-color': 'rgba(236,70,54,0.1)',
|
|
194
|
-
'--critical-base-shadow-penumbra-color': 'rgba(236,70,54,0.07)',
|
|
195
|
-
'--critical-base-shadow-ambient-color': 'rgba(236,70,54,0.06)',
|
|
196
|
-
'--critical-base-text-color': '#ffffff',
|
|
197
|
-
'--critical-skeleton-from': '#fee8e7',
|
|
198
|
-
'--critical-skeleton-to': 'rgba(255,245,245,0.5)',
|
|
199
|
-
'--card-shadow-outline-color': 'var(--default-base-shadow-outline-color)',
|
|
200
|
-
'--card-shadow-umbra-color': 'var(--default-base-shadow-umbra-color)',
|
|
201
|
-
'--card-shadow-penumbra-color': 'var(--default-base-shadow-penumbra-color)',
|
|
202
|
-
'--card-shadow-ambient-color': 'var(--default-base-shadow-ambient-color)',
|
|
203
|
-
'--card-focus-ring-color': 'var(--positive-bg-accent)',
|
|
204
|
-
'--card-icon-color': 'var(--default-icon-default)',
|
|
205
|
-
'--card-bg-image': 'inherit',
|
|
206
|
-
'--card-bg-color': 'var(--default-bg-base)',
|
|
207
|
-
'--card-fg-color': 'var(--default-text-primary)',
|
|
208
|
-
'--card-muted-fg-color': 'var(--default-text-secondary)',
|
|
209
|
-
'--card-accent-fg-color': 'var(--default-text-accent)',
|
|
210
|
-
'--card-link-fg-color': 'var(--default-text-link)',
|
|
211
|
-
'--card-code-bg-color': 'var(--default-bg-tint-code)',
|
|
212
|
-
'--card-code-fg-color': 'var(--default-text-code)',
|
|
213
|
-
'--card-skeleton-color-from': 'var(--default-skeleton-from)',
|
|
214
|
-
'--card-skeleton-color-to': 'var(--default-skeleton-to)',
|
|
215
|
-
'--card-link-color': 'var(--default-text-link)',
|
|
216
|
-
'--card-hairline-soft-color': 'var(--default-border-base)',
|
|
217
|
-
'--card-hairline-hard-color': 'var(--default-border-base)',
|
|
218
|
-
'--card-border-color': 'var(--default-border-base)',
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
expect(result).toEqual(expected)
|
|
222
|
-
})
|
|
223
|
-
it('Should create the variables when a default tone is provided in light mode', () => {
|
|
224
|
-
const defaultVariables = createCssVars('light', tones)
|
|
225
|
-
const result = createCssVars('light', tones, 'caution')
|
|
226
|
-
|
|
227
|
-
expect(result['--default-text-primary']).toEqual(result['--caution-text-primary'])
|
|
228
|
-
// It's not equal because it has been mixed with the default bg
|
|
229
|
-
expect(result['--default-text-primary']).not.toEqual(defaultVariables['--caution-text-primary'])
|
|
230
|
-
|
|
231
|
-
expect(result['--default-text-secondary']).toEqual(result['--caution-text-secondary'])
|
|
232
|
-
// It's not equal because it has been mixed with the default bg
|
|
233
|
-
expect(result['--default-text-secondary']).not.toEqual(
|
|
234
|
-
defaultVariables['--caution-text-secondary'],
|
|
235
|
-
)
|
|
236
|
-
// The default base bg should not be mixed
|
|
237
|
-
expect(result['--default-bg_base']).toEqual(defaultVariables['--caution-card_base_bg'])
|
|
238
|
-
|
|
239
|
-
expect(result['--default-base-shadow-ambient-color']).toEqual(
|
|
240
|
-
defaultVariables['--caution-base-shadow-ambient-color'],
|
|
241
|
-
)
|
|
242
|
-
expect(result['--default-base-shadow-ambient-color']).not.toEqual(
|
|
243
|
-
defaultVariables['--positive-base-shadow-ambient-color'],
|
|
244
|
-
)
|
|
245
|
-
})
|
|
246
|
-
it('Should create the variables when a default tone is provided in dark mode', () => {
|
|
247
|
-
const defaultVariables = createCssVars('dark', tones)
|
|
248
|
-
const result = createCssVars('dark', tones, 'caution')
|
|
249
|
-
|
|
250
|
-
expect(result['--default-text-primary']).toEqual(result['--caution-text-primary'])
|
|
251
|
-
// It's not equal because it has been mixed with the default bg
|
|
252
|
-
expect(result['--default-text-primary']).not.toEqual(defaultVariables['--caution-text-primary'])
|
|
253
|
-
|
|
254
|
-
expect(result['--default-text-secondary']).toEqual(result['--caution-text-secondary'])
|
|
255
|
-
// It's not equal because it has been mixed with the default bg
|
|
256
|
-
expect(result['--default-text-secondary']).not.toEqual(
|
|
257
|
-
defaultVariables['--caution-text-secondary'],
|
|
258
|
-
)
|
|
259
|
-
// The base bg should not be mixed
|
|
260
|
-
expect(result['--default-bg_base']).toEqual(defaultVariables['--caution-card_base_bg'])
|
|
261
|
-
})
|
|
262
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './createCssVars'
|
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
)
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,9 +0,0 @@
|
|
|
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,12 +0,0 @@
|
|
|
1
|
-
import {createContext} from 'react'
|
|
2
|
-
import {globalScope} from '../../lib/globalScope'
|
|
3
|
-
import {ToneContextValue} from './types'
|
|
4
|
-
|
|
5
|
-
const key = Symbol.for('@sanity/ui/context/toneContext')
|
|
6
|
-
|
|
7
|
-
globalScope[key] = globalScope[key] || createContext<ToneContextValue | null>(null)
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export const ToneContext: React.Context<ToneContextValue | null> = globalScope[key]
|