@sanity/ui 2.0.0-beta.7 → 2.0.0-beta.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.0.0-beta.7",
3
+ "version": "2.0.0-beta.9",
4
4
  "sideEffects": false,
5
5
  "types": "./dist/index.d.ts",
6
6
  "source": "./exports/index.ts",
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@floating-ui/react-dom": "^2.0.4",
75
- "@sanity/color": "3.0.0-beta.8",
75
+ "@sanity/color": "3.0.0-beta.9",
76
76
  "@sanity/icons": "^2.7.0",
77
77
  "csstype": "^3.1.2",
78
78
  "framer-motion": "^10.16.5",
@@ -155,6 +155,7 @@
155
155
  "peerDependencies": {
156
156
  "react": "^18",
157
157
  "react-dom": "^18",
158
+ "react-is": "^18",
158
159
  "styled-components": "^5.2 || ^6"
159
160
  },
160
161
  "engines": {
@@ -152,7 +152,7 @@ export function switchThumbStyles(
152
152
  transition-timing-function: ${input.switch.transitionTimingFunction};
153
153
  background: var(--switch-fg-color);
154
154
  transform: translate3d(0, 0, 0);
155
- box-shadow: 0px 1px 0px 0px rgba(0, 0, 0, 0.1);
155
+ box-shadow: 0px 1px 0px 0px rgba(0, 0, 0, 0.05);
156
156
 
157
157
  ${checked &&
158
158
  css`
@@ -9,6 +9,10 @@ export function compileColorTokenValue(node: TokenColorValueNode): string {
9
9
  key = `${node.hue}/${node.tint}`
10
10
  }
11
11
 
12
+ if (node.mix !== undefined) {
13
+ return `${key} ${node.mix * 100}%`
14
+ }
15
+
12
16
  if (node.opacity !== undefined) {
13
17
  key += `/${node.opacity}`
14
18
  }
@@ -1,7 +1,7 @@
1
1
  import {ColorTint as ColorPaletteValue} from '@sanity/color'
2
2
  import {ThemeColorPalette, parseTokenValue} from '../config'
3
3
  import {ThemeColorBlendModeKey} from '../system'
4
- import {rgba} from './lib/color-fns'
4
+ import {hexToRgb, mix, rgbToHex, rgba} from './lib/color-fns'
5
5
  import {mixThemeColor} from './mixThemeColor'
6
6
 
7
7
  export interface RenderColorValueOptions {
@@ -53,6 +53,13 @@ export function renderColorValue(str: string, options: RenderColorValueOptions):
53
53
 
54
54
  try {
55
55
  hex = mixThemeColor(hex, mixOptions)
56
+
57
+ if (bg && node.mix !== undefined) {
58
+ const from = hexToRgb(bg)
59
+ const to = hexToRgb(hex)
60
+
61
+ hex = rgbToHex(mix(from, to, node.mix))
62
+ }
56
63
  } catch (err) {
57
64
  // eslint-disable-next-line no-console
58
65
  console.warn('could not blend', hex, mixOptions)
@@ -63,11 +63,13 @@ export type ColorConfigValue =
63
63
  | `black/${ColorConfigOpacityValue}`
64
64
  | `white/${ColorConfigOpacityValue}`
65
65
  | `${ColorHueKey}`
66
+ | `${ColorHueKey} ${number}%`
66
67
  | `${ColorHueKey}/${ColorTintKey}`
68
+ | `${ColorHueKey}/${ColorTintKey} ${number}%`
67
69
  | `${ColorHueKey}/${ColorTintKey}/${ColorConfigOpacityValue}`
68
70
  | `${ColorTintKey}`
71
+ | `${ColorTintKey} ${number}%`
69
72
  | `${ColorTintKey}/${ColorConfigOpacityValue}`
70
- | ThemeColorBlendModeKey
71
73
 
72
74
  /** @public */
73
75
  export type ThemeColorTokenValue = [ColorConfigValue, ColorConfigValue]
@@ -11,13 +11,25 @@ test('parse color value', () => {
11
11
  tint: '50',
12
12
  })
13
13
 
14
+ expect(parseTokenValue('50 50%')).toEqual({
15
+ type: 'color',
16
+ tint: '50',
17
+ mix: 0.5,
18
+ })
19
+
14
20
  expect(parseTokenValue('cyan/500')).toEqual({
15
21
  type: 'color',
16
- key: 'cyan/500',
17
22
  hue: 'cyan',
18
23
  tint: '500',
19
24
  })
20
25
 
26
+ expect(parseTokenValue('cyan/500 50%')).toEqual({
27
+ type: 'color',
28
+ hue: 'cyan',
29
+ mix: 0.5,
30
+ tint: '500',
31
+ })
32
+
21
33
  expect(parseTokenValue('screen')).toEqual({
22
34
  type: 'blendMode',
23
35
  value: 'screen',
@@ -27,19 +39,4 @@ test('parse color value', () => {
27
39
  type: 'blendMode',
28
40
  value: 'multiply',
29
41
  })
30
-
31
- expect(parseTokenValue('0')).toEqual({
32
- type: 'color',
33
- opacity: 0,
34
- })
35
-
36
- expect(parseTokenValue('0.1')).toEqual({
37
- type: 'color',
38
- opacity: 0.1,
39
- })
40
-
41
- expect(parseTokenValue('1')).toEqual({
42
- type: 'color',
43
- opacity: 1,
44
- })
45
42
  })
@@ -2,15 +2,32 @@ import {isColorBlendModeValue, isColorHueKey, isColorTintKey} from '../../system
2
2
  import {isColorOpacityValue, isColorValue} from '../helpers'
3
3
  import {TokenValueNode} from './types'
4
4
 
5
+ function isColorMixPercentValue(str: string): str is `${number}%` {
6
+ return /^\d+%$/.test(str)
7
+ }
8
+
5
9
  /** @internal */
6
10
  export function parseTokenValue(str: string): TokenValueNode | undefined {
7
11
  const segments = str.split('/')
8
- const segment0 = segments.shift() || ''
12
+
13
+ let nextSegment = segments.shift() || ''
14
+
15
+ const [segment0, segment0mix] = nextSegment.split(' ')
9
16
 
10
17
  if (isColorTintKey(segment0)) {
11
18
  const tint = segment0
12
19
  const segment1 = segments.shift() || ''
13
20
 
21
+ if (isColorMixPercentValue(segment0mix)) {
22
+ const mix = Number(segment0mix.slice(0, -1)) / 100
23
+
24
+ return {
25
+ type: 'color',
26
+ tint,
27
+ mix,
28
+ }
29
+ }
30
+
14
31
  if (isColorOpacityValue(segment1)) {
15
32
  const opacity = Number(segment1)
16
33
 
@@ -31,6 +48,16 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
31
48
  const key = segment0 as 'black' | 'white'
32
49
  const segment1 = segments.shift() || ''
33
50
 
51
+ if (isColorMixPercentValue(segment0mix)) {
52
+ const mix = Number(segment0mix.slice(0, -1)) / 100
53
+
54
+ return {
55
+ type: 'color',
56
+ key,
57
+ mix,
58
+ }
59
+ }
60
+
34
61
  if (isColorOpacityValue(segment1)) {
35
62
  const opacity = Number(segment1)
36
63
 
@@ -49,18 +76,31 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
49
76
 
50
77
  if (isColorHueKey(segment0)) {
51
78
  const hue = segment0
52
- const segment1 = segments.shift() || ''
79
+
80
+ nextSegment = segments.shift() || ''
81
+
82
+ const [segment1, segment1mix] = nextSegment.split(' ')
53
83
 
54
84
  if (isColorTintKey(segment1)) {
55
85
  const tint = segment1
56
86
  const segment2 = segments.shift() || ''
57
87
 
88
+ if (isColorMixPercentValue(segment1mix)) {
89
+ const mix = Number(segment1mix.slice(0, -1)) / 100
90
+
91
+ return {
92
+ type: 'color',
93
+ hue,
94
+ tint,
95
+ mix,
96
+ }
97
+ }
98
+
58
99
  if (isColorOpacityValue(segment2)) {
59
100
  const opacity = Number(segment2)
60
101
 
61
102
  return {
62
103
  type: 'color',
63
- key: `${hue}/${tint}`,
64
104
  hue,
65
105
  tint,
66
106
  opacity,
@@ -69,7 +109,6 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
69
109
 
70
110
  return {
71
111
  type: 'color',
72
- key: `${hue}/${tint}`,
73
112
  hue,
74
113
  tint,
75
114
  }
@@ -77,16 +116,7 @@ export function parseTokenValue(str: string): TokenValueNode | undefined {
77
116
 
78
117
  return {
79
118
  type: 'hue',
80
- value: `${hue}`,
81
- }
82
- }
83
-
84
- if (isColorOpacityValue(segment0)) {
85
- const opacity = Number(segment0)
86
-
87
- return {
88
- type: 'color',
89
- opacity,
119
+ value: hue,
90
120
  }
91
121
  }
92
122
 
@@ -29,10 +29,11 @@ export type TokenKeyNode = TokenBaseKeyNode | TokenButtonKeyNode
29
29
  /** @internal */
30
30
  export interface TokenColorValueNode {
31
31
  type: 'color'
32
- key?: 'black' | 'white' | `${ColorHueKey}/${ColorTintKey}` | ColorTintKey
32
+ key?: 'black' | 'white'
33
33
  hue?: ColorHueKey
34
- tint?: ColorTintKey
34
+ mix?: number
35
35
  opacity?: number
36
+ tint?: ColorTintKey
36
37
  }
37
38
 
38
39
  /** @internal */