@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.
Files changed (137) hide show
  1. package/dist/index.cjs.mjs +3 -0
  2. package/dist/index.d.ts +339 -415
  3. package/dist/index.esm.js +5374 -2489
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +5375 -2487
  6. package/dist/index.js.map +1 -1
  7. package/package.json +21 -3
  8. package/src/components/autocomplete/autocomplete.tsx +2 -1
  9. package/src/components/dialog/constants.ts +4 -0
  10. package/src/components/dialog/dialog.tsx +89 -27
  11. package/src/components/dialog/styles.ts +3 -4
  12. package/src/components/hotkeys/hotkeys.tsx +2 -1
  13. package/src/components/menu/__workshop__/closableMenuButton.tsx +2 -2
  14. package/src/components/menu/menuButton.tsx +2 -2
  15. package/src/components/menu/menuDivider.ts +2 -1
  16. package/src/components/menu/menuGroup.tsx +24 -25
  17. package/src/components/menu/menuItem.tsx +31 -37
  18. package/src/components/skeleton/styles.ts +8 -7
  19. package/src/components/tab/tab.tsx +2 -1
  20. package/src/components/tree/style.ts +19 -20
  21. package/src/primitives/_selectable/style.ts +25 -23
  22. package/src/primitives/avatar/avatar.tsx +8 -3
  23. package/src/primitives/avatar/avatarCounter.tsx +5 -4
  24. package/src/primitives/avatar/spotColors.ts +53 -0
  25. package/src/primitives/avatar/styles.ts +6 -8
  26. package/src/primitives/avatar/types.ts +14 -0
  27. package/src/primitives/badge/badge.tsx +5 -3
  28. package/src/primitives/badge/styles.ts +7 -8
  29. package/src/primitives/box/__workshop__/responsive.tsx +2 -2
  30. package/src/primitives/button/__workshop__/sanityUploadButton.tsx +1 -2
  31. package/src/primitives/button/button.tsx +8 -9
  32. package/src/primitives/button/styles.ts +100 -17
  33. package/src/primitives/card/__workshop__/selected.tsx +8 -9
  34. package/src/primitives/card/card.tsx +43 -7
  35. package/src/primitives/card/styles.ts +31 -24
  36. package/src/primitives/card/types.ts +3 -1
  37. package/src/primitives/checkbox/checkbox.tsx +1 -0
  38. package/src/primitives/checkbox/styles.ts +53 -23
  39. package/src/primitives/code/code.tsx +15 -3
  40. package/src/primitives/code/styles.ts +51 -42
  41. package/src/primitives/heading/styles.ts +6 -5
  42. package/src/primitives/kbd/kbd.tsx +7 -6
  43. package/src/primitives/label/styles.ts +3 -2
  44. package/src/primitives/popover/popoverArrow.tsx +3 -2
  45. package/src/primitives/popover/popoverCard.tsx +8 -4
  46. package/src/primitives/radio/radio.tsx +1 -0
  47. package/src/primitives/radio/styles.ts +26 -13
  48. package/src/primitives/select/select.tsx +3 -2
  49. package/src/primitives/select/styles.ts +22 -24
  50. package/src/primitives/switch/__workshop__/props.tsx +4 -4
  51. package/src/primitives/switch/styles.ts +19 -12
  52. package/src/primitives/text/__workshop__/colored.tsx +10 -11
  53. package/src/primitives/text/styles.ts +10 -8
  54. package/src/primitives/textArea/textArea.tsx +8 -12
  55. package/src/primitives/textInput/textInput.tsx +15 -14
  56. package/src/primitives/tooltip/__workshop__/props.tsx +20 -3
  57. package/src/primitives/tooltip/tooltip.tsx +2 -2
  58. package/src/primitives/tooltip/tooltipArrow.tsx +3 -2
  59. package/src/primitives/types.ts +3 -2
  60. package/src/styles/border/borderStyle.ts +2 -1
  61. package/src/styles/colorVars/colorVarsStyle.ts +73 -30
  62. package/src/styles/focusRing/index.ts +8 -4
  63. package/src/styles/input/textInputStyle.ts +78 -94
  64. package/src/styles/margin/marginsStyle.test.ts +1 -2
  65. package/src/styles/padding/paddingStyle.test.ts +1 -2
  66. package/src/styles/radius/radiusStyle.ts +14 -4
  67. package/src/styles/radius/types.ts +3 -1
  68. package/src/styles/shadow/shadowStyle.ts +5 -5
  69. package/src/theme/__workshop__/color.tsx +2 -2
  70. package/src/theme/__workshop__/index.ts +0 -5
  71. package/src/theme/lib/color-fns/blend/multiply.ts +2 -2
  72. package/src/theme/lib/color-fns/blend/screen.ts +2 -2
  73. package/src/theme/lib/color-fns/convert.ts +15 -1
  74. package/src/theme/lib/color-fns/parse.ts +7 -3
  75. package/src/theme/lib/color-fns/types.ts +11 -0
  76. package/src/theme/lib/theme/avatar.ts +3 -0
  77. package/src/theme/lib/theme/color/_legacy/createColorTheme.ts +7 -0
  78. package/src/theme/lib/theme/color/_legacy/index.ts +1 -0
  79. package/src/theme/lib/theme/color/_legacy/legacyColor.ts +3997 -0
  80. package/src/theme/lib/theme/color/cssVariables/cardVariables.ts +88 -0
  81. package/src/theme/lib/theme/color/cssVariables/createCssVars.ts +31 -0
  82. package/src/theme/lib/theme/color/cssVariables/cssVars.test.ts +262 -0
  83. package/src/theme/lib/theme/color/cssVariables/index.ts +1 -0
  84. package/src/theme/lib/theme/color/cssVariables/tints.ts +312 -0
  85. package/src/theme/lib/theme/color/cssVariables/tones.ts +67 -0
  86. package/src/theme/lib/theme/color/cssVariables/utils.test.ts +15 -0
  87. package/src/theme/lib/theme/color/cssVariables/utils.ts +9 -0
  88. package/src/theme/lib/theme/color/index.ts +3 -12
  89. package/src/theme/lib/theme/color/types.ts +6 -37
  90. package/src/theme/lib/theme/input.ts +11 -0
  91. package/src/theme/lib/theme/theme.ts +7 -1
  92. package/src/theme/studioTheme/color.ts +6 -633
  93. package/src/theme/studioTheme/fonts.ts +3 -3
  94. package/src/theme/studioTheme/helpers.ts +15 -1
  95. package/src/theme/studioTheme/theme.ts +26 -6
  96. package/src/theme/themeColorProvider.tsx +2 -0
  97. package/src/theme/themeProvider.tsx +28 -8
  98. package/src/theme/toneContext/toneContext.ts +12 -0
  99. package/src/theme/toneContext/toneProvider.tsx +31 -0
  100. package/src/theme/toneContext/types.ts +10 -0
  101. package/src/theme/toneContext/useToneContext.tsx +26 -0
  102. package/src/theme/types.ts +10 -4
  103. package/src/types/index.ts +1 -0
  104. package/src/types/radius.ts +4 -0
  105. package/src/utils/elementQuery/__workshop__/customMedia.tsx +4 -3
  106. package/src/theme/__workshop__/canvas.tsx +0 -395
  107. package/src/theme/lib/theme/color/_generic/index.ts +0 -1
  108. package/src/theme/lib/theme/color/_generic/types.ts +0 -29
  109. package/src/theme/lib/theme/color/base/index.ts +0 -1
  110. package/src/theme/lib/theme/color/base/types.ts +0 -19
  111. package/src/theme/lib/theme/color/button/createButtonModes.ts +0 -20
  112. package/src/theme/lib/theme/color/button/createButtonTones.ts +0 -52
  113. package/src/theme/lib/theme/color/button/index.ts +0 -1
  114. package/src/theme/lib/theme/color/button/types.ts +0 -44
  115. package/src/theme/lib/theme/color/card/createCardStates.ts +0 -58
  116. package/src/theme/lib/theme/color/card/index.ts +0 -1
  117. package/src/theme/lib/theme/color/card/types.ts +0 -18
  118. package/src/theme/lib/theme/color/color.test.ts +0 -62
  119. package/src/theme/lib/theme/color/defaults.ts +0 -382
  120. package/src/theme/lib/theme/color/factory.ts +0 -138
  121. package/src/theme/lib/theme/color/input/createInputModes.ts +0 -84
  122. package/src/theme/lib/theme/color/input/index.ts +0 -1
  123. package/src/theme/lib/theme/color/input/types.ts +0 -27
  124. package/src/theme/lib/theme/color/muted/createMuted.ts +0 -56
  125. package/src/theme/lib/theme/color/muted/index.ts +0 -1
  126. package/src/theme/lib/theme/color/muted/types.ts +0 -24
  127. package/src/theme/lib/theme/color/selectable/createSelectableTones.ts +0 -73
  128. package/src/theme/lib/theme/color/selectable/index.ts +0 -1
  129. package/src/theme/lib/theme/color/selectable/types.ts +0 -29
  130. package/src/theme/lib/theme/color/solid/createSolidTones.ts +0 -56
  131. package/src/theme/lib/theme/color/solid/index.ts +0 -1
  132. package/src/theme/lib/theme/color/solid/types.ts +0 -24
  133. package/src/theme/lib/theme/color/spot/createSpot.ts +0 -21
  134. package/src/theme/lib/theme/color/spot/index.ts +0 -1
  135. package/src/theme/lib/theme/color/spot/types.ts +0 -28
  136. package/src/theme/lib/theme/color/syntax/index.ts +0 -1
  137. package/src/theme/lib/theme/color/syntax/types.ts +0 -41
@@ -1,5 +1,5 @@
1
1
  import {RootTheme} from '../types'
2
- import {color} from './color'
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, -1], penumbra: [0, 6, 10, 0], ambient: [0, 1, 18, 0]},
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: 33,
47
- height: 17,
48
- padding: 4,
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 {ThemeColorSchemeKey, ThemeColorName} from './lib/theme'
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 {color: rootColor, layer: rootLayer, ...restTheme} = themeProp
34
- const colorScheme = rootColor[scheme] || rootColor.light
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, layer}}
39
- }, [scheme, themeProp, tone])
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
- <StyledThemeProvider theme={theme}>{children}</StyledThemeProvider>
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,10 @@
1
+ import {ThemeColorName, ThemeColorSchemeKey} from '..'
2
+
3
+ /**
4
+ * @public
5
+ */
6
+ export interface ToneContextValue {
7
+ version: 0.0
8
+ scheme: ThemeColorSchemeKey
9
+ tone: ThemeColorName
10
+ }
@@ -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
+ }
@@ -1,5 +1,5 @@
1
1
  import {CSSObject} from '../types/styled'
2
- import {BaseTheme, ThemeColor, ThemeColorName, ThemeColorSchemeKey} from './lib/theme'
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: Omit<RootTheme, 'color'> & {
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
+ }
@@ -9,6 +9,7 @@ export * from './grid'
9
9
  export * from './gridItem'
10
10
  export * from './placement'
11
11
  export * from './popover'
12
+ export * from './radius'
12
13
  export * from './selectable'
13
14
  export * from './styled'
14
15
  export * from './text'
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export type Radius = number | 'full'
@@ -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
- --card-fg-color: orange;
6
+ ${mutableCardVariables['fg-color']}: orange;
6
7
 
7
8
  [data-eq-min~='0'] > & {
8
- --card-fg-color: green;
9
+ ${mutableCardVariables['fg-color']}: green;
9
10
  }
10
11
 
11
12
  [data-eq-min~='1'] > & {
12
- --card-fg-color: blue;
13
+ ${mutableCardVariables['fg-color']}: blue;
13
14
  }
14
15
  `
15
16