@sanity/ui 1.8.3 → 2.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.mjs +3 -0
- package/dist/index.d.ts +339 -415
- package/dist/index.esm.js +5374 -2489
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5375 -2487
- package/dist/index.js.map +1 -1
- package/package.json +21 -3
- package/src/components/autocomplete/autocomplete.tsx +2 -1
- package/src/components/dialog/constants.ts +4 -0
- package/src/components/dialog/dialog.tsx +89 -27
- package/src/components/dialog/styles.ts +3 -4
- package/src/components/hotkeys/hotkeys.tsx +2 -1
- package/src/components/menu/__workshop__/closableMenuButton.tsx +2 -2
- package/src/components/menu/menuButton.tsx +2 -2
- package/src/components/menu/menuDivider.ts +2 -1
- package/src/components/menu/menuGroup.tsx +24 -25
- package/src/components/menu/menuItem.tsx +31 -37
- package/src/components/skeleton/styles.ts +8 -7
- package/src/components/tab/tab.tsx +2 -1
- package/src/components/tree/style.ts +19 -20
- package/src/primitives/_selectable/style.ts +25 -23
- package/src/primitives/avatar/avatar.tsx +8 -3
- package/src/primitives/avatar/avatarCounter.tsx +5 -4
- package/src/primitives/avatar/spotColors.ts +53 -0
- package/src/primitives/avatar/styles.ts +6 -8
- package/src/primitives/avatar/types.ts +14 -0
- package/src/primitives/badge/badge.tsx +5 -3
- package/src/primitives/badge/styles.ts +7 -8
- package/src/primitives/box/__workshop__/responsive.tsx +2 -2
- package/src/primitives/button/__workshop__/sanityUploadButton.tsx +1 -2
- package/src/primitives/button/button.tsx +8 -9
- package/src/primitives/button/styles.ts +100 -17
- package/src/primitives/card/__workshop__/selected.tsx +8 -9
- package/src/primitives/card/card.tsx +43 -7
- package/src/primitives/card/styles.ts +31 -24
- package/src/primitives/card/types.ts +3 -1
- package/src/primitives/checkbox/checkbox.tsx +1 -0
- package/src/primitives/checkbox/styles.ts +53 -23
- package/src/primitives/code/code.tsx +15 -3
- package/src/primitives/code/styles.ts +51 -42
- package/src/primitives/heading/styles.ts +6 -5
- package/src/primitives/kbd/kbd.tsx +7 -6
- package/src/primitives/label/styles.ts +3 -2
- package/src/primitives/popover/popoverArrow.tsx +3 -2
- package/src/primitives/popover/popoverCard.tsx +8 -4
- package/src/primitives/radio/radio.tsx +1 -0
- package/src/primitives/radio/styles.ts +26 -13
- package/src/primitives/select/select.tsx +3 -2
- package/src/primitives/select/styles.ts +22 -24
- package/src/primitives/switch/__workshop__/props.tsx +4 -4
- package/src/primitives/switch/styles.ts +19 -12
- package/src/primitives/text/__workshop__/colored.tsx +10 -11
- package/src/primitives/text/styles.ts +10 -8
- package/src/primitives/textArea/textArea.tsx +8 -12
- package/src/primitives/textInput/textInput.tsx +15 -14
- package/src/primitives/tooltip/__workshop__/props.tsx +20 -3
- package/src/primitives/tooltip/tooltip.tsx +2 -2
- package/src/primitives/tooltip/tooltipArrow.tsx +3 -2
- package/src/primitives/types.ts +3 -2
- package/src/styles/border/borderStyle.ts +2 -1
- package/src/styles/colorVars/colorVarsStyle.ts +73 -30
- package/src/styles/focusRing/index.ts +8 -4
- package/src/styles/input/textInputStyle.ts +78 -94
- package/src/styles/margin/marginsStyle.test.ts +1 -2
- package/src/styles/padding/paddingStyle.test.ts +1 -2
- package/src/styles/radius/radiusStyle.ts +14 -4
- package/src/styles/radius/types.ts +3 -1
- package/src/styles/shadow/shadowStyle.ts +5 -5
- package/src/theme/__workshop__/color.tsx +2 -2
- package/src/theme/__workshop__/index.ts +0 -5
- package/src/theme/lib/color-fns/blend/multiply.ts +2 -2
- package/src/theme/lib/color-fns/blend/screen.ts +2 -2
- package/src/theme/lib/color-fns/convert.ts +15 -1
- package/src/theme/lib/color-fns/parse.ts +7 -3
- package/src/theme/lib/color-fns/types.ts +11 -0
- package/src/theme/lib/theme/avatar.ts +3 -0
- package/src/theme/lib/theme/color/_legacy/createColorTheme.ts +7 -0
- package/src/theme/lib/theme/color/_legacy/index.ts +1 -0
- package/src/theme/lib/theme/color/_legacy/legacyColor.ts +3997 -0
- package/src/theme/lib/theme/color/cssVariables/cardVariables.ts +88 -0
- package/src/theme/lib/theme/color/cssVariables/createCssVars.ts +31 -0
- package/src/theme/lib/theme/color/cssVariables/cssVars.test.ts +262 -0
- package/src/theme/lib/theme/color/cssVariables/index.ts +1 -0
- package/src/theme/lib/theme/color/cssVariables/tints.ts +312 -0
- package/src/theme/lib/theme/color/cssVariables/tones.ts +67 -0
- package/src/theme/lib/theme/color/cssVariables/utils.test.ts +15 -0
- package/src/theme/lib/theme/color/cssVariables/utils.ts +9 -0
- package/src/theme/lib/theme/color/index.ts +3 -12
- package/src/theme/lib/theme/color/types.ts +6 -37
- package/src/theme/lib/theme/input.ts +11 -0
- package/src/theme/lib/theme/theme.ts +7 -1
- package/src/theme/studioTheme/color.ts +6 -633
- package/src/theme/studioTheme/fonts.ts +3 -3
- package/src/theme/studioTheme/helpers.ts +15 -1
- package/src/theme/studioTheme/theme.ts +26 -6
- package/src/theme/themeColorProvider.tsx +2 -0
- package/src/theme/themeProvider.tsx +28 -8
- package/src/theme/toneContext/toneContext.ts +12 -0
- package/src/theme/toneContext/toneProvider.tsx +31 -0
- package/src/theme/toneContext/types.ts +10 -0
- package/src/theme/toneContext/useToneContext.tsx +26 -0
- package/src/theme/types.ts +10 -4
- package/src/types/index.ts +1 -0
- package/src/types/radius.ts +4 -0
- package/src/utils/elementQuery/__workshop__/customMedia.tsx +4 -3
- package/src/theme/__workshop__/canvas.tsx +0 -395
- package/src/theme/lib/theme/color/_generic/index.ts +0 -1
- package/src/theme/lib/theme/color/_generic/types.ts +0 -29
- package/src/theme/lib/theme/color/base/index.ts +0 -1
- package/src/theme/lib/theme/color/base/types.ts +0 -19
- package/src/theme/lib/theme/color/button/createButtonModes.ts +0 -20
- package/src/theme/lib/theme/color/button/createButtonTones.ts +0 -52
- package/src/theme/lib/theme/color/button/index.ts +0 -1
- package/src/theme/lib/theme/color/button/types.ts +0 -44
- package/src/theme/lib/theme/color/card/createCardStates.ts +0 -58
- package/src/theme/lib/theme/color/card/index.ts +0 -1
- package/src/theme/lib/theme/color/card/types.ts +0 -18
- package/src/theme/lib/theme/color/color.test.ts +0 -62
- package/src/theme/lib/theme/color/defaults.ts +0 -382
- package/src/theme/lib/theme/color/factory.ts +0 -138
- package/src/theme/lib/theme/color/input/createInputModes.ts +0 -84
- package/src/theme/lib/theme/color/input/index.ts +0 -1
- package/src/theme/lib/theme/color/input/types.ts +0 -27
- package/src/theme/lib/theme/color/muted/createMuted.ts +0 -56
- package/src/theme/lib/theme/color/muted/index.ts +0 -1
- package/src/theme/lib/theme/color/muted/types.ts +0 -24
- package/src/theme/lib/theme/color/selectable/createSelectableTones.ts +0 -73
- package/src/theme/lib/theme/color/selectable/index.ts +0 -1
- package/src/theme/lib/theme/color/selectable/types.ts +0 -29
- package/src/theme/lib/theme/color/solid/createSolidTones.ts +0 -56
- package/src/theme/lib/theme/color/solid/index.ts +0 -1
- package/src/theme/lib/theme/color/solid/types.ts +0 -24
- package/src/theme/lib/theme/color/spot/createSpot.ts +0 -21
- package/src/theme/lib/theme/color/spot/index.ts +0 -1
- package/src/theme/lib/theme/color/spot/types.ts +0 -28
- package/src/theme/lib/theme/color/syntax/index.ts +0 -1
- package/src/theme/lib/theme/color/syntax/types.ts +0 -41
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {RootTheme} from '../types'
|
|
2
|
-
import {
|
|
2
|
+
import {tones} from './color'
|
|
3
3
|
import {fonts} from './fonts'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -12,11 +12,22 @@ export const studioTheme: RootTheme = {
|
|
|
12
12
|
{distance: -6, size: 35},
|
|
13
13
|
{distance: -9, size: 55},
|
|
14
14
|
],
|
|
15
|
+
focusRing: {offset: 1, width: 1},
|
|
15
16
|
},
|
|
16
17
|
button: {
|
|
17
18
|
textWeight: 'medium',
|
|
19
|
+
focusRing: {offset: -1, width: 2},
|
|
20
|
+
},
|
|
21
|
+
card: {
|
|
22
|
+
focusRing: {offset: -1, width: 1},
|
|
23
|
+
},
|
|
24
|
+
color: {
|
|
25
|
+
tones: tones,
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
+
// @ts-ignore This is necessary until workshop is updated.
|
|
29
|
+
base: {bg: '#fffff'},
|
|
18
30
|
},
|
|
19
|
-
color,
|
|
20
31
|
container: [320, 640, 960, 1280, 1600, 1920],
|
|
21
32
|
focusRing: {
|
|
22
33
|
offset: 1,
|
|
@@ -28,7 +39,7 @@ export const studioTheme: RootTheme = {
|
|
|
28
39
|
shadows: [
|
|
29
40
|
null,
|
|
30
41
|
{umbra: [0, 0, 0, 0], penumbra: [0, 0, 0, 0], ambient: [0, 0, 0, 0]},
|
|
31
|
-
{umbra: [0, 3, 5, -
|
|
42
|
+
{umbra: [0, 3, 5, -2], penumbra: [0, 6, 10, 0], ambient: [0, 1, 18, 1]},
|
|
32
43
|
{umbra: [0, 7, 8, -4], penumbra: [0, 12, 17, 2], ambient: [0, 5, 22, 4]},
|
|
33
44
|
{umbra: [0, 9, 11, -5], penumbra: [0, 18, 28, 2], ambient: [0, 7, 34, 6]},
|
|
34
45
|
{umbra: [0, 11, 15, -7], penumbra: [0, 24, 38, 3], ambient: [0, 9, 46, 8]},
|
|
@@ -37,21 +48,30 @@ export const studioTheme: RootTheme = {
|
|
|
37
48
|
input: {
|
|
38
49
|
checkbox: {
|
|
39
50
|
size: 17,
|
|
51
|
+
focusRing: {offset: -1, width: 1},
|
|
40
52
|
},
|
|
41
53
|
radio: {
|
|
42
54
|
size: 17,
|
|
43
55
|
markSize: 9,
|
|
56
|
+
focusRing: {offset: -1, width: 1},
|
|
44
57
|
},
|
|
45
58
|
switch: {
|
|
46
|
-
width:
|
|
47
|
-
height:
|
|
48
|
-
padding:
|
|
59
|
+
width: 21,
|
|
60
|
+
height: 13,
|
|
61
|
+
padding: 2,
|
|
49
62
|
transitionDurationMs: 150,
|
|
50
63
|
transitionTimingFunction: 'ease-out',
|
|
64
|
+
focusRing: {offset: 1, width: 1},
|
|
51
65
|
},
|
|
52
66
|
border: {
|
|
53
67
|
width: 1,
|
|
54
68
|
},
|
|
69
|
+
select: {
|
|
70
|
+
focusRing: {offset: -1, width: 1},
|
|
71
|
+
},
|
|
72
|
+
text: {
|
|
73
|
+
focusRing: {offset: -1, width: 1},
|
|
74
|
+
},
|
|
55
75
|
},
|
|
56
76
|
// styles: {
|
|
57
77
|
// button: {
|
|
@@ -4,6 +4,7 @@ import {useRootTheme} from './useRootTheme'
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @public
|
|
7
|
+
* @deprecated
|
|
7
8
|
*/
|
|
8
9
|
export interface ThemeColorProviderProps {
|
|
9
10
|
children?: React.ReactNode
|
|
@@ -13,6 +14,7 @@ export interface ThemeColorProviderProps {
|
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @public
|
|
17
|
+
* @deprecated Use `toneContext` instead.
|
|
16
18
|
*/
|
|
17
19
|
export function ThemeColorProvider(props: ThemeColorProviderProps): React.ReactElement {
|
|
18
20
|
const {children, scheme, tone} = props
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import {useContext, useMemo} from 'react'
|
|
2
|
-
import {ThemeProvider as StyledThemeProvider} from 'styled-components'
|
|
2
|
+
import {ThemeProvider as StyledThemeProvider, createGlobalStyle} from 'styled-components'
|
|
3
3
|
import {DEFAULT_THEME_LAYER} from './defaults'
|
|
4
|
-
import {
|
|
4
|
+
import {ThemeColorName, ThemeColorSchemeKey} from './lib/theme'
|
|
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'
|
|
5
8
|
import {ThemeContext} from './themeContext'
|
|
9
|
+
import {ToneProvider} from './toneContext/toneProvider'
|
|
6
10
|
import {RootTheme, Theme, ThemeContextValue} from './types'
|
|
7
11
|
|
|
12
|
+
const GlobalVariables = createGlobalStyle<{$vars?: string}>`
|
|
13
|
+
:root {
|
|
14
|
+
${({$vars}) => $vars}
|
|
15
|
+
}
|
|
16
|
+
`
|
|
17
|
+
|
|
8
18
|
/**
|
|
9
19
|
* @public
|
|
10
20
|
*/
|
|
@@ -30,13 +40,12 @@ export function ThemeProvider(props: ThemeProviderProps): React.ReactElement {
|
|
|
30
40
|
const theme: Theme | null = useMemo(() => {
|
|
31
41
|
if (!themeProp) return null
|
|
32
42
|
|
|
33
|
-
const {
|
|
34
|
-
|
|
35
|
-
const color = colorScheme[tone] || colorScheme.default
|
|
43
|
+
const {layer: rootLayer, ...restTheme} = themeProp
|
|
44
|
+
|
|
36
45
|
const layer = rootLayer || DEFAULT_THEME_LAYER
|
|
37
46
|
|
|
38
|
-
return {sanity: {...restTheme, color,
|
|
39
|
-
}, [
|
|
47
|
+
return {sanity: {...restTheme, layer, color: {...legacyColors, tones: restTheme.color.tones}}}
|
|
48
|
+
}, [themeProp])
|
|
40
49
|
|
|
41
50
|
const value: ThemeContextValue | null = useMemo(
|
|
42
51
|
() =>
|
|
@@ -49,13 +58,24 @@ export function ThemeProvider(props: ThemeProviderProps): React.ReactElement {
|
|
|
49
58
|
[themeProp, scheme, tone],
|
|
50
59
|
)
|
|
51
60
|
|
|
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
|
+
|
|
52
67
|
if (!theme) {
|
|
53
68
|
return <pre>ThemeProvider: no "theme" property provided</pre>
|
|
54
69
|
}
|
|
55
70
|
|
|
56
71
|
return (
|
|
57
72
|
<ThemeContext.Provider value={value}>
|
|
58
|
-
<
|
|
73
|
+
<GlobalVariables $vars={cssVariables} />
|
|
74
|
+
<StyledThemeProvider theme={theme}>
|
|
75
|
+
<ToneProvider tone={tone} scheme={scheme}>
|
|
76
|
+
{children}
|
|
77
|
+
</ToneProvider>
|
|
78
|
+
</StyledThemeProvider>
|
|
59
79
|
</ThemeContext.Provider>
|
|
60
80
|
)
|
|
61
81
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
import {ThemeColorName, ThemeColorSchemeKey, useRootTheme} from '..'
|
|
3
|
+
import {ToneContext} from './toneContext'
|
|
4
|
+
import {ToneContextValue} from './types'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ToneProviderProps {
|
|
10
|
+
children?: React.ReactNode
|
|
11
|
+
scheme?: ThemeColorSchemeKey
|
|
12
|
+
tone: ThemeColorName
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export function ToneProvider(props: ToneProviderProps): React.ReactElement {
|
|
19
|
+
const {children, scheme, tone} = props
|
|
20
|
+
const root = useRootTheme()
|
|
21
|
+
const value: ToneContextValue = useMemo(
|
|
22
|
+
() => ({
|
|
23
|
+
version: 0.0,
|
|
24
|
+
scheme: scheme || root.scheme,
|
|
25
|
+
tone,
|
|
26
|
+
}),
|
|
27
|
+
[root.scheme, scheme, tone],
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return <ToneContext.Provider value={value}>{children}</ToneContext.Provider>
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import {useContext} from 'react'
|
|
3
|
+
|
|
4
|
+
import {isRecord} from '../../lib/isRecord'
|
|
5
|
+
import {ToneContext} from './toneContext'
|
|
6
|
+
import {ToneContextValue} from './types'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export function useToneContext(): ToneContextValue {
|
|
12
|
+
const value: unknown = useContext(ToneContext)
|
|
13
|
+
|
|
14
|
+
if (!value) {
|
|
15
|
+
throw new Error('useToneContext(): missing context value')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// NOTE: This check is for future-compatiblity
|
|
19
|
+
// - If the value is not an object, it’s not compatible with the current version
|
|
20
|
+
// - If the value is an object, but doesn’t have `version: 0.0`, it’s not compatible with the current version
|
|
21
|
+
if (!isRecord(value) || value.version !== 0.0) {
|
|
22
|
+
throw new Error('useToneContext(): the context value is not compatible')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return value as any as ToneContextValue
|
|
26
|
+
}
|
package/src/theme/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {CSSObject} from '../types/styled'
|
|
2
|
-
import {BaseTheme,
|
|
2
|
+
import {BaseTheme, ThemeColorName, ThemeColorSchemeKey} from './lib/theme'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
@@ -23,9 +23,7 @@ export interface Styles {
|
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
25
|
export interface Theme {
|
|
26
|
-
sanity:
|
|
27
|
-
color: ThemeColor
|
|
28
|
-
}
|
|
26
|
+
sanity: RootTheme
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
/**
|
|
@@ -37,3 +35,11 @@ export interface ThemeContextValue {
|
|
|
37
35
|
theme: RootTheme
|
|
38
36
|
tone: ThemeColorName
|
|
39
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export interface FocusRing {
|
|
43
|
+
offset: number
|
|
44
|
+
width: number
|
|
45
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
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'
|
|
3
4
|
|
|
4
5
|
const TestCard = styled(Card)`
|
|
5
|
-
|
|
6
|
+
${mutableCardVariables['fg-color']}: orange;
|
|
6
7
|
|
|
7
8
|
[data-eq-min~='0'] > & {
|
|
8
|
-
|
|
9
|
+
${mutableCardVariables['fg-color']}: green;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
[data-eq-min~='1'] > & {
|
|
12
|
-
|
|
13
|
+
${mutableCardVariables['fg-color']}: blue;
|
|
13
14
|
}
|
|
14
15
|
`
|
|
15
16
|
|