@sanity/ui 2.0.0-alpha.1 → 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 (120) hide show
  1. package/dist/index.cjs.mjs +3 -0
  2. package/dist/index.d.ts +309 -411
  3. package/dist/index.esm.js +5098 -2428
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +5230 -2557
  6. package/dist/index.js.map +1 -1
  7. package/package.json +2 -2
  8. package/src/components/dialog/constants.ts +4 -0
  9. package/src/components/dialog/dialog.tsx +86 -24
  10. package/src/components/dialog/styles.ts +3 -4
  11. package/src/components/menu/__workshop__/closableMenuButton.tsx +2 -2
  12. package/src/components/menu/menuDivider.ts +2 -1
  13. package/src/components/menu/menuGroup.tsx +22 -23
  14. package/src/components/menu/menuItem.tsx +31 -37
  15. package/src/components/skeleton/styles.ts +8 -7
  16. package/src/components/tree/style.ts +19 -20
  17. package/src/primitives/_selectable/style.ts +25 -22
  18. package/src/primitives/avatar/avatar.tsx +8 -3
  19. package/src/primitives/avatar/avatarCounter.tsx +5 -4
  20. package/src/primitives/avatar/spotColors.ts +53 -0
  21. package/src/primitives/avatar/styles.ts +5 -7
  22. package/src/primitives/avatar/types.ts +14 -0
  23. package/src/primitives/badge/badge.tsx +5 -3
  24. package/src/primitives/badge/styles.ts +7 -8
  25. package/src/primitives/box/__workshop__/responsive.tsx +2 -2
  26. package/src/primitives/button/button.tsx +2 -2
  27. package/src/primitives/button/styles.ts +82 -16
  28. package/src/primitives/card/__workshop__/selected.tsx +8 -9
  29. package/src/primitives/card/card.tsx +43 -7
  30. package/src/primitives/card/styles.ts +30 -22
  31. package/src/primitives/card/types.ts +3 -1
  32. package/src/primitives/checkbox/styles.ts +20 -20
  33. package/src/primitives/code/code.tsx +15 -3
  34. package/src/primitives/code/styles.ts +51 -42
  35. package/src/primitives/heading/styles.ts +6 -5
  36. package/src/primitives/kbd/kbd.tsx +2 -1
  37. package/src/primitives/label/styles.ts +3 -2
  38. package/src/primitives/popover/popoverArrow.tsx +3 -2
  39. package/src/primitives/popover/popoverCard.tsx +6 -2
  40. package/src/primitives/radio/styles.ts +15 -15
  41. package/src/primitives/select/styles.ts +20 -22
  42. package/src/primitives/switch/styles.ts +13 -13
  43. package/src/primitives/text/__workshop__/colored.tsx +10 -11
  44. package/src/primitives/text/styles.ts +10 -9
  45. package/src/primitives/textArea/textArea.tsx +8 -12
  46. package/src/primitives/textInput/textInput.tsx +13 -13
  47. package/src/primitives/tooltip/__workshop__/props.tsx +20 -3
  48. package/src/primitives/tooltip/tooltipArrow.tsx +3 -2
  49. package/src/styles/border/borderStyle.ts +2 -1
  50. package/src/styles/colorVars/colorVarsStyle.ts +73 -32
  51. package/src/styles/focusRing/index.ts +6 -4
  52. package/src/styles/input/textInputStyle.ts +76 -93
  53. package/src/styles/margin/marginsStyle.test.ts +1 -2
  54. package/src/styles/padding/paddingStyle.test.ts +1 -2
  55. package/src/styles/shadow/shadowStyle.ts +5 -5
  56. package/src/theme/__workshop__/color.tsx +2 -2
  57. package/src/theme/__workshop__/index.ts +0 -5
  58. package/src/theme/lib/color-fns/blend/multiply.ts +2 -2
  59. package/src/theme/lib/color-fns/blend/screen.ts +2 -2
  60. package/src/theme/lib/color-fns/convert.ts +15 -1
  61. package/src/theme/lib/color-fns/parse.ts +7 -3
  62. package/src/theme/lib/color-fns/types.ts +11 -0
  63. package/src/theme/lib/theme/color/_legacy/createColorTheme.ts +7 -0
  64. package/src/theme/lib/theme/color/_legacy/index.ts +1 -0
  65. package/src/theme/lib/theme/color/_legacy/legacyColor.ts +3997 -0
  66. package/src/theme/lib/theme/color/cssVariables/cardVariables.ts +88 -0
  67. package/src/theme/lib/theme/color/cssVariables/createCssVars.ts +31 -0
  68. package/src/theme/lib/theme/color/cssVariables/cssVars.test.ts +262 -0
  69. package/src/theme/lib/theme/color/cssVariables/index.ts +1 -0
  70. package/src/theme/lib/theme/color/cssVariables/tints.ts +312 -0
  71. package/src/theme/lib/theme/color/cssVariables/tones.ts +67 -0
  72. package/src/theme/lib/theme/color/cssVariables/utils.test.ts +15 -0
  73. package/src/theme/lib/theme/color/cssVariables/utils.ts +9 -0
  74. package/src/theme/lib/theme/color/index.ts +3 -12
  75. package/src/theme/lib/theme/color/types.ts +6 -37
  76. package/src/theme/lib/theme/theme.ts +9 -4
  77. package/src/theme/studioTheme/color.ts +2 -641
  78. package/src/theme/studioTheme/helpers.ts +15 -1
  79. package/src/theme/studioTheme/theme.ts +13 -3
  80. package/src/theme/themeColorProvider.tsx +2 -0
  81. package/src/theme/themeProvider.tsx +28 -8
  82. package/src/theme/toneContext/toneContext.ts +12 -0
  83. package/src/theme/toneContext/toneProvider.tsx +31 -0
  84. package/src/theme/toneContext/types.ts +10 -0
  85. package/src/theme/toneContext/useToneContext.tsx +26 -0
  86. package/src/theme/types.ts +2 -4
  87. package/src/utils/elementQuery/__workshop__/customMedia.tsx +4 -3
  88. package/src/theme/__workshop__/canvas.tsx +0 -395
  89. package/src/theme/lib/theme/color/_generic/index.ts +0 -1
  90. package/src/theme/lib/theme/color/_generic/types.ts +0 -30
  91. package/src/theme/lib/theme/color/base/index.ts +0 -1
  92. package/src/theme/lib/theme/color/base/types.ts +0 -19
  93. package/src/theme/lib/theme/color/button/createButtonModes.ts +0 -20
  94. package/src/theme/lib/theme/color/button/createButtonTones.ts +0 -52
  95. package/src/theme/lib/theme/color/button/index.ts +0 -1
  96. package/src/theme/lib/theme/color/button/types.ts +0 -44
  97. package/src/theme/lib/theme/color/card/createCardStates.ts +0 -58
  98. package/src/theme/lib/theme/color/card/index.ts +0 -1
  99. package/src/theme/lib/theme/color/card/types.ts +0 -18
  100. package/src/theme/lib/theme/color/color.test.ts +0 -63
  101. package/src/theme/lib/theme/color/defaults.ts +0 -390
  102. package/src/theme/lib/theme/color/factory.ts +0 -138
  103. package/src/theme/lib/theme/color/input/createInputModes.ts +0 -84
  104. package/src/theme/lib/theme/color/input/index.ts +0 -1
  105. package/src/theme/lib/theme/color/input/types.ts +0 -28
  106. package/src/theme/lib/theme/color/muted/createMuted.ts +0 -56
  107. package/src/theme/lib/theme/color/muted/index.ts +0 -1
  108. package/src/theme/lib/theme/color/muted/types.ts +0 -24
  109. package/src/theme/lib/theme/color/selectable/createSelectableTones.ts +0 -73
  110. package/src/theme/lib/theme/color/selectable/index.ts +0 -1
  111. package/src/theme/lib/theme/color/selectable/types.ts +0 -29
  112. package/src/theme/lib/theme/color/solid/createSolidTones.ts +0 -56
  113. package/src/theme/lib/theme/color/solid/index.ts +0 -1
  114. package/src/theme/lib/theme/color/solid/types.ts +0 -24
  115. package/src/theme/lib/theme/color/spot/createSpot.ts +0 -21
  116. package/src/theme/lib/theme/color/spot/index.ts +0 -1
  117. package/src/theme/lib/theme/color/spot/types.ts +0 -28
  118. package/src/theme/lib/theme/color/syntax/index.ts +0 -1
  119. package/src/theme/lib/theme/color/syntax/types.ts +0 -41
  120. package/src/theme/studioTheme/tints.ts +0 -152
@@ -1,13 +1,19 @@
1
1
  import {css} from 'styled-components'
2
2
  import {ThemeProps} from '../../styles'
3
- import {_colorVarsStyle} from '../../styles/colorVars'
4
- import {SelectableTone} from '../../types/selectable'
3
+ import {
4
+ _colorVarStyleHover,
5
+ _selectableVarStyle,
6
+ _selectableVarStyleDisabled,
7
+ } from '../../styles/colorVars'
8
+
9
+ import {ThemeColorSchemeKey, ThemeColorToneKey, createCssVars, cssVars} from '../../theme'
5
10
 
6
11
  /**
7
12
  * @internal
8
13
  */
9
14
  export interface SelectableStyleProps {
10
- $tone: SelectableTone
15
+ $tone: ThemeColorToneKey
16
+ $scheme: ThemeColorSchemeKey
11
17
  }
12
18
 
13
19
  export function selectableBaseStyle(): ReturnType<typeof css> {
@@ -35,43 +41,41 @@ export function selectableBaseStyle(): ReturnType<typeof css> {
35
41
  export function selectableColorStyle(
36
42
  props: SelectableStyleProps & ThemeProps,
37
43
  ): ReturnType<typeof css> {
38
- const {$tone, theme} = props
39
- const {base, muted, selectable} = theme.sanity.color
40
- // @todo: remove use of `muted` here
41
- const tone = selectable ? selectable[$tone] || selectable.default : muted[$tone] || muted.default
44
+ const {theme, $tone, $scheme} = props
42
45
 
43
46
  return css`
44
- ${_colorVarsStyle(base, tone.enabled)}
47
+ ${$tone !== 'default' && createCssVars($scheme, theme.sanity.color.tones, $tone)}
48
+ ${_selectableVarStyle($tone)}
45
49
 
46
- background-color: var(--card-bg-color);
47
- color: var(--card-fg-color);
50
+ background-color: ${cssVars.mutable['bg-color']};
51
+ color: ${cssVars[$tone]['text-secondary']};
48
52
  outline: none;
49
53
 
50
- /* &:is(button) */
54
+ /* &:is(button) - Looks like a button in default mode */
51
55
  &[data-as='button'] {
52
56
  &:disabled {
53
- ${_colorVarsStyle(base, tone.disabled)}
57
+ ${_selectableVarStyleDisabled()}
54
58
  }
55
59
 
56
60
  &:not(:disabled) {
57
61
  &[aria-pressed='true'] {
58
- ${_colorVarsStyle(base, tone.pressed)}
62
+ ${_colorVarStyleHover()}
59
63
  }
60
64
 
61
65
  &[data-selected],
62
66
  &[aria-selected='true'] > & {
63
- ${_colorVarsStyle(base, tone.selected)}
67
+ ${_colorVarStyleHover()}
64
68
  }
65
69
 
66
70
  @media (hover: hover) {
67
71
  &:not([data-selected]) {
68
72
  &[data-hovered],
69
73
  &:hover {
70
- ${_colorVarsStyle(base, tone.hovered)}
74
+ ${_colorVarStyleHover()}
71
75
  }
72
76
 
73
77
  &:active {
74
- ${_colorVarsStyle(base, tone.pressed)}
78
+ ${_colorVarStyleHover()}
75
79
  }
76
80
  }
77
81
  }
@@ -81,27 +85,26 @@ export function selectableColorStyle(
81
85
  /* &:is(a) */
82
86
  &[data-as='a'] {
83
87
  &[data-disabled] {
84
- ${_colorVarsStyle(base, tone.disabled)}
88
+ ${_selectableVarStyleDisabled()}
85
89
  }
86
90
 
87
91
  &:not([data-disabled]) {
88
92
  &[data-pressed] {
89
- ${_colorVarsStyle(base, tone.pressed)}
93
+ ${_colorVarStyleHover()}
90
94
  }
91
95
 
92
96
  &[data-selected] {
93
- ${_colorVarsStyle(base, tone.selected)}
97
+ ${_colorVarStyleHover()}
94
98
  }
95
99
 
96
100
  @media (hover: hover) {
97
101
  &:not([data-selected]) {
98
102
  &[data-hovered],
99
103
  &:hover {
100
- ${_colorVarsStyle(base, tone.hovered)}
104
+ ${_colorVarStyleHover()}
101
105
  }
102
-
103
106
  &:active {
104
- ${_colorVarsStyle(base, tone.pressed)}
107
+ ${_colorVarStyleHover()}
105
108
  }
106
109
  }
107
110
  }
@@ -2,10 +2,14 @@ import {forwardRef, useCallback, useEffect, useId, useMemo, useState} from 'reac
2
2
  import ReactIs from 'react-is'
3
3
  import styled from 'styled-components'
4
4
  import {useArrayProp} from '../../hooks'
5
- import {ThemeColorSpotKey, useTheme} from '../../theme'
5
+ import {useTheme} from '../../theme'
6
+
7
+ import {useToneContext} from '../../theme/toneContext/useToneContext'
6
8
  import {AvatarPosition, AvatarSize, AvatarStatus} from '../../types'
7
9
  import {Text} from '../text'
10
+ import {spotColor} from './spotColors'
8
11
  import {avatarStyle, responsiveAvatarSizeStyle} from './styles'
12
+ import {ThemeColorSpotKey} from './types'
9
13
 
10
14
  /**
11
15
  * @public
@@ -63,9 +67,10 @@ export const Avatar = forwardRef(function Avatar(
63
67
  const as = ReactIs.isValidElementType(asProp) ? asProp : 'div'
64
68
  const size = useArrayProp(sizeProp)
65
69
  const theme = useTheme()
66
- const color = theme.sanity.color.spot[colorKey] || theme.sanity.color.spot.gray
70
+ const {scheme} = useToneContext()
71
+
72
+ const color = spotColor[colorKey][scheme].hex
67
73
 
68
- // @todo: remove this
69
74
  const avatarSize = theme.sanity.avatar.sizes[size[0]] || theme.sanity.avatar.sizes[0]
70
75
  const _sizeRem = avatarSize.size
71
76
  const _radius = _sizeRem / 2
@@ -3,6 +3,7 @@ import styled, {css} from 'styled-components'
3
3
  import {EMPTY_RECORD} from '../../constants'
4
4
  import {useArrayProp} from '../../hooks'
5
5
  import {rem, _responsive, ThemeProps} from '../../styles'
6
+ import {cssVars} from '../../theme'
6
7
  import {AvatarSize} from '../../types'
7
8
  import {Text} from '../text'
8
9
 
@@ -32,11 +33,11 @@ function _avatarCounterBaseStyle(props: ThemeProps) {
32
33
  box-sizing: border-box;
33
34
  user-select: none;
34
35
  color: inherit;
35
- color: var(--card-fg-color);
36
- background: var(--card-bg-color);
36
+ color: ${cssVars.mutable['fg-color']};
37
+ background: ${cssVars.mutable['bg-color']};
37
38
  box-shadow:
38
- 0 0 0 1px var(--card-bg-color),
39
- inset 0 0 0 1.5px var(--card-hairline-hard-color);
39
+ 0 0 0 1px ${cssVars.mutable['bg-color']},
40
+ inset 0 0 0 1.5px ${cssVars.default['border-base']});
40
41
  padding: 0 ${rem(theme.sanity.space[2])};
41
42
 
42
43
  &:not([hidden]) {
@@ -0,0 +1,53 @@
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,5 +1,6 @@
1
1
  import {rem, _responsive, ThemeProps} from '../../styles'
2
2
  import {focusRingStyle} from '../../styles/internal'
3
+ import {cssVars} from '../../theme/lib/theme/color/cssVariables/createCssVars'
3
4
  import {CSSObject} from '../../types/styled'
4
5
  import {AvatarRootStyleProps, ResponsiveAvatarSizeStyleProps} from './types'
5
6
 
@@ -64,7 +65,7 @@ export function avatarRootStyle(props: AvatarRootStyleProps & ThemeProps): CSSOb
64
65
  position: 'relative',
65
66
  boxSizing: 'border-box',
66
67
  userSelect: 'none',
67
- boxShadow: '0 0 0 1px var(--card-bg-color)',
68
+ boxShadow: `0 0 0 1px ${cssVars.mutable['bg-color']}`,
68
69
 
69
70
  '&[data-status="inactive"]': {
70
71
  opacity: 0.5,
@@ -123,14 +124,11 @@ export function responsiveAvatarSizeStyle(
123
124
  })
124
125
  }
125
126
 
126
- export function avatarInitialsStyle(props: ThemeProps): CSSObject {
127
- const {theme} = props
128
- const {base} = theme.sanity.color
129
-
127
+ export function avatarInitialsStyle(): CSSObject {
130
128
  return {
131
129
  width: '100%',
132
130
  height: '100%',
133
- color: base.fg,
131
+ color: cssVars.default['text-primary'],
134
132
  alignItems: 'center',
135
133
  justifyContent: 'center',
136
134
  textTransform: 'uppercase',
@@ -146,7 +144,7 @@ export function avatarInitialsStyle(props: ThemeProps): CSSObject {
146
144
  function avatarBgStrokeStyle(): CSSObject {
147
145
  return {
148
146
  strokeWidth: '4px',
149
- stroke: 'var(--card-bg-color)',
147
+ stroke: cssVars.mutable['bg-color'],
150
148
  }
151
149
  }
152
150
 
@@ -13,3 +13,17 @@ export interface AvatarRootStyleProps {
13
13
  export interface ResponsiveAvatarSizeStyleProps {
14
14
  $size: AvatarSize[]
15
15
  }
16
+
17
+ /**
18
+ * @public
19
+ */
20
+ export type ThemeColorSpotKey =
21
+ | 'gray'
22
+ | 'blue'
23
+ | 'purple'
24
+ | 'magenta'
25
+ | 'red'
26
+ | 'orange'
27
+ | 'yellow'
28
+ | 'green'
29
+ | 'cyan'
@@ -4,7 +4,7 @@ import {useArrayProp} from '../../hooks'
4
4
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
5
5
  import {BadgeMode, BadgeTone} from '../../types'
6
6
  import {Box, BoxProps} from '../box'
7
- import {Label} from '../label'
7
+ import {Text} from '../text'
8
8
  import {ResponsiveRadiusProps} from '../types'
9
9
  import {badgeStyle} from './styles'
10
10
  import {BadgeStyleProps} from './types'
@@ -33,7 +33,7 @@ export const Badge = forwardRef(function Badge(
33
33
  ) {
34
34
  const {
35
35
  children,
36
- fontSize,
36
+ fontSize = 1,
37
37
  mode = 'default',
38
38
  padding = 1,
39
39
  radius = 2,
@@ -51,7 +51,9 @@ export const Badge = forwardRef(function Badge(
51
51
  padding={useArrayProp(padding)}
52
52
  ref={ref}
53
53
  >
54
- <Label size={fontSize}>{children}</Label>
54
+ <Text size={fontSize} weight="medium">
55
+ {children}
56
+ </Text>
55
57
  </Root>
56
58
  )
57
59
  })
@@ -1,16 +1,15 @@
1
- import {ThemeProps} from '../../styles'
1
+ import {mutableCardVariables} from '../../theme/lib/theme/color/cssVariables/cardVariables'
2
+ import {cssVars} from '../../theme/lib/theme/color/cssVariables/createCssVars'
2
3
  import {CSSObject} from '../../types/styled'
3
4
  import {BadgeStyleProps} from './types'
4
5
 
5
- export function badgeStyle(props: BadgeStyleProps & ThemeProps): CSSObject {
6
- const {$mode, $tone, theme} = props
7
- const palette = theme.sanity.color[$mode === 'outline' ? 'muted' : 'solid']
8
- const color = palette[$tone] || palette.default
6
+ export function badgeStyle(props: BadgeStyleProps): CSSObject {
7
+ const {$mode, $tone} = props
9
8
 
10
9
  return {
11
- backgroundColor: color.enabled.bg,
12
- color: color.enabled.fg,
13
- boxShadow: `inset 0 0 0 1px ${color.enabled.border}`,
10
+ backgroundColor: $mode === 'outline' ? cssVars[$tone]['bg-base'] : cssVars[$tone]['bg-tint'],
11
+ [mutableCardVariables['fg-color']]: cssVars[$tone]['text-secondary'],
12
+ boxShadow: $mode === 'outline' ? `inset 0 0 0 1px ${cssVars[$tone]['border-base']}` : undefined,
14
13
  cursor: 'default',
15
14
 
16
15
  '&:not([hidden])': {
@@ -1,4 +1,4 @@
1
- import {Box, Text} from '@sanity/ui'
1
+ import {Box, Text, cssVars} from '@sanity/ui'
2
2
 
3
3
  export default function ResponsiveStory() {
4
4
  return (
@@ -9,7 +9,7 @@ export default function ResponsiveStory() {
9
9
  flex={[1, 2, 3, 4, 5, 6, 7]}
10
10
  padding={3}
11
11
  sizing={['content', 'border', 'content', 'border', 'content', 'border', 'content']}
12
- style={{outline: '1px solid var(--card-border-color)'}}
12
+ style={{outline: `1px solid ${cssVars.default['border-base']}`}}
13
13
  >
14
14
  <Text align="center" muted>
15
15
  This is a box with responsive props
@@ -4,7 +4,7 @@ import styled from 'styled-components'
4
4
  import {useArrayProp} from '../../hooks'
5
5
  import {ThemeProps} from '../../styles'
6
6
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
7
- import {useTheme} from '../../theme'
7
+ import {cssVars, useTheme} from '../../theme'
8
8
  import {ButtonMode, ButtonTextAlign, ButtonTone, FlexJustify} from '../../types'
9
9
  import {Box} from '../box'
10
10
  import {Flex} from '../flex'
@@ -49,7 +49,7 @@ const LoadingBox = styled.div`
49
49
  display: flex;
50
50
  align-items: center;
51
51
  justify-content: center;
52
- background-color: var(--card-bg-color);
52
+ background-color: ${cssVars.mutable['bg-color']};
53
53
  border-radius: inherit;
54
54
  z-index: 1;
55
55
  box-shadow: inherit;
@@ -1,7 +1,9 @@
1
1
  import {css} from 'styled-components'
2
2
  import {ThemeProps} from '../../styles'
3
- import {_colorVarsStyle} from '../../styles/colorVars'
4
3
  import {focusRingBorderStyle, focusRingStyle} from '../../styles/internal'
4
+ import {mutableCardVariables} from '../../theme/lib/theme/color/cssVariables/cardVariables'
5
+ import {cssVars} from '../../theme/lib/theme/color/cssVariables/createCssVars'
6
+ import {getToneCssVar} from '../../theme/lib/theme/color/cssVariables/tones'
5
7
  import {ButtonMode, ButtonTone} from '../../types'
6
8
  import {CSSObject} from '../../types/styled'
7
9
 
@@ -54,21 +56,65 @@ function combineBoxShadow(...boxShadows: (string | undefined)[]): string {
54
56
  export function buttonColorStyles(
55
57
  props: {$mode: ButtonMode; $tone: ButtonTone} & ThemeProps,
56
58
  ): CSSObject[] {
57
- const {$mode, theme} = props
59
+ const {$mode, theme, $tone} = props
58
60
  const {focusRing} = theme.sanity.button
59
61
  const shadow = props.$mode !== 'bleed'
60
- const base = theme.sanity.color.base
61
- const mode = theme.sanity.color.button[$mode] || theme.sanity.color.button.default
62
- const color = mode[props.$tone] || mode.default
63
- const border = {width: buttonTheme.border.width, color: 'var(--card-border-color)'}
62
+ const border = {
63
+ width: buttonTheme.border.width,
64
+ color:
65
+ $mode === 'default'
66
+ ? cssVars[$tone]['bg-accent']
67
+ : $mode === 'ghost'
68
+ ? cssVars[$tone]['border-base']
69
+ : cssVars[$tone]['bg-base'],
70
+ }
64
71
 
65
72
  return [
66
- _colorVarsStyle(base, color.enabled),
67
73
  {
68
- backgroundColor: 'var(--card-bg-color)',
69
- color: 'var(--card-fg-color)',
74
+ // This is going to be used by the text elements inside the button
75
+ [mutableCardVariables['fg-color']]:
76
+ $mode === 'default' ? cssVars[$tone]['base-text-color'] : cssVars[$tone]['text-primary'],
77
+ [mutableCardVariables['muted-fg-color']]:
78
+ $mode === 'default' ? cssVars[$tone]['base-text-color'] : cssVars[$tone]['text-secondary'],
79
+ [mutableCardVariables['icon-color']]:
80
+ $mode === 'default' ? cssVars[$tone]['icon-inverted'] : cssVars[$tone]['icon-default'],
81
+ [mutableCardVariables['bg-color']]:
82
+ $mode === 'default' ? cssVars[$tone]['bg-accent'] : cssVars[$tone]['bg-base'],
83
+
84
+ // Override the default variables for elements used inside buttons
85
+ [getToneCssVar('default', 'bg-tint-code')]:
86
+ $mode === 'default' ? cssVars[$tone]['bg-accent'] : cssVars[$tone]['bg-tint-code'],
87
+ ...($mode === 'default' && {
88
+ [getToneCssVar('default', 'text-code')]: cssVars[$tone]['base-text-color'],
89
+ [getToneCssVar('default', 'text-code')]: cssVars[$tone]['base-text-color'],
90
+ [getToneCssVar('default', 'text-link')]: cssVars[$tone]['base-text-color'],
91
+ [getToneCssVar('default', 'text-accent')]: cssVars[$tone]['base-text-color'],
92
+ }),
93
+
94
+ '&:disabled, &[data-disabled="true"]': {
95
+ /* Updates the variables for the */
96
+ [mutableCardVariables['fg-color']]: cssVars.primary['text-inactive'],
97
+ [mutableCardVariables['muted-fg-color']]: cssVars.primary['text-inactive'],
98
+ [mutableCardVariables['icon-color']]: cssVars.primary['border-base'],
99
+ [mutableCardVariables['bg-color']]:
100
+ $mode === 'default' ? cssVars.primary['bg-tint'] : cssVars.default['bg-base'],
101
+ },
102
+ },
103
+ {
104
+ backgroundColor:
105
+ $mode === 'default' ? cssVars[$tone]['bg-accent'] : cssVars[$tone]['bg-base'],
106
+ color:
107
+ $mode === 'default' ? cssVars[$tone]['base-text-color'] : cssVars[$tone]['text-primary'],
70
108
  boxShadow: focusRingBorderStyle(border),
71
- '&:disabled, &[data-disabled="true"]': _colorVarsStyle(base, color.disabled),
109
+ '&:disabled, &[data-disabled="true"]': {
110
+ backgroundColor:
111
+ $mode === 'default' ? cssVars.primary['bg-tint'] : cssVars.default['bg-base'],
112
+ color: cssVars.primary['text-inactive'],
113
+ boxShadow: focusRingBorderStyle({
114
+ ...border,
115
+ color: $mode === 'default' ? cssVars.primary['bg-tint'] : cssVars.primary['border-base'],
116
+ }),
117
+ },
72
118
  "&:not([data-disabled='true'])": {
73
119
  boxShadow: combineBoxShadow(
74
120
  focusRingBorderStyle(border),
@@ -76,8 +122,8 @@ export function buttonColorStyles(
76
122
  ),
77
123
  '&:focus': {
78
124
  boxShadow: focusRingStyle({
79
- base,
80
- border: {width: 2, color: base.bg},
125
+ base: {bg: cssVars.positive['border-accent']},
126
+ border: {width: 2, color: cssVars.default['bg-base']},
81
127
  focusRing,
82
128
  }),
83
129
  },
@@ -88,11 +134,31 @@ export function buttonColorStyles(
88
134
  ),
89
135
  },
90
136
  '@media (hover: hover)': {
91
- '&:hover': _colorVarsStyle(base, color.hovered),
92
- '&:active': _colorVarsStyle(base, color.pressed),
93
- '&[data-hovered]': _colorVarsStyle(base, color.hovered),
137
+ '&:hover': {
138
+ backgroundColor:
139
+ $mode === 'default'
140
+ ? cssVars[$tone]['bg-accent-hover']
141
+ : cssVars[$tone]['bg-base-hover'],
142
+ },
143
+ '&:active': {
144
+ backgroundColor:
145
+ $mode === 'default'
146
+ ? cssVars[$tone]['bg-accent-active']
147
+ : cssVars[$tone]['bg-base-active'],
148
+ },
149
+ '&[data-hovered]': {
150
+ backgroundColor:
151
+ $mode === 'default'
152
+ ? cssVars[$tone]['bg-accent-hover']
153
+ : cssVars[$tone]['bg-base-hover'],
154
+ },
155
+ },
156
+ '&[data-selected]': {
157
+ backgroundColor:
158
+ $mode === 'default'
159
+ ? cssVars[$tone]['bg-accent-active']
160
+ : cssVars[$tone]['bg-base-active'],
94
161
  },
95
- '&[data-selected]': _colorVarsStyle(base, color.pressed),
96
162
  },
97
163
  },
98
164
  theme.sanity.styles?.button?.root,
@@ -7,31 +7,30 @@ import {
7
7
  Inline,
8
8
  Stack,
9
9
  Text,
10
- Theme,
11
10
  ThemeColorToneKey,
12
11
  useRootTheme,
13
12
  } from '@sanity/ui'
14
13
  import {useBoolean} from '@sanity/ui-workshop'
15
14
  import styled, {css} from 'styled-components'
15
+ import {mutableCardVariables} from '../../../theme/lib/theme/color/cssVariables/cardVariables'
16
+ import {cssVars} from '../../../theme/lib/theme/color/cssVariables/createCssVars'
16
17
 
17
18
  const TextWithTone = styled(Text)<{$tone: ThemeColorToneKey}>(({
18
19
  $tone,
19
- theme,
20
20
  }: {
21
21
  $tone: ThemeColorToneKey
22
- theme: Theme
23
22
  }) => {
24
- const tone = theme.sanity.color.solid[$tone]
25
-
26
23
  return css`
27
24
  &:not([data-selected]) {
28
- --card-fg-color: ${tone ? tone.enabled.bg : undefined};
29
- --card-muted-fg-color: ${tone ? tone.enabled.bg : undefined};
25
+ ${mutableCardVariables['fg-color']}: ${$tone ? cssVars[$tone]['text-secondary'] : undefined};
26
+ ${mutableCardVariables['muted-fg-color']} ${$tone
27
+ ? cssVars[$tone]['text-secondary']
28
+ : undefined};
30
29
  }
31
30
 
32
31
  [data-ui='Card']:disabled & {
33
- --card-fg-color: inherit;
34
- --card-muted-fg-color: inherit;
32
+ ${mutableCardVariables['fg-color']}: inherit;
33
+ ${mutableCardVariables['muted-fg-color']} inherit;
35
34
  }
36
35
  `
37
36
  })
@@ -10,7 +10,9 @@ import {
10
10
  responsiveShadowStyle,
11
11
  ResponsiveShadowStyleProps,
12
12
  } from '../../styles/internal'
13
- import {ThemeColorProvider, ThemeColorSchemeKey, useRootTheme} from '../../theme'
13
+ import {ThemeColorName, ThemeColorSchemeKey} from '../../theme'
14
+ import {ToneProvider} from '../../theme/toneContext/toneProvider'
15
+ import {useToneContext} from '../../theme/toneContext/useToneContext'
14
16
  import {CardTone} from '../../types'
15
17
  import {Box, BoxProps} from '../box'
16
18
  import {ResponsiveBorderProps, ResponsiveRadiusProps, ResponsiveShadowProps} from '../types'
@@ -38,6 +40,12 @@ export interface CardProps
38
40
  pressed?: boolean
39
41
  scheme?: ThemeColorSchemeKey
40
42
  tone?: CardTone
43
+ /**
44
+ * @internal
45
+ * Used by the popover, as it creates a new html element that it's ouside of the previous scope of the card.
46
+ * So if it's inheriting styles from the parent, it needs to create a new cars context
47
+ */
48
+ updateCssVars?: boolean
41
49
  }
42
50
 
43
51
  const Root = styled(Box)<
@@ -47,6 +55,29 @@ const Root = styled(Box)<
47
55
  ResponsiveShadowStyleProps
48
56
  >(responsiveBorderStyle, responsiveRadiusStyle, responsiveShadowStyle, cardStyle)
49
57
 
58
+ const Wrapper = ({
59
+ shouldAddContext,
60
+ scheme,
61
+ tone,
62
+ children,
63
+ }: {
64
+ shouldAddContext: boolean
65
+ scheme: ThemeColorSchemeKey
66
+ tone: ThemeColorName
67
+ children: React.ReactElement
68
+ }): React.ReactElement => {
69
+ // Avoid creating a new react context if the card is just inheriting styles from the parent.
70
+ if (shouldAddContext) {
71
+ return (
72
+ <ToneProvider scheme={scheme} tone={tone}>
73
+ {children}
74
+ </ToneProvider>
75
+ )
76
+ }
77
+
78
+ return children
79
+ }
80
+
50
81
  /**
51
82
  * @public
52
83
  */
@@ -65,24 +96,28 @@ export const Card = forwardRef(function Card(
65
96
  borderLeft,
66
97
  pressed,
67
98
  radius = 0,
68
- scheme,
99
+ scheme: schemeProp,
69
100
  selected,
70
101
  shadow,
71
102
  tone: toneProp = 'default',
103
+ updateCssVars = false,
72
104
  ...restProps
73
105
  } = props
74
106
 
75
107
  const as = isValidElementType(asProp) ? asProp : 'div'
76
- const rootTheme = useRootTheme()
77
- const tone = toneProp === 'inherit' ? rootTheme.tone : toneProp
108
+ const toneContext = useToneContext()
109
+ const tone = toneProp === 'inherit' ? toneContext.tone : toneProp
110
+ const scheme = schemeProp ?? toneContext.scheme
111
+ const shouldAddContext = scheme !== toneContext.scheme || tone !== toneContext.tone
78
112
 
79
113
  return (
80
- <ThemeColorProvider scheme={scheme} tone={tone}>
114
+ <Wrapper shouldAddContext={shouldAddContext} scheme={scheme} tone={tone}>
81
115
  <Root
82
116
  data-as={typeof as === 'string' ? as : undefined}
83
- data-scheme={rootTheme.scheme}
117
+ data-scheme={scheme}
84
118
  data-ui="Card"
85
119
  data-tone={tone}
120
+ $scheme={scheme ?? toneContext.scheme}
86
121
  {...restProps}
87
122
  $border={useArrayProp(border)}
88
123
  $borderTop={useArrayProp(borderTop)}
@@ -94,6 +129,7 @@ export const Card = forwardRef(function Card(
94
129
  $radius={useArrayProp(radius)}
95
130
  $shadow={useArrayProp(shadow)}
96
131
  $tone={tone}
132
+ $updateCssVars={updateCssVars || shouldAddContext}
97
133
  data-checkered={checkered ? '' : undefined}
98
134
  data-pressed={pressed ? '' : undefined}
99
135
  data-selected={selected ? '' : undefined}
@@ -101,6 +137,6 @@ export const Card = forwardRef(function Card(
101
137
  ref={ref}
102
138
  selected={selected}
103
139
  />
104
- </ThemeColorProvider>
140
+ </Wrapper>
105
141
  )
106
142
  })