@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,6 +1,7 @@
|
|
|
1
1
|
import {css} from 'styled-components'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import {ThemeColorToneKey, ThemeFontWeightKey} from '../../theme'
|
|
3
|
+
import {mutableCardVariables} from '../../theme/lib/theme/color/cssVariables/cardVariables'
|
|
4
|
+
import {cssVars} from '../../theme/lib/theme/color/cssVariables/createCssVars'
|
|
4
5
|
import {CSSObject} from '../../types/styled'
|
|
5
6
|
import {focusRingBorderStyle, focusRingStyle} from '../focusRing'
|
|
6
7
|
import {rem, _responsive} from '../helpers'
|
|
@@ -11,8 +12,7 @@ import {ThemeProps} from '../types'
|
|
|
11
12
|
*/
|
|
12
13
|
export interface TextInputInputStyleProps {
|
|
13
14
|
$fontSize: number[]
|
|
14
|
-
$
|
|
15
|
-
$tone: CardTone
|
|
15
|
+
$tone: ThemeColorToneKey
|
|
16
16
|
$weight?: ThemeFontWeightKey
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -22,8 +22,7 @@ export interface TextInputInputStyleProps {
|
|
|
22
22
|
export interface TextInputRepresentationStyleProps {
|
|
23
23
|
$hasPrefix?: boolean
|
|
24
24
|
$hasSuffix?: boolean
|
|
25
|
-
$
|
|
26
|
-
$tone: CardTone
|
|
25
|
+
$tone: ThemeColorToneKey
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
const ROOT_STYLE = css`
|
|
@@ -41,9 +40,8 @@ export function textInputRootStyle(): ReturnType<typeof css> {
|
|
|
41
40
|
export function textInputBaseStyle(
|
|
42
41
|
props: TextInputInputStyleProps & ThemeProps,
|
|
43
42
|
): ReturnType<typeof css> {
|
|
44
|
-
const {theme, $
|
|
43
|
+
const {theme, $tone, $weight} = props
|
|
45
44
|
const font = theme.sanity.fonts.text
|
|
46
|
-
const color = theme.sanity.color.input
|
|
47
45
|
|
|
48
46
|
return css`
|
|
49
47
|
appearance: none;
|
|
@@ -81,33 +79,31 @@ export function textInputBaseStyle(
|
|
|
81
79
|
color: var(--input-placeholder-color);
|
|
82
80
|
}
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
--input-placeholder-color: ${color.default.enabled.placeholder};
|
|
82
|
+
--input-fg-color: ${cssVars[$tone]['text-primary']};
|
|
83
|
+
--input-placeholder-color: ${cssVars[$tone]['text-inactive']};
|
|
87
84
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
/* enabled */
|
|
86
|
+
&:not(:invalid):not(:disabled):not(:read-only) {
|
|
87
|
+
--input-fg-color: ${cssVars[$tone]['text-primary']};
|
|
88
|
+
--input-placeholder-color: ${cssVars[$tone]['text-inactive']};
|
|
89
|
+
}
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
/* disabled */
|
|
92
|
+
&:not(:invalid):disabled {
|
|
93
|
+
--input-fg-color: ${cssVars[$tone]['text-primary']};
|
|
94
|
+
--input-placeholder-color: ${cssVars[$tone]['text-inactive']};
|
|
95
|
+
}
|
|
99
96
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
/* invalid */
|
|
98
|
+
&:invalid {
|
|
99
|
+
--input-fg-color: ${cssVars.critical['text-primary']};
|
|
100
|
+
--input-placeholder-color: ${cssVars.critical['text-inactive']};
|
|
101
|
+
}
|
|
105
102
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
103
|
+
/* readOnly */
|
|
104
|
+
&:read-only {
|
|
105
|
+
--input-fg-color: ${cssVars[$tone]['text-primary']};
|
|
106
|
+
--input-placeholder-color: ${cssVars[$tone]['text-inactive']};
|
|
111
107
|
}
|
|
112
108
|
`
|
|
113
109
|
}
|
|
@@ -129,9 +125,9 @@ export function textInputFontSizeStyle(props: TextInputInputStyleProps & ThemePr
|
|
|
129
125
|
export function textInputRepresentationStyle(
|
|
130
126
|
props: TextInputRepresentationStyleProps & ThemeProps,
|
|
131
127
|
): ReturnType<typeof css> {
|
|
132
|
-
const {$hasPrefix, $hasSuffix, $
|
|
133
|
-
const {
|
|
134
|
-
const
|
|
128
|
+
const {$hasPrefix, $hasSuffix, $tone, theme} = props
|
|
129
|
+
const {input} = theme.sanity
|
|
130
|
+
const {focusRing} = input.text
|
|
135
131
|
|
|
136
132
|
return css`
|
|
137
133
|
--input-box-shadow: none;
|
|
@@ -145,7 +141,7 @@ export function textInputRepresentationStyle(
|
|
|
145
141
|
pointer-events: none;
|
|
146
142
|
z-index: 0;
|
|
147
143
|
|
|
148
|
-
background-color:
|
|
144
|
+
background-color: ${cssVars.mutable['bg-color']};
|
|
149
145
|
box-shadow: var(--input-box-shadow);
|
|
150
146
|
|
|
151
147
|
border-top-left-radius: ${$hasPrefix ? 0 : undefined};
|
|
@@ -153,78 +149,66 @@ export function textInputRepresentationStyle(
|
|
|
153
149
|
border-top-right-radius: ${$hasSuffix ? 0 : undefined};
|
|
154
150
|
border-bottom-right-radius: ${$hasSuffix ? 0 : undefined};
|
|
155
151
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
152
|
+
${mutableCardVariables['bg-color']}: ${cssVars[$tone]['bg-base']};
|
|
153
|
+
${mutableCardVariables['fg-color']}: ${cssVars[$tone]['text-primary']};
|
|
154
|
+
|
|
155
|
+
/* enabled */
|
|
156
|
+
&[data-border] {
|
|
157
|
+
--input-box-shadow: ${focusRingBorderStyle({
|
|
158
|
+
color: cssVars[$tone]['border-base'],
|
|
159
|
+
width: input.border.width,
|
|
160
|
+
})};
|
|
161
|
+
}
|
|
159
162
|
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
/* invalid */
|
|
164
|
+
*:not(:disabled):invalid + & {
|
|
165
|
+
${mutableCardVariables['bg-color']}: ${cssVars.critical['bg-tint']};
|
|
166
|
+
${mutableCardVariables['fg-color']}: ${cssVars.critical['text-primary']};
|
|
167
|
+
|
|
168
|
+
&[data-border] {
|
|
162
169
|
--input-box-shadow: ${focusRingBorderStyle({
|
|
163
|
-
color:
|
|
170
|
+
color: cssVars.critical['border-base'],
|
|
164
171
|
width: input.border.width,
|
|
165
172
|
})};
|
|
166
173
|
}
|
|
174
|
+
}
|
|
167
175
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
--
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
color: color.invalid.enabled.border,
|
|
176
|
-
width: input.border.width,
|
|
177
|
-
})};
|
|
178
|
-
}
|
|
176
|
+
/* focused */
|
|
177
|
+
*:not(:disabled):focus + & {
|
|
178
|
+
&[data-border] {
|
|
179
|
+
--input-box-shadow: ${focusRingStyle({
|
|
180
|
+
border: {color: cssVars[$tone]['border-base'], width: input.border.width},
|
|
181
|
+
focusRing,
|
|
182
|
+
})};
|
|
179
183
|
}
|
|
180
184
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
&[data-border] {
|
|
184
|
-
--input-box-shadow: ${focusRingStyle({
|
|
185
|
-
border: {color: color.default.enabled.border, width: input.border.width},
|
|
186
|
-
focusRing,
|
|
187
|
-
})};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
&:not([data-border]) {
|
|
191
|
-
--input-box-shadow: ${focusRingStyle({focusRing})};
|
|
192
|
-
}
|
|
185
|
+
&:not([data-border]) {
|
|
186
|
+
--input-box-shadow: ${focusRingStyle({focusRing})};
|
|
193
187
|
}
|
|
188
|
+
}
|
|
194
189
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
&[data-border] {
|
|
201
|
-
--input-box-shadow: ${focusRingBorderStyle({
|
|
202
|
-
color: color.default.disabled.border,
|
|
203
|
-
width: input.border.width,
|
|
204
|
-
})};
|
|
205
|
-
}
|
|
206
|
-
}
|
|
190
|
+
/* disabled */
|
|
191
|
+
*:disabled + & {
|
|
192
|
+
${mutableCardVariables['bg-color']}: ${cssVars.default['bg-tint']} !important;
|
|
193
|
+
${mutableCardVariables['fg-color']}: ${cssVars.default['text-primary']} !important;
|
|
194
|
+
}
|
|
207
195
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
196
|
+
/* readOnly */
|
|
197
|
+
*:read-only + & {
|
|
198
|
+
${mutableCardVariables['bg-color']}: ${cssVars.default['bg-tint']} !important;
|
|
199
|
+
${mutableCardVariables['fg-color']}: ${cssVars.default['text-primary']} !important;
|
|
200
|
+
}
|
|
213
201
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
--input-box-shadow: ${focusRingBorderStyle({
|
|
223
|
-
color: color.default.hovered.border,
|
|
224
|
-
width: input.border.width,
|
|
225
|
-
})};
|
|
226
|
-
}
|
|
202
|
+
/* hovered */
|
|
203
|
+
@media (hover: hover) {
|
|
204
|
+
|
|
205
|
+
*:not(:disabled):not(:read-only):not(:invalid):not(:focus):hover + &[data-border] {
|
|
206
|
+
--input-box-shadow: ${focusRingBorderStyle({
|
|
207
|
+
color: cssVars.default['border-base-hover'],
|
|
208
|
+
width: input.border.width,
|
|
209
|
+
})};
|
|
227
210
|
}
|
|
228
211
|
}
|
|
212
|
+
}
|
|
229
213
|
`
|
|
230
214
|
}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
import {studioTheme, Theme} from '../../theme'
|
|
4
4
|
import {responsiveMarginStyle} from './marginStyle'
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const theme: Theme = {sanity: {...restTheme, color: color.light.default}}
|
|
6
|
+
const theme: Theme = {sanity: studioTheme}
|
|
8
7
|
|
|
9
8
|
describe('styles/margin', () => {
|
|
10
9
|
it('should 1', () => {
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
import {studioTheme, Theme} from '../../theme'
|
|
4
4
|
import {responsivePaddingStyle} from './paddingStyle'
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const theme: Theme = {sanity: {...restTheme, color: color.light.default}}
|
|
6
|
+
const theme: Theme = {sanity: studioTheme}
|
|
8
7
|
|
|
9
8
|
describe('styles/padding', () => {
|
|
10
9
|
it('should 1', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {CSSObject} from '../../types/styled'
|
|
2
|
-
import {
|
|
2
|
+
import {_responsive, rem} from '../helpers'
|
|
3
3
|
import {ThemeProps} from '../types'
|
|
4
4
|
import {ResponsiveRadiusStyleProps} from './types'
|
|
5
5
|
|
|
@@ -7,7 +7,17 @@ export function responsiveRadiusStyle(props: ResponsiveRadiusStyleProps & ThemeP
|
|
|
7
7
|
const {theme} = props
|
|
8
8
|
const {media, radius} = theme.sanity
|
|
9
9
|
|
|
10
|
-
return _responsive(media, props.$radius, (
|
|
11
|
-
borderRadius:
|
|
12
|
-
|
|
10
|
+
return _responsive(media, props.$radius, (value) => {
|
|
11
|
+
let borderRadius: string | 0 = 0
|
|
12
|
+
|
|
13
|
+
if (typeof value === 'number') {
|
|
14
|
+
borderRadius = rem(radius[value])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (value === 'full') {
|
|
18
|
+
borderRadius = '9999px'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {borderRadius}
|
|
22
|
+
})
|
|
13
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {EMPTY_RECORD} from '../../constants'
|
|
2
|
-
import {BoxShadow, ThemeShadow} from '../../theme'
|
|
2
|
+
import {BoxShadow, ThemeShadow, cssVars} from '../../theme'
|
|
3
3
|
import {CSSObject} from '../../types/styled'
|
|
4
4
|
import {rem, _responsive} from '../helpers'
|
|
5
5
|
import {ThemeProps} from '../types'
|
|
@@ -12,10 +12,10 @@ function toBoxShadow(shadow: BoxShadow, color: string) {
|
|
|
12
12
|
function shadowStyle(shadow: ThemeShadow | null): CSSObject {
|
|
13
13
|
if (!shadow) return EMPTY_RECORD
|
|
14
14
|
|
|
15
|
-
const outline = `0 0 0 ${rem(1)}
|
|
16
|
-
const umbra = toBoxShadow(shadow.umbra, '
|
|
17
|
-
const penumbra = toBoxShadow(shadow.penumbra, '
|
|
18
|
-
const ambient = toBoxShadow(shadow.ambient, '
|
|
15
|
+
const outline = `0 0 0 ${rem(1)} ${cssVars.default['base-shadow-outline-color']}`
|
|
16
|
+
const umbra = toBoxShadow(shadow.umbra, cssVars.default['base-shadow-umbra-color'])
|
|
17
|
+
const penumbra = toBoxShadow(shadow.penumbra, cssVars.default['base-shadow-penumbra-color'])
|
|
18
|
+
const ambient = toBoxShadow(shadow.ambient, cssVars.default['base-shadow-ambient-color'])
|
|
19
19
|
|
|
20
20
|
return {boxShadow: `${outline}, ${umbra}, ${penumbra}, ${ambient}`}
|
|
21
21
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {Box, Card, Tree, TreeItem, useRootTheme} from '@sanity/ui'
|
|
2
|
+
import {Box, Card, Tree, TreeItem, cssVars, useRootTheme} from '@sanity/ui'
|
|
3
3
|
|
|
4
4
|
export default function ColorStory() {
|
|
5
5
|
const {theme} = useRootTheme()
|
|
@@ -48,7 +48,7 @@ function ColorPreview({name, value}: {name: string; value: string}) {
|
|
|
48
48
|
radius={2}
|
|
49
49
|
style={{
|
|
50
50
|
backgroundColor: value,
|
|
51
|
-
boxShadow:
|
|
51
|
+
boxShadow: `inset 0 0 0 1px ${cssVars.default['base-shadow-outline-color']}`,
|
|
52
52
|
display: 'inline-block',
|
|
53
53
|
height: 17,
|
|
54
54
|
width: 25,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {RGB} from '../types'
|
|
1
|
+
import {RGB, RGBA} from '../types'
|
|
2
2
|
|
|
3
3
|
function multiplyChannel(b: number, s: number) {
|
|
4
4
|
return b * s
|
|
@@ -9,7 +9,7 @@ function multiplyChannel(b: number, s: number) {
|
|
|
9
9
|
* Source: https://www.w3.org/TR/compositing-1/#blendingmultiply
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export function multiply(b: RGB, s: RGB): RGB {
|
|
12
|
+
export function multiply(b: RGB | RGBA, s: RGB | RGBA): RGB {
|
|
13
13
|
return {
|
|
14
14
|
r: Math.round(clamp(multiplyChannel(b.r / 255, s.r / 255) * 255)),
|
|
15
15
|
g: Math.round(clamp(multiplyChannel(b.g / 255, s.g / 255) * 255)),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {RGB} from '../types'
|
|
1
|
+
import {RGB, RGBA} from '../types'
|
|
2
2
|
|
|
3
3
|
function screenChannel(b: number, s: number) {
|
|
4
4
|
return b + s - b * s
|
|
@@ -9,7 +9,7 @@ function screenChannel(b: number, s: number) {
|
|
|
9
9
|
* Source: https://www.w3.org/TR/compositing-1/#blendingscreen
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export function screen(b: RGB, s: RGB): RGB {
|
|
12
|
+
export function screen(b: RGB | RGBA, s: RGB | RGBA): RGB {
|
|
13
13
|
return {
|
|
14
14
|
r: Math.round(clamp(screenChannel(b.r / 255, s.r / 255) * 255)),
|
|
15
15
|
g: Math.round(clamp(screenChannel(b.g / 255, s.g / 255) * 255)),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {HSL, RGB} from './types'
|
|
1
|
+
import {HSL, RGB, RGBA} from './types'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
@@ -23,6 +23,20 @@ export function hexToRgb(hex: string): RGB {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export function rgbaToRGBA(rgba: string): RGBA {
|
|
30
|
+
const values = rgba.replace(/rgba\(|\)/g, '').split(',')
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
r: parseInt(values[0]),
|
|
34
|
+
g: parseInt(values[1]),
|
|
35
|
+
b: parseInt(values[2]),
|
|
36
|
+
a: parseFloat(values[3]),
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
26
40
|
/**
|
|
27
41
|
* @internal
|
|
28
42
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {hexToRgb, hslToRgb} from './convert'
|
|
2
|
-
import {HSL, RGB} from './types'
|
|
1
|
+
import {hexToRgb, hslToRgb, rgbaToRGBA} from './convert'
|
|
2
|
+
import {HSL, RGB, RGBA} from './types'
|
|
3
3
|
|
|
4
4
|
const HEX_CHARS = '0123456789ABCDEFabcdef'
|
|
5
5
|
|
|
@@ -37,7 +37,7 @@ function parseHsl(str: string): HSL {
|
|
|
37
37
|
/**
|
|
38
38
|
* @internal
|
|
39
39
|
*/
|
|
40
|
-
export function parseColor(color: unknown): RGB {
|
|
40
|
+
export function parseColor(color: unknown): RGB | RGBA {
|
|
41
41
|
if (!color) return {r: 0, g: 0, b: 0}
|
|
42
42
|
|
|
43
43
|
if (typeof color !== 'string') {
|
|
@@ -52,5 +52,9 @@ export function parseColor(color: unknown): RGB {
|
|
|
52
52
|
return hslToRgb(parseHsl(color))
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
if (color.startsWith('rgba(')) {
|
|
56
|
+
return rgbaToRGBA(color)
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
throw new Error(`parseColor: unexpected color format: "${color}"`)
|
|
56
60
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createColorTheme'
|