@sanity/ui 2.0.0-alpha.2 → 2.0.0-alpha.21

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 (96) hide show
  1. package/dist/index.cjs.mjs +28 -0
  2. package/dist/index.d.ts +476 -12
  3. package/dist/index.esm.js +1326 -524
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +1353 -523
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -8
  8. package/src/components/autocomplete/autocomplete.tsx +6 -0
  9. package/src/components/dialog/constants.ts +4 -0
  10. package/src/components/dialog/dialog.tsx +79 -15
  11. package/src/components/hotkeys/hotkeys.tsx +2 -0
  12. package/src/components/menu/menu.tsx +2 -0
  13. package/src/components/menu/menuButton.tsx +2 -0
  14. package/src/components/menu/menuGroup.tsx +22 -23
  15. package/src/components/menu/menuItem.tsx +29 -35
  16. package/src/components/tab/tab.tsx +4 -1
  17. package/src/components/toast/toast.tsx +4 -0
  18. package/src/primitives/_selectable/style.ts +2 -1
  19. package/src/primitives/avatar/avatar.tsx +16 -9
  20. package/src/primitives/avatar/avatarCounter.tsx +3 -3
  21. package/src/primitives/avatar/styles.ts +1 -1
  22. package/src/primitives/badge/badge.tsx +7 -3
  23. package/src/primitives/box/box.tsx +3 -0
  24. package/src/primitives/button/__workshop__/sanityUploadButton.tsx +2 -1
  25. package/src/primitives/button/button.tsx +7 -3
  26. package/src/primitives/button/styles.ts +9 -2
  27. package/src/primitives/card/card.tsx +4 -0
  28. package/src/primitives/card/styles.ts +2 -0
  29. package/src/primitives/checkbox/checkbox.tsx +2 -0
  30. package/src/primitives/code/code.tsx +1 -0
  31. package/src/primitives/container/container.tsx +2 -0
  32. package/src/primitives/flex/flex.tsx +2 -0
  33. package/src/primitives/grid/grid.tsx +2 -0
  34. package/src/primitives/heading/heading.tsx +2 -0
  35. package/src/primitives/inline/inline.tsx +3 -0
  36. package/src/primitives/kbd/kbd.tsx +2 -0
  37. package/src/primitives/label/label.tsx +2 -0
  38. package/src/primitives/popover/popover.tsx +6 -1
  39. package/src/primitives/radio/radio.tsx +2 -0
  40. package/src/primitives/select/select.tsx +2 -0
  41. package/src/primitives/select/styles.ts +2 -0
  42. package/src/primitives/spinner/spinner.tsx +2 -0
  43. package/src/primitives/stack/stack.tsx +2 -0
  44. package/src/primitives/switch/switch.tsx +4 -0
  45. package/src/primitives/text/text.tsx +3 -0
  46. package/src/primitives/textArea/textArea.tsx +4 -1
  47. package/src/primitives/textInput/textInput.tsx +10 -1
  48. package/src/primitives/tooltip/__workshop__/customPortal.tsx +99 -0
  49. package/src/primitives/tooltip/__workshop__/index.ts +15 -0
  50. package/src/primitives/tooltip/__workshop__/overflowingBoundary.tsx +73 -0
  51. package/src/primitives/tooltip/__workshop__/resizableBoundary.tsx +85 -0
  52. package/src/primitives/tooltip/constants.ts +1 -0
  53. package/src/primitives/tooltip/tooltip.test.tsx +192 -0
  54. package/src/primitives/tooltip/tooltip.tsx +109 -33
  55. package/src/primitives/types.ts +4 -0
  56. package/src/styles/input/textInputStyle.ts +11 -6
  57. package/src/theme/_internal/__workshop__/build/story.tsx +288 -0
  58. package/src/theme/_internal/__workshop__/build/theme.ts +3 -0
  59. package/src/theme/_internal/__workshop__/index.ts +14 -0
  60. package/src/theme/_internal/build/buildTheme.test.ts +78 -0
  61. package/src/theme/_internal/build/buildTheme.ts +16 -0
  62. package/src/theme/_internal/build/colorTheme/buildColorTheme.test.ts +185 -0
  63. package/src/theme/_internal/build/colorTheme/buildColorTheme.ts +164 -0
  64. package/src/theme/_internal/build/colorTheme/renderColorTheme.ts +242 -0
  65. package/src/theme/_internal/build/colorTheme/resolveColorTokens.ts +121 -0
  66. package/src/theme/_internal/build/defaults/colorPalette.ts +8 -0
  67. package/src/theme/_internal/build/defaults/colorTokens.ts +147 -0
  68. package/src/theme/_internal/build/helpers.ts +65 -0
  69. package/src/theme/_internal/build/index.ts +1 -0
  70. package/src/theme/_internal/config/helpers.ts +47 -0
  71. package/src/theme/_internal/config/index.ts +3 -0
  72. package/src/theme/_internal/config/token/index.ts +2 -0
  73. package/src/theme/_internal/config/token/parseTokenKey.test.ts +72 -0
  74. package/src/theme/_internal/config/token/parseTokenKey.ts +88 -0
  75. package/src/theme/_internal/config/token/parseTokenValue.test.ts +45 -0
  76. package/src/theme/_internal/config/token/parseTokenValue.ts +123 -0
  77. package/src/theme/_internal/config/types.ts +137 -0
  78. package/src/theme/_internal/constants.ts +48 -0
  79. package/src/theme/_internal/helpers.ts +19 -0
  80. package/src/theme/_internal/index.ts +5 -0
  81. package/src/theme/_internal/types.ts +91 -0
  82. package/src/theme/index.ts +1 -0
  83. package/src/theme/lib/color-fns/blend/multiply.ts +2 -2
  84. package/src/theme/lib/color-fns/blend/screen.ts +2 -2
  85. package/src/theme/lib/color-fns/convert.ts +15 -1
  86. package/src/theme/lib/color-fns/parse.ts +7 -3
  87. package/src/theme/lib/color-fns/types.ts +11 -0
  88. package/src/theme/lib/theme/avatar.ts +2 -0
  89. package/src/theme/lib/theme/color/_legacy/createColorTheme.ts +7 -0
  90. package/src/theme/lib/theme/color/_legacy/index.ts +1 -0
  91. package/src/theme/lib/theme/color/_legacy/legacyColor.ts +3997 -0
  92. package/src/theme/studioTheme/color.ts +98 -82
  93. package/src/theme/studioTheme/helpers.ts +15 -1
  94. package/src/theme/studioTheme/theme.ts +5 -5
  95. package/src/theme/studioTheme/tints.ts +244 -84
  96. package/src/types/button.ts +5 -0
@@ -0,0 +1,91 @@
1
+ import {ColorBlendModeValue} from './config'
2
+ import {
3
+ COLOR_BASE_TONES,
4
+ COLOR_BUTTON_MODES,
5
+ COLOR_HUES,
6
+ COLOR_STATE_TONES,
7
+ COLOR_STATES,
8
+ COLOR_TINTS,
9
+ } from './constants'
10
+
11
+ export type ColorHueValue = (typeof COLOR_HUES)[number]
12
+
13
+ export type ColorTintValue = (typeof COLOR_TINTS)[number]
14
+
15
+ export type ColorBaseTone = (typeof COLOR_BASE_TONES)[number]
16
+
17
+ export type ColorButtonMode = (typeof COLOR_BUTTON_MODES)[number]
18
+
19
+ export type ColorState = (typeof COLOR_STATES)[number]
20
+
21
+ export type ColorStateTone = (typeof COLOR_STATE_TONES)[number]
22
+
23
+ export interface TMP_StateColorTheme {
24
+ _blend: ColorBlendModeValue
25
+ bg: string
26
+ bg2?: string
27
+ fg: string
28
+ border: string
29
+ muted: {
30
+ fg: string
31
+ }
32
+ accent: {
33
+ fg: string
34
+ }
35
+ link: {
36
+ fg: string
37
+ }
38
+ code: {
39
+ bg: string
40
+ fg: string
41
+ }
42
+ skeleton?: {
43
+ from: string
44
+ to: string
45
+ }
46
+ }
47
+
48
+ export type TMP_ButtonStatesColorTheme = Record<ColorState, TMP_StateColorTheme>
49
+
50
+ export type TMP_ButtonModesColorTheme = Record<ColorButtonMode, TMP_ButtonStatesColorTheme>
51
+
52
+ export type TMP_ButtonColorTheme = Record<ColorStateTone, TMP_ButtonModesColorTheme>
53
+
54
+ export interface TMP_BaseColorTheme {
55
+ _blend: ColorBlendModeValue
56
+ dark: boolean
57
+ // base: ThemeColorBase
58
+ base: {
59
+ bg: string
60
+ fg: string
61
+ border: string
62
+ focusRing: string
63
+ shadow: {
64
+ outline: string
65
+ umbra: string
66
+ penumbra: string
67
+ ambient: string
68
+ }
69
+ skeleton: {
70
+ from: string
71
+ to: string
72
+ }
73
+ }
74
+ button: TMP_ButtonColorTheme
75
+ // card: ThemeColorCard
76
+ // input: ThemeColorInput
77
+ // selectable?: ThemeColorSelectable
78
+ // spot: ThemeColorSpot
79
+ // syntax: ThemeColorSyntax
80
+ // solid: ThemeColorSolid
81
+ // muted: ThemeColorMuted
82
+ }
83
+
84
+ export type TMP_ColorTheme = Record<ColorBaseTone, TMP_BaseColorTheme>
85
+
86
+ export interface TMP_Theme {
87
+ color: {
88
+ light: TMP_ColorTheme
89
+ dark: TMP_ColorTheme
90
+ }
91
+ }
@@ -1,3 +1,4 @@
1
+ export * from './_internal'
1
2
  export * from './lib/color-fns'
2
3
  export * from './lib/theme'
3
4
  export * from './studioTheme'
@@ -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
  }
@@ -5,6 +5,17 @@ export interface RGB {
5
5
  r: number
6
6
  g: number
7
7
  b: number
8
+ a?: undefined
9
+ }
10
+
11
+ /**
12
+ * @internal
13
+ */
14
+ export interface RGBA {
15
+ r: number
16
+ g: number
17
+ b: number
18
+ a: number
8
19
  }
9
20
 
10
21
  /**
@@ -5,7 +5,9 @@ import {FocusRing} from '../../types'
5
5
  */
6
6
  export interface ThemeAvatar {
7
7
  sizes: {
8
+ /** Distance between avatars in an <AvatarStack> component (px) */
8
9
  distance: number
10
+ /** Diameter (px) */
9
11
  size: number
10
12
  }[]
11
13
  focusRing: FocusRing
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @internal
3
+ * @deprecated Use studioTheme instead.
4
+ */
5
+ export function createColorTheme(): null {
6
+ return null
7
+ }
@@ -0,0 +1 @@
1
+ export * from './createColorTheme'