@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,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
 
@@ -42,6 +44,11 @@ export function buttonBaseStyles(): ReturnType<typeof css> {
42
44
  }
43
45
 
44
46
  const buttonTheme = {border: {width: 1}}
47
+ const defaultBoxShadow = '0px 2px 0px 0px rgba(112, 128, 155, 0.19);'
48
+
49
+ function combineBoxShadow(...boxShadows: (string | undefined)[]): string {
50
+ return boxShadows.filter(Boolean).join(',')
51
+ }
45
52
 
46
53
  /**
47
54
  * @internal
@@ -49,33 +56,109 @@ const buttonTheme = {border: {width: 1}}
49
56
  export function buttonColorStyles(
50
57
  props: {$mode: ButtonMode; $tone: ButtonTone} & ThemeProps,
51
58
  ): CSSObject[] {
52
- const {$mode, theme} = props
53
- const {focusRing} = theme.sanity
54
- const base = theme.sanity.color.base
55
- const mode = theme.sanity.color.button[$mode] || theme.sanity.color.button.default
56
- const color = mode[props.$tone] || mode.default
57
- const border = {width: buttonTheme.border.width, color: 'var(--card-border-color)'}
59
+ const {$mode, theme, $tone} = props
60
+ const {focusRing} = theme.sanity.button
61
+ const shadow = props.$mode !== 'bleed'
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
+ }
58
71
 
59
72
  return [
60
- _colorVarsStyle(base, color.enabled),
61
73
  {
62
- backgroundColor: 'var(--card-bg-color)',
63
- 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'],
64
108
  boxShadow: focusRingBorderStyle(border),
65
- '&: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
+ },
66
118
  "&:not([data-disabled='true'])": {
119
+ boxShadow: combineBoxShadow(
120
+ focusRingBorderStyle(border),
121
+ shadow ? defaultBoxShadow : undefined,
122
+ ),
67
123
  '&:focus': {
68
- boxShadow: focusRingStyle({base, border, focusRing}),
124
+ boxShadow: focusRingStyle({
125
+ base: {bg: cssVars.positive['border-accent']},
126
+ border: {width: 2, color: cssVars.default['bg-base']},
127
+ focusRing,
128
+ }),
69
129
  },
70
130
  '&:focus:not(:focus-visible)': {
71
- boxShadow: focusRingBorderStyle(border),
131
+ boxShadow: combineBoxShadow(
132
+ focusRingBorderStyle(border),
133
+ shadow ? defaultBoxShadow : undefined,
134
+ ),
72
135
  },
73
136
  '@media (hover: hover)': {
74
- '&:hover': _colorVarsStyle(base, color.hovered),
75
- '&:active': _colorVarsStyle(base, color.pressed),
76
- '&[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'],
77
161
  },
78
- '&[data-selected]': _colorVarsStyle(base, color.pressed),
79
162
  },
80
163
  },
81
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
  })
@@ -1,7 +1,13 @@
1
1
  import {css} from 'styled-components'
2
2
  import {ThemeProps} from '../../styles'
3
- import {_colorVarsStyle} from '../../styles/colorVars'
3
+ import {
4
+ _colorVarStyleActive,
5
+ _colorVarStyleDisabled,
6
+ _colorVarStyleHover,
7
+ _colorVarStyleSelected,
8
+ } from '../../styles/colorVars'
4
9
  import {focusRingBorderStyle, focusRingStyle} from '../../styles/focusRing'
10
+ import {createCssVars, cssVars} from '../../theme/lib/theme/color/cssVariables'
5
11
  import {CardStyleProps} from './types'
6
12
 
7
13
  export function cardStyle(
@@ -19,7 +25,7 @@ export function cardBaseStyle(props: CardStyleProps & ThemeProps): ReturnType<ty
19
25
  css`
20
26
  background-size: ${space[3]}px ${space[3]}px;
21
27
  background-position: 50% 50%;
22
- background-image: var(--card-bg-image);
28
+ background-image: ${cssVars.mutable['bg-image']};
23
29
  `}
24
30
 
25
31
  &[data-as='button'] {
@@ -29,7 +35,6 @@ export function cardBaseStyle(props: CardStyleProps & ThemeProps): ReturnType<ty
29
35
  font: inherit;
30
36
  text-align: inherit;
31
37
  border: 0;
32
- width: -webkit-fill-available;
33
38
  width: stretch;
34
39
  }
35
40
 
@@ -47,18 +52,20 @@ export function cardBaseStyle(props: CardStyleProps & ThemeProps): ReturnType<ty
47
52
  }
48
53
 
49
54
  export function cardColorStyle(props: CardStyleProps & ThemeProps): ReturnType<typeof css> {
50
- const {$checkered, $focusRing, theme} = props
51
- const {focusRing} = theme.sanity
52
- const {base, card, dark} = theme.sanity.color
53
- const border = {width: 0, color: 'var(--card-border-color)'}
55
+ const {$checkered, $focusRing, theme, $tone, $scheme, $updateCssVars} = props
56
+ const {focusRing} = theme.sanity.card
54
57
 
55
- return css`
56
- color-scheme: ${dark ? 'dark' : 'light'};
58
+ const border = {width: 0, color: cssVars.positive['border-accent']}
57
59
 
58
- ${_colorVarsStyle(base, card.enabled, $checkered)}
60
+ return css`
61
+ /* A new css vars context is created, allowing for override of the default tone and changing the scheme */
62
+ ${$updateCssVars && createCssVars($scheme, theme.sanity.color.tones, $tone)}
63
+ color-scheme: ${$scheme === 'dark' ? 'dark' : 'light'};
64
+ ${$checkered &&
65
+ `--card-bg-image: repeating-conic-gradient(${cssVars.default['base-bg-card']} 0% 25%, ${cssVars.default['bg-tint']} 0% 50%)`}
59
66
 
60
- background-color: var(--card-bg-color);
61
- color: var(--card-fg-color);
67
+ background-color: ${cssVars.mutable['bg-color']};
68
+ color: ${cssVars.default['text-primary']};
62
69
 
63
70
  /* &:is(button) */
64
71
  &[data-as='button'] {
@@ -68,34 +75,34 @@ export function cardColorStyle(props: CardStyleProps & ThemeProps): ReturnType<t
68
75
  box-shadow: var(--card-focus-ring-box-shadow);
69
76
 
70
77
  &:disabled {
71
- ${_colorVarsStyle(base, card.disabled, $checkered)}
78
+ ${_colorVarStyleDisabled($checkered)}
72
79
  }
73
80
 
74
81
  &:not(:disabled) {
75
82
  &[data-pressed] {
76
- ${_colorVarsStyle(base, card.pressed, $checkered)}
83
+ ${_colorVarStyleActive()}
77
84
  }
78
85
 
79
86
  &[data-selected] {
80
- ${_colorVarsStyle(base, card.selected, $checkered)}
87
+ ${_colorVarStyleSelected()}
81
88
  }
82
89
 
83
90
  @media (hover: hover) {
84
91
  &:not([data-pressed]):not([data-selected]) {
85
92
  &[data-hovered],
86
93
  &:hover {
87
- ${_colorVarsStyle(base, card.hovered, $checkered)}
94
+ ${_colorVarStyleHover()}
88
95
  }
89
96
 
90
97
  &:active {
91
- ${_colorVarsStyle(base, card.pressed, $checkered)}
98
+ ${_colorVarStyleActive()}
92
99
  }
93
100
  }
94
101
  }
95
102
 
96
103
  &:focus {
97
104
  --card-focus-ring-box-shadow: ${$focusRing
98
- ? focusRingStyle({base, border, focusRing})
105
+ ? focusRingStyle({border, focusRing})
99
106
  : undefined};
100
107
  }
101
108
 
@@ -111,34 +118,34 @@ export function cardColorStyle(props: CardStyleProps & ThemeProps): ReturnType<t
111
118
  box-shadow: var(--card-focus-ring-box-shadow);
112
119
 
113
120
  &[data-disabled] {
114
- ${_colorVarsStyle(base, card.disabled, $checkered)}
121
+ ${_colorVarStyleDisabled($checkered)}
115
122
  }
116
123
 
117
124
  &:not([data-disabled]) {
118
125
  &[data-pressed] {
119
- ${_colorVarsStyle(base, card.pressed, $checkered)}
126
+ ${_colorVarStyleActive()}
120
127
  }
121
128
 
122
129
  &[data-selected] {
123
- ${_colorVarsStyle(base, card.selected, $checkered)}
130
+ ${_colorVarStyleSelected()}
124
131
  }
125
132
 
126
133
  @media (hover: hover) {
127
134
  &:not([data-pressed]):not([data-selected]) {
128
135
  &[data-hovered],
129
136
  &:hover {
130
- ${_colorVarsStyle(base, card.hovered, $checkered)}
137
+ ${_colorVarStyleHover()}
131
138
  }
132
139
 
133
140
  &:active {
134
- ${_colorVarsStyle(base, card.pressed, $checkered)}
141
+ ${_colorVarStyleActive()}
135
142
  }
136
143
  }
137
144
  }
138
145
 
139
146
  &:focus {
140
147
  --card-focus-ring-box-shadow: ${$focusRing
141
- ? focusRingStyle({base, border, focusRing})
148
+ ? focusRingStyle({border, focusRing})
142
149
  : undefined};
143
150
  }
144
151
 
@@ -1,4 +1,4 @@
1
- import {ThemeColorToneKey} from '../../theme'
1
+ import {ThemeColorSchemeKey, ThemeColorToneKey} from '../../theme'
2
2
 
3
3
  /**
4
4
  * @internal
@@ -7,4 +7,6 @@ export interface CardStyleProps {
7
7
  $checkered: boolean
8
8
  $focusRing: boolean
9
9
  $tone: ThemeColorToneKey
10
+ $scheme: ThemeColorSchemeKey
11
+ $updateCssVars: boolean
10
12
  }
@@ -47,6 +47,7 @@ export const Checkbox = forwardRef(function Checkbox(
47
47
  <Root className={className} data-ui="Checkbox" style={style}>
48
48
  <Input
49
49
  data-read-only={!disabled && readOnly ? '' : undefined}
50
+ data-error={customValidity ? '' : undefined}
50
51
  {...restProps}
51
52
  checked={checked}
52
53
  disabled={disabled || readOnly}
@@ -1,6 +1,7 @@
1
1
  import {css} from 'styled-components'
2
2
  import {rem, ThemeProps} from '../../styles'
3
3
  import {focusRingBorderStyle, focusRingStyle} from '../../styles/internal'
4
+ import {cssVars} from '../../theme/lib/theme/color/cssVariables/createCssVars'
4
5
 
5
6
  export function checkboxBaseStyles(): ReturnType<typeof css> {
6
7
  return css`
@@ -11,8 +12,8 @@ export function checkboxBaseStyles(): ReturnType<typeof css> {
11
12
 
12
13
  export function inputElementStyles(props: ThemeProps): ReturnType<typeof css> {
13
14
  const {theme} = props
14
- const color = theme.sanity.color.input
15
- const {focusRing, input, radius} = theme.sanity
15
+ const {input, radius} = theme.sanity
16
+ const {focusRing} = input.checkbox
16
17
 
17
18
  return css`
18
19
  position: absolute;
@@ -33,12 +34,12 @@ export function inputElementStyles(props: ThemeProps): ReturnType<typeof css> {
33
34
  width: ${rem(input.checkbox.size)};
34
35
  box-sizing: border-box;
35
36
  box-shadow: ${focusRingBorderStyle({
36
- color: color.default.enabled.border,
37
+ color: cssVars.default['border-base'],
37
38
  width: input.border.width,
38
39
  })};
39
40
  border-radius: ${rem(radius[2])};
40
41
  line-height: 1;
41
- background-color: ${color.default.enabled.bg};
42
+ background-color: ${cssVars.default['bg-base']};
42
43
 
43
44
  & > svg {
44
45
  display: block;
@@ -49,47 +50,76 @@ export function inputElementStyles(props: ThemeProps): ReturnType<typeof css> {
49
50
 
50
51
  & > path {
51
52
  vector-effect: non-scaling-stroke;
52
- stroke-width: 2 !important;
53
+ stroke-width: 1.2 !important;
53
54
  }
54
55
  }
55
56
  }
56
-
57
- &:not(:disabled):focus + span {
58
- box-shadow: ${focusRingStyle({
59
- border: {width: input.border.width, color: color.default.enabled.border},
60
- focusRing,
57
+ &:checked + span {
58
+ background: ${cssVars.default['text-secondary']};
59
+ box-shadow: ${focusRingBorderStyle({
60
+ color: cssVars.default['text-secondary'],
61
+ width: input.border.width,
61
62
  })};
63
+ color: ${cssVars.default['bg-base']};
64
+ }
65
+
66
+ /* focus */
67
+ &:not(:disabled):focus:focus-visible + span {
68
+ box-shadow: ${focusRingStyle({focusRing})};
62
69
  }
63
70
 
64
- &:not(:disabled):focus:not(:focus-visible) + span {
71
+ /* focus when checked - uses a different offset */
72
+ &:not(:disabled):focus:focus-visible&:checked + span {
73
+ box-shadow: ${focusRingStyle({focusRing: {width: 1, offset: 1}})};
74
+ }
75
+
76
+ &[data-error] + span {
77
+ background-color: ${cssVars.critical['border-base']};
65
78
  box-shadow: ${focusRingBorderStyle({
66
- color: color.default.enabled.border,
67
79
  width: input.border.width,
80
+ color: cssVars.critical['text-secondary'],
68
81
  })};
82
+ color: ${cssVars.default['text-secondary']};
69
83
  }
70
-
71
- &:checked + span > svg:first-child {
72
- opacity: 1;
84
+ &[data-error]&:checked + span {
85
+ background-color: ${cssVars.critical['text-secondary']};
86
+ color: ${cssVars.default['bg-base']};
87
+ }
88
+ &[data-error]&:checked&:not(:disabled):focus:focus-visible + span {
89
+ box-shadow: ${focusRingStyle({
90
+ border: {width: input.border.width, color: cssVars.critical['text-secondary']},
91
+ focusRing: {width: 1, offset: 1},
92
+ })};
73
93
  }
74
94
 
75
- &[data-read-only] + span {
76
- background-color: ${color.default.readOnly.bg};
95
+ &:disabled + span {
96
+ background-color: ${cssVars.default['bg-tint']};
77
97
  box-shadow: ${focusRingBorderStyle({
78
98
  width: input.border.width,
79
- color: color.default.readOnly.border,
99
+ color: cssVars.default['border-base'],
80
100
  })};
81
- color: ${color.default.readOnly.fg};
101
+ color: ${cssVars.default['text-secondary']};
102
+ }
103
+ &:disabled&:checked + span {
104
+ background-color: ${cssVars.default['border-base']};
82
105
  }
83
106
 
84
- &:not([data-read-only]):disabled + span {
85
- background-color: ${color.default.disabled.bg};
107
+ &[data-read-only] + span {
108
+ background-color: ${cssVars.default['bg-tint']};
86
109
  box-shadow: ${focusRingBorderStyle({
87
110
  width: input.border.width,
88
- color: color.default.disabled.border,
111
+ color: cssVars.default['border-base'],
89
112
  })};
90
- color: ${color.default.disabled.fg};
113
+ color: ${cssVars.default['text-secondary']};
91
114
  }
92
115
 
116
+ &[data-read-only]&:checked + span {
117
+ background-color: ${cssVars.default['border-base']};
118
+ }
119
+
120
+ &:checked + span > svg:first-child {
121
+ opacity: 1;
122
+ }
93
123
  &:indeterminate + span > svg:last-child {
94
124
  opacity: 1;
95
125
  }
@@ -4,7 +4,8 @@ import Refractor from 'react-refractor'
4
4
  import styled from 'styled-components'
5
5
  import {useArrayProp} from '../../hooks'
6
6
  import {responsiveCodeFontStyle, ResponsiveFontStyleProps} from '../../styles/internal'
7
- import {codeBaseStyle} from './styles'
7
+ import {useToneContext} from '../../theme/toneContext/useToneContext'
8
+ import {codeBaseStyle, CodeBaseStyleProps} from './styles'
8
9
 
9
10
  /**
10
11
  * @public
@@ -16,7 +17,10 @@ export interface CodeProps {
16
17
  weight?: string
17
18
  }
18
19
 
19
- const Root = styled.pre<ResponsiveFontStyleProps>(codeBaseStyle, responsiveCodeFontStyle)
20
+ const Root = styled.pre<CodeBaseStyleProps & ResponsiveFontStyleProps>(
21
+ codeBaseStyle,
22
+ responsiveCodeFontStyle,
23
+ )
20
24
 
21
25
  /**
22
26
  * @public
@@ -28,9 +32,17 @@ export const Code = forwardRef(function Code(
28
32
  const {children, language: languageProp, size = 2, weight, ...restProps} = props
29
33
  const language = typeof languageProp === 'string' ? languageProp : undefined
30
34
  const registered = language ? Refractor.hasLanguage(language as any) : false
35
+ const {scheme} = useToneContext()
31
36
 
32
37
  return (
33
- <Root data-ui="Code" {...restProps} $size={useArrayProp(size)} $weight={weight} ref={ref}>
38
+ <Root
39
+ data-ui="Code"
40
+ {...restProps}
41
+ $size={useArrayProp(size)}
42
+ $weight={weight}
43
+ ref={ref}
44
+ $scheme={scheme}
45
+ >
34
46
  {!(language && registered) && <code>{children}</code>}
35
47
  {language && registered && <Refractor inline language={language} value={String(children)} />}
36
48
  </Root>