@sanity/ui 5.0.0-alpha.2 → 5.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 (140) hide show
  1. package/README.md +1 -1
  2. package/dist/LazyRefractor-CQ22IeXB.js +19 -0
  3. package/dist/LazyRefractor-CQ22IeXB.js.map +1 -0
  4. package/dist/cli/install.js +2 -1
  5. package/dist/index.d.ts +826 -855
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +2439 -1796
  8. package/dist/index.js.map +1 -1
  9. package/dist/polyfills.d.ts +1 -0
  10. package/dist/polyfills.js +5 -0
  11. package/dist/polyfills.js.map +1 -0
  12. package/dist/styles.css +1 -1
  13. package/package.json +16 -9
  14. package/src/cli/install.ts +2 -1
  15. package/src/components/avatar/Avatar.tsx +50 -0
  16. package/src/components/avatar/avatar.css +51 -0
  17. package/src/components/avatar/avatar.props.ts +57 -0
  18. package/src/components/avatar-counter/AvatarCounter.tsx +38 -0
  19. package/src/components/avatar-counter/avatar-counter.css +8 -0
  20. package/src/components/avatar-counter/avatarCounter.props.ts +44 -0
  21. package/src/components/avatar-stack/AvatarStack.tsx +60 -0
  22. package/src/components/avatar-stack/avatar-stack.css +16 -0
  23. package/src/components/avatar-stack/avatarStack.props.ts +20 -0
  24. package/src/components/badge/Badge.tsx +53 -0
  25. package/src/components/badge/badge.css +6 -0
  26. package/src/components/badge/badge.props.ts +31 -0
  27. package/src/components/box/box.css +5 -0
  28. package/src/components/box/box.props.ts +7 -2
  29. package/src/components/button/Button.tsx +7 -1
  30. package/src/components/button/button.css +51 -23
  31. package/src/components/button/button.props.ts +27 -9
  32. package/src/components/card/Card.tsx +1 -1
  33. package/src/components/card/card.props.ts +10 -5
  34. package/src/components/checkbox/Checkbox.tsx +15 -29
  35. package/src/components/checkbox/checkbox.css +19 -20
  36. package/src/components/checkbox/checkbox.props.ts +11 -12
  37. package/src/components/code/Code.tsx +18 -19
  38. package/src/components/code/code.props.ts +23 -14
  39. package/src/components/container/Container.tsx +5 -1
  40. package/src/components/container/container.css +4 -0
  41. package/src/components/container/container.props.ts +6 -2
  42. package/src/components/dialog/Dialog.tsx +139 -0
  43. package/src/components/dialog/dialog.css +49 -0
  44. package/src/components/dialog/dialog.props.ts +45 -0
  45. package/src/components/eyebrow/eyebrow.props.ts +6 -2
  46. package/src/components/flex/flex.css +5 -0
  47. package/src/components/flex/flex.props.ts +6 -2
  48. package/src/components/grid/grid.css +5 -0
  49. package/src/components/grid/grid.props.ts +14 -3
  50. package/src/components/h-stack/HStack.tsx +8 -14
  51. package/src/components/h-stack/hStack.props.ts +5 -13
  52. package/src/components/heading/Heading.tsx +8 -3
  53. package/src/components/heading/heading.css +0 -5
  54. package/src/components/heading/heading.props.ts +16 -5
  55. package/src/components/hotkeys/Hotkeys.tsx +29 -0
  56. package/src/components/hotkeys/hotkeys.css +3 -0
  57. package/src/components/hotkeys/hotkeys.props.ts +15 -0
  58. package/src/components/icon/Icon.tsx +22 -11
  59. package/src/components/icon/icon.props.ts +7 -3
  60. package/src/components/icon-button/iconButton.props.ts +7 -2
  61. package/src/components/index.css +12 -1
  62. package/src/components/indicator/indicator.css +1 -1
  63. package/src/components/indicator/indicator.props.ts +6 -2
  64. package/src/components/indicator-stack/indicatorStack.props.ts +3 -1
  65. package/src/components/inline/inline.props.ts +6 -2
  66. package/src/components/kbd/KBD.tsx +33 -0
  67. package/src/components/kbd/kbd.css +6 -0
  68. package/src/components/kbd/kbd.props.ts +20 -0
  69. package/src/components/link/link.props.ts +4 -4
  70. package/src/components/list/list.props.ts +27 -9
  71. package/src/components/popover/Popover.tsx +85 -0
  72. package/src/components/popover/popover.css +21 -0
  73. package/src/components/popover/popover.props.ts +38 -0
  74. package/src/components/press-area/pressArea.props.ts +3 -1
  75. package/src/components/radio/Radio.tsx +10 -28
  76. package/src/components/radio/radio.css +17 -32
  77. package/src/components/radio/radio.props.ts +1 -19
  78. package/src/components/select/Select.tsx +41 -0
  79. package/src/components/select/select.css +67 -0
  80. package/src/components/select/select.props.ts +18 -0
  81. package/src/components/skip-to-content/skipToContent.props.ts +9 -3
  82. package/src/components/spinner/Spinner.tsx +2 -1
  83. package/src/components/spinner/spinner.props.ts +3 -0
  84. package/src/components/switch/Switch.tsx +9 -21
  85. package/src/components/switch/switch.css +22 -23
  86. package/src/components/switch/switch.props.ts +7 -11
  87. package/src/components/tabs/Tabs.tsx +186 -0
  88. package/src/components/tabs/tabs.css +34 -0
  89. package/src/components/tabs/tabs.props.ts +66 -0
  90. package/src/components/text/text.props.ts +6 -2
  91. package/src/components/text-area/TextArea.tsx +32 -0
  92. package/src/components/text-area/text-area.css +56 -0
  93. package/src/components/text-area/textArea.props.ts +35 -0
  94. package/src/components/text-input/TextInput.tsx +32 -0
  95. package/src/components/text-input/text-input.css +55 -0
  96. package/src/components/text-input/textInput.props.ts +42 -0
  97. package/src/components/tooltip/Tooltip.tsx +59 -55
  98. package/src/components/tooltip/tooltip.css +21 -40
  99. package/src/components/tooltip/tooltip.props.ts +24 -8
  100. package/src/components/tooltip-group/TooltipGroup.tsx +2 -5
  101. package/src/components/tooltip-group/tooltipGroup.props.ts +3 -1
  102. package/src/components/v-stack/VStack.tsx +8 -14
  103. package/src/components/v-stack/vStack.props.ts +5 -13
  104. package/src/components/visually-hidden/visuallyHidden.props.ts +6 -2
  105. package/src/css/classes/dynamic/height.css +2 -0
  106. package/src/css/classes/generic/display.css +8 -8
  107. package/src/css/classes/generic/placement.css +105 -86
  108. package/src/css/classes/local/animation.css +4 -0
  109. package/src/css/classes/local/field-sizing.css +3 -0
  110. package/src/css/classes/local/index.css +3 -1
  111. package/src/css/classes/local/text-trim.css +11 -4
  112. package/src/css/classes/local/top-anchor.css +4 -0
  113. package/src/css/classes/system/shadow.css +6 -6
  114. package/src/css/classes/system/typography.css +0 -4
  115. package/src/css/global/reset.css +16 -1
  116. package/src/css/tokens/semantic.css +7 -6
  117. package/src/css/tokens/surface.css +80 -12
  118. package/src/hooks/useIsClient.ts +10 -0
  119. package/src/index.ts +17 -2
  120. package/src/polyfills.ts +17 -0
  121. package/src/props/formElement.ts +34 -0
  122. package/src/props/layout.ts +3 -3
  123. package/src/props/tone.ts +13 -2
  124. package/src/types/Avatar.ts +14 -0
  125. package/src/types/Code.ts +0 -3
  126. package/src/types/Eyebrow.ts +1 -1
  127. package/src/types/FormElement.ts +2 -0
  128. package/src/types/Heading.ts +1 -1
  129. package/src/types/TextAlign.ts +1 -1
  130. package/src/types/Tone.ts +2 -0
  131. package/src/utils/getProps.ts +1 -1
  132. package/src/utils/mergeTriggerProps.ts +66 -0
  133. package/src/utils/renderPortal.tsx +14 -0
  134. package/src/version.ts +2 -2
  135. package/dist/_chunks-es/LazyRefractor.js +0 -20
  136. package/dist/_chunks-es/LazyRefractor.js.map +0 -1
  137. package/src/components/label/Label.tsx +0 -34
  138. package/src/components/label/label.css +0 -3
  139. package/src/components/label/label.props.ts +0 -19
  140. package/src/css/classes/local/tone.css +0 -75
package/src/props/tone.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import {type PropDef} from '../types/PropDef'
2
- import {TONE, type Tone} from '../types/Tone'
2
+ import {TONE_WITH_DEFAULT, TONE, type ToneWithDefault, type Tone} from '../types/Tone'
3
3
 
4
4
  export type ToneProps = {
5
- /** CSS **background-color** property */
6
5
  tone?: Tone
7
6
  }
8
7
 
@@ -13,3 +12,15 @@ export const toneProps: Record<string, PropDef> = {
13
12
  values: TONE,
14
13
  },
15
14
  }
15
+
16
+ export type ToneWithDefaultProps = {
17
+ tone?: ToneWithDefault
18
+ }
19
+
20
+ export const toneWithDefaultProps: Record<string, PropDef> = {
21
+ tone: {
22
+ type: 'union',
23
+ className: 'tone',
24
+ values: TONE_WITH_DEFAULT,
25
+ },
26
+ }
@@ -0,0 +1,14 @@
1
+ export const AVATAR_SIZE = [0, 1, 2] as const
2
+ export type AvatarSize = (typeof AVATAR_SIZE)[number]
3
+
4
+ export const AVATAR_COLOR = [
5
+ 'gray',
6
+ 'purple',
7
+ 'magenta',
8
+ 'red',
9
+ 'orange',
10
+ 'yellow',
11
+ 'green',
12
+ 'cyan',
13
+ ] as const
14
+ export type AvatarColor = (typeof AVATAR_COLOR)[number]
package/src/types/Code.ts CHANGED
@@ -1,6 +1,3 @@
1
- export const CODE_TAG = ['pre', 'span'] as const
2
- export type CodeTag = (typeof CODE_TAG)[number]
3
-
4
1
  export const CODE_SIZE = [0, 1, 2, 3, 4] as const
5
2
  /** @public */
6
3
  export type CodeSize = (typeof CODE_SIZE)[number]
@@ -1,3 +1,3 @@
1
- export const EYEBROW_SIZE = [0, 1, 2, 3, 4] as const
1
+ export const EYEBROW_SIZE = [0, 1, 2, 3, 4, 5] as const
2
2
  /** @public */
3
3
  export type EyebrowSize = (typeof EYEBROW_SIZE)[number]
@@ -0,0 +1,2 @@
1
+ export const FORM_ELEMENT_DENSITY = ['regular', 'loose'] as const
2
+ export type FormElementDensity = (typeof FORM_ELEMENT_DENSITY)[number]
@@ -1,6 +1,6 @@
1
1
  export const HEADING_TAG = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const
2
2
  export type HeadingTag = (typeof HEADING_TAG)[number]
3
3
 
4
- export const HEADING_SIZE = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] as const
4
+ export const HEADING_SIZE = [0, 1, 2, 3, 4, 5] as const
5
5
  /** @public */
6
6
  export type HeadingSize = (typeof HEADING_SIZE)[number]
@@ -1,3 +1,3 @@
1
- export const TEXT_ALIGN = ['left', 'center', 'right', 'justify'] as const
1
+ export const TEXT_ALIGN = ['left', 'center', 'right'] as const
2
2
  /** @public */
3
3
  export type TextAlign = (typeof TEXT_ALIGN)[number]
package/src/types/Tone.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export const TONE = ['neutral', 'positive', 'suggest', 'caution', 'critical'] as const
2
+ export const TONE_WITH_DEFAULT = ['default', ...TONE]
2
3
  /** @public */
3
4
  export type Tone = (typeof TONE)[number]
5
+ export type ToneWithDefault = (typeof TONE_WITH_DEFAULT)[number]
@@ -5,7 +5,7 @@ import {type PropDef} from '../types/PropDef'
5
5
  const PREFIX = 'sui'
6
6
  const BREAKPOINTS_LENGTH = 6
7
7
 
8
- interface ComponentProps {
8
+ export interface ComponentProps {
9
9
  className?: string | undefined
10
10
  style?: React.CSSProperties | undefined
11
11
  [key: string]: any
@@ -0,0 +1,66 @@
1
+ function isReactEventHandler(key: string, value: unknown): value is (e: never) => void {
2
+ return /^on[A-Z]/.test(key) && typeof value === 'function'
3
+ }
4
+
5
+ function chainEventHandlers<E>(
6
+ ...handlers: (((e: E) => void) | undefined)[]
7
+ ): ((e: E) => void) | undefined {
8
+ const defined = handlers.filter(Boolean) as ((e: E) => void)[]
9
+
10
+ if (defined.length === 0) {
11
+ return undefined
12
+ }
13
+
14
+ if (defined.length === 1) {
15
+ return defined[0]
16
+ }
17
+
18
+ return (e: E) => {
19
+ for (const handler of defined) {
20
+ handler(e)
21
+ }
22
+ }
23
+ }
24
+
25
+ export function mergeTriggerProps(
26
+ childProps: Record<string, unknown>,
27
+ forwardedProps?: Record<string, unknown>,
28
+ ownProps?: Record<string, unknown>,
29
+ ) {
30
+ const result: Record<string, unknown> = {}
31
+
32
+ for (const source of [forwardedProps, ownProps]) {
33
+ if (!source) {
34
+ continue
35
+ }
36
+
37
+ for (const [key, value] of Object.entries(source)) {
38
+ if (key === 'style') {
39
+ continue
40
+ }
41
+
42
+ if (isReactEventHandler(key, value)) {
43
+ result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
44
+ continue
45
+ }
46
+
47
+ if (value !== undefined) {
48
+ result[key] = value
49
+ }
50
+ }
51
+ }
52
+
53
+ result['style'] = {
54
+ ...(childProps['style'] as object),
55
+ ...(forwardedProps?.['style'] as object),
56
+ ...(ownProps?.['style'] as object),
57
+ }
58
+
59
+ for (const [key, value] of Object.entries(childProps)) {
60
+ if (isReactEventHandler(key, value)) {
61
+ result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
62
+ }
63
+ }
64
+
65
+ return result
66
+ }
@@ -0,0 +1,14 @@
1
+ import {type ReactNode} from 'react'
2
+ import {createPortal} from 'react-dom'
3
+
4
+ export function renderPortal(node: ReactNode, mounted: boolean, portal?: boolean) {
5
+ if (!portal) {
6
+ return node
7
+ }
8
+
9
+ if (!mounted) {
10
+ return null
11
+ }
12
+
13
+ return createPortal(node, document.body)
14
+ }
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is generated by scripts/write-version.js. Do not edit.
2
- export const VERSION = '500alpha2'
3
- export const HASH = 'eaf84d'
2
+ export const VERSION = '500alpha21'
3
+ export const HASH = 'd891eb'
@@ -1,20 +0,0 @@
1
- "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { c } from "react/compiler-runtime";
4
- import { hasLanguage, Refractor } from "react-refractor";
5
- function LazyRefractor(t0) {
6
- const $ = c(5), {
7
- language,
8
- value
9
- } = t0;
10
- if (!hasLanguage(language)) {
11
- let t12;
12
- return $[0] !== value ? (t12 = /* @__PURE__ */ jsx("code", { children: value }), $[0] = value, $[1] = t12) : t12 = $[1], t12;
13
- }
14
- let t1;
15
- return $[2] !== language || $[3] !== value ? (t1 = /* @__PURE__ */ jsx(Refractor, { inline: !0, language, value }), $[2] = language, $[3] = value, $[4] = t1) : t1 = $[4], t1;
16
- }
17
- export {
18
- LazyRefractor as default
19
- };
20
- //# sourceMappingURL=LazyRefractor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LazyRefractor.js","sources":["../../src/components/code/LazyRefractor.tsx"],"sourcesContent":["import {hasLanguage, Refractor, type RefractorProps} from 'react-refractor'\n\nexport default function LazyRefractor({language, value}: RefractorProps) {\n if (!hasLanguage(language)) {\n return <code>{value}</code>\n }\n\n return <Refractor inline language={language} value={value} />\n}\n"],"names":["LazyRefractor","t0","$","_c","language","value","hasLanguage","t1"],"mappings":";;;;AAEA,SAAeA,cAAAC,IAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GAAuB;AAAA,IAAAC;AAAAA,IAAAC;AAAAA,EAAAA,IAAAJ;AACpC,MAAI,CAACK,YAAYF,QAAQ,GAAC;AAAA,QAAAG;AAAA,WAAAL,SAAAG,SACjBE,MAAA,oBAAA,QAAA,EAAOF,iBAAM,GAAOH,OAAAG,OAAAH,OAAAK,OAAAA,MAAAL,EAAA,CAAA,GAApBK;AAAAA,EAAoB;AAC5B,MAAAA;AAAA,SAAAL,EAAA,CAAA,MAAAE,YAAAF,SAAAG,SAEME,yBAAC,WAAA,EAAU,YAAiBH,UAAiBC,MAAAA,CAAK,GAAIH,OAAAE,UAAAF,OAAAG,OAAAH,OAAAK,MAAAA,KAAAL,EAAA,CAAA,GAAtDK;AAAsD;"}
@@ -1,34 +0,0 @@
1
- import clsx from 'clsx'
2
-
3
- import {getProps} from '../../utils/getProps'
4
- import {suffixClassName} from '../../utils/suffixClassName'
5
- import {Text} from '../text/Text'
6
- import {type LabelProps, labelProps} from './label.props'
7
-
8
- const labelClassName = suffixClassName('sui-Label')
9
-
10
- /** @beta */
11
- export function Label(props: LabelProps) {
12
- const {children, className, style, disabled, error, ...rest} = getProps(props, labelProps)
13
-
14
- return (
15
- <Text
16
- as="label"
17
- size={1}
18
- muted={disabled}
19
- className={clsx(
20
- labelClassName,
21
- 'sui-display-flex sui-align-items-center sui-gap2',
22
- error && 'sui-error',
23
- className,
24
- )}
25
- style={style}
26
- data-ui="Label"
27
- {...rest}
28
- >
29
- {children}
30
- </Text>
31
- )
32
- }
33
-
34
- export type {LabelProps}
@@ -1,3 +0,0 @@
1
- .sui-Label.sui-error {
2
- color: var(--error-foreground);
3
- }
@@ -1,19 +0,0 @@
1
- import {type MarginProps, marginProps} from '../../props/margin'
2
- import {type PropDef} from '../../types/PropDef'
3
-
4
- /** @beta */
5
- export interface LabelProps extends React.ComponentProps<'label'>, MarginProps {
6
- /** Element to render */
7
- disabled?: boolean
8
- error?: boolean
9
- }
10
-
11
- export const labelProps: Record<string, PropDef> = {
12
- disabled: {
13
- type: 'boolean',
14
- },
15
- error: {
16
- type: 'boolean',
17
- },
18
- ...marginProps,
19
- }
@@ -1,75 +0,0 @@
1
- [class*='sui-tone'] {
2
- /* All .sui-tone classes use white and black for tone-0/-1000 */
3
- --tone-0: light-dark(var(--white), var(--black));
4
- --tone-1000: light-dark(var(--black), var(--white));
5
- }
6
-
7
- .sui-tone-neutral {
8
- --tone-50: light-dark(var(--gray-50), var(--gray-950));
9
- --tone-100: light-dark(var(--gray-100), var(--gray-900));
10
- --tone-200: light-dark(var(--gray-200), var(--gray-800));
11
- --tone-300: light-dark(var(--gray-300), var(--gray-700));
12
- --tone-400: light-dark(var(--gray-400), var(--gray-600));
13
- --tone-500: light-dark(var(--gray-500), var(--gray-500));
14
- --tone-600: light-dark(var(--gray-600), var(--gray-400));
15
- --tone-700: light-dark(var(--gray-700), var(--gray-300));
16
- --tone-800: light-dark(var(--gray-800), var(--gray-200));
17
- --tone-900: light-dark(var(--gray-900), var(--gray-100));
18
- --tone-950: light-dark(var(--gray-950), var(--gray-50));
19
- }
20
-
21
- .sui-tone-suggest {
22
- --tone-50: light-dark(var(--purple-50), var(--purple-950));
23
- --tone-100: light-dark(var(--purple-100), var(--purple-900));
24
- --tone-200: light-dark(var(--purple-200), var(--purple-800));
25
- --tone-300: light-dark(var(--purple-300), var(--purple-700));
26
- --tone-400: light-dark(var(--purple-400), var(--purple-600));
27
- --tone-500: light-dark(var(--purple-500), var(--purple-500));
28
- --tone-600: light-dark(var(--purple-600), var(--purple-400));
29
- --tone-700: light-dark(var(--purple-700), var(--purple-300));
30
- --tone-800: light-dark(var(--purple-800), var(--purple-200));
31
- --tone-900: light-dark(var(--purple-900), var(--purple-100));
32
- --tone-950: light-dark(var(--purple-950), var(--purple-50));
33
- }
34
-
35
- .sui-tone-positive {
36
- --tone-50: light-dark(var(--green-50), var(--green-950));
37
- --tone-100: light-dark(var(--green-100), var(--green-900));
38
- --tone-200: light-dark(var(--green-200), var(--green-800));
39
- --tone-300: light-dark(var(--green-300), var(--green-700));
40
- --tone-400: light-dark(var(--green-400), var(--green-600));
41
- --tone-500: light-dark(var(--green-500), var(--green-500));
42
- --tone-600: light-dark(var(--green-600), var(--green-400));
43
- --tone-700: light-dark(var(--green-700), var(--green-300));
44
- --tone-800: light-dark(var(--green-800), var(--green-200));
45
- --tone-900: light-dark(var(--green-900), var(--green-100));
46
- --tone-950: light-dark(var(--green-950), var(--green-50));
47
- }
48
-
49
- .sui-tone-caution {
50
- --tone-50: light-dark(var(--yellow-50), var(--yellow-950));
51
- --tone-100: light-dark(var(--yellow-100), var(--yellow-900));
52
- --tone-200: light-dark(var(--yellow-200), var(--yellow-800));
53
- --tone-300: light-dark(var(--yellow-300), var(--yellow-700));
54
- --tone-400: light-dark(var(--yellow-400), var(--yellow-600));
55
- --tone-500: light-dark(var(--yellow-500), var(--yellow-500));
56
- --tone-600: light-dark(var(--yellow-600), var(--yellow-400));
57
- --tone-700: light-dark(var(--yellow-700), var(--yellow-300));
58
- --tone-800: light-dark(var(--yellow-800), var(--yellow-200));
59
- --tone-900: light-dark(var(--yellow-900), var(--yellow-100));
60
- --tone-950: light-dark(var(--yellow-950), var(--yellow-50));
61
- }
62
-
63
- .sui-tone-critical {
64
- --tone-50: light-dark(var(--red-50), var(--red-950));
65
- --tone-100: light-dark(var(--red-100), var(--red-900));
66
- --tone-200: light-dark(var(--red-200), var(--red-800));
67
- --tone-300: light-dark(var(--red-300), var(--red-700));
68
- --tone-400: light-dark(var(--red-400), var(--red-600));
69
- --tone-500: light-dark(var(--red-500), var(--red-500));
70
- --tone-600: light-dark(var(--red-600), var(--red-400));
71
- --tone-700: light-dark(var(--red-700), var(--red-300));
72
- --tone-800: light-dark(var(--red-800), var(--red-200));
73
- --tone-900: light-dark(var(--red-900), var(--red-100));
74
- --tone-950: light-dark(var(--red-950), var(--red-50));
75
- }