@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "5.0.0-alpha.2",
3
+ "version": "5.0.0-alpha.21",
4
4
  "description": "Sanity UI Library",
5
5
  "keywords": [
6
6
  "components",
@@ -30,11 +30,14 @@
30
30
  ],
31
31
  "type": "module",
32
32
  "sideEffects": [
33
- "*.css"
33
+ "*.css",
34
+ "./src/polyfills.ts",
35
+ "./dist/polyfills.js"
34
36
  ],
35
37
  "types": "./dist/index.d.ts",
36
38
  "exports": {
37
39
  ".": "./dist/index.js",
40
+ "./polyfills": "./dist/polyfills.js",
38
41
  "./package.json": "./package.json",
39
42
  "./styles.css": {
40
43
  "types": "./src/styles.css.d.ts",
@@ -45,31 +48,35 @@
45
48
  }
46
49
  },
47
50
  "dependencies": {
48
- "@sanity-labs/design-tokens": "0.0.2-alpha.4",
49
- "@sanity/icons": "^3.7.4",
51
+ "@sanity-labs/design-tokens": "0.0.2-alpha.9",
52
+ "@sanity/icons": "^5.2.1",
50
53
  "clsx": "^2.1.1",
51
54
  "comment-json": "^5.0.0",
55
+ "dialog-closedby-polyfill": "^1.3.0",
56
+ "interestfor": "^1.0.8",
52
57
  "react-refractor": "^4.0.0"
53
58
  },
54
59
  "devDependencies": {
55
60
  "@sanity/browserslist-config": "^1.0.5",
56
- "@sanity/pkg-utils": "^10.8.2",
57
61
  "@sanity/tsconfig": "^1.0.0",
62
+ "@sanity/tsdown-config": "^0.28.0",
58
63
  "@types/node": "^25.5.2",
59
64
  "@types/postcss-import": "^14.0.3",
60
65
  "@types/postcss-prefix-selector": "^1.16.3",
61
66
  "@types/react": "^19.2.17",
67
+ "@types/react-dom": "^19.2.3",
62
68
  "autoprefixer": "^10.4.27",
63
- "babel-plugin-react-compiler": "^1.0.0",
64
69
  "concurrently": "^9.2.1",
65
70
  "cssnano": "^8.0.0",
71
+ "oxc-transform-react": "^0.149.0",
66
72
  "postcss": "^8.5.14",
67
73
  "postcss-cli": "^11.0.1",
68
74
  "postcss-import": "^16.1.1",
69
75
  "postcss-prefix-selector": "^2.1.1",
70
76
  "postcss-selector-parser": "^7.1.1",
71
77
  "rimraf": "^6.1.3",
72
- "typescript": "^5.9.3",
78
+ "tsdown": "^0.23.0",
79
+ "typescript": "~6.0.2",
73
80
  "vitest": "^4.1.1"
74
81
  },
75
82
  "peerDependencies": {
@@ -83,11 +90,11 @@
83
90
  "build": "pnpm run sync-version && pnpm run clean && pnpm run build:css && pnpm run build:js && pnpm run build:cli",
84
91
  "build:cli": "tsc -p tsconfig.cli.json",
85
92
  "build:css": "NODE_ENV=production postcss src/index.css -o dist/styles.css",
86
- "build:js": "pkg build --strict --check",
93
+ "build:js": "tsdown",
87
94
  "clean": "rimraf dist",
88
95
  "dev": "concurrently -n css,js \"pnpm run dev:css\" \"pnpm run dev:js\"",
89
96
  "dev:css": "postcss src/index.css -o dist/styles.css --watch",
90
- "dev:js": "pkg watch",
97
+ "dev:js": "tsdown --watch",
91
98
  "sync-version": "node scripts/write-version.js",
92
99
  "test": "vitest run",
93
100
  "ts:check": "tsc --noEmit"
@@ -36,7 +36,8 @@ function exactFromRange(range: string | undefined): string | null {
36
36
  *
37
37
  * Icons is already a dependency, so the package manager installs it either way.
38
38
  * It is listed explicitly because apps import icons directly to pass to
39
- * components (`<Button iconStart={AddIcon} />`), and under pnpm an import that
39
+ * components (`import {AddIcon} from '@sanity/icons/Add'`, then
40
+ * `<Button iconStart={AddIcon} />`), and under pnpm an import that
40
41
  * isn't in the app's own package.json doesn't resolve. Dependencies the app
41
42
  * never imports itself (react-refractor, clsx) are left to the package manager.
42
43
  * React/react-dom are peers that belong to the host app, so they are left out
@@ -0,0 +1,50 @@
1
+ import clsx from 'clsx'
2
+ import {useState} from 'react'
3
+
4
+ import {getProps} from '../../utils/getProps'
5
+ import {suffixClassName} from '../../utils/suffixClassName'
6
+ import {Text} from '../text/Text'
7
+ import {type AvatarProps, avatarProps} from './avatar.props'
8
+
9
+ const avatarClassName = suffixClassName('sui-Avatar')
10
+
11
+ /** @public */
12
+ export function Avatar({color = 'gray', size = 1, ...props}: AvatarProps) {
13
+ const {
14
+ className,
15
+ style,
16
+ 'aria-label': ariaLabel,
17
+ name,
18
+ src,
19
+ ...rest
20
+ } = getProps({color, size, ...props}, avatarProps)
21
+ const [error, setError] = useState(false)
22
+
23
+ return (
24
+ <figure
25
+ className={clsx(
26
+ avatarClassName,
27
+ 'sui-display-inline-flex sui-align-items-center sui-justify-content-center sui-radius-full sui-position-relative',
28
+ className,
29
+ )}
30
+ style={style}
31
+ data-ui="Avatar"
32
+ {...rest}
33
+ >
34
+ {src && !error ? (
35
+ <img
36
+ className="sui-radius-full sui-width-full sui-height-full"
37
+ src={src}
38
+ alt={ariaLabel || name}
39
+ onError={() => setError(true)}
40
+ />
41
+ ) : (
42
+ <Text role="img" weight="semibold" aria-label={ariaLabel || name}>
43
+ {name.slice(0, 1)}
44
+ </Text>
45
+ )}
46
+ </figure>
47
+ )
48
+ }
49
+
50
+ export type {AvatarProps}
@@ -0,0 +1,51 @@
1
+ .sui-Avatar {
2
+ border: 1px solid transparent;
3
+ aspect-ratio: 1;
4
+ }
5
+
6
+ .sui-Avatar img {
7
+ border: 1px solid light-dark(var(--white), var(--black));
8
+ object-fit: cover;
9
+ }
10
+
11
+ .sui-Avatar .sui-Text {
12
+ color: light-dark(var(--white), var(--black));
13
+ font-size: inherit;
14
+ text-transform: uppercase;
15
+ }
16
+
17
+ .sui-Avatar.sui-avatar-gray {
18
+ background-color: light-dark(var(--gray-600), var(--gray-400));
19
+ }
20
+
21
+ .sui-Avatar.sui-avatar-blue {
22
+ background-color: light-dark(var(--blue-600), var(--blue-400));
23
+ }
24
+
25
+ .sui-Avatar.sui-avatar-purple {
26
+ background-color: light-dark(var(--purple-600), var(--purple-400));
27
+ }
28
+
29
+ .sui-Avatar.sui-avatar-magenta {
30
+ background-color: light-dark(var(--magenta-600), var(--magenta-400));
31
+ }
32
+
33
+ .sui-Avatar.sui-avatar-red {
34
+ background-color: light-dark(var(--red-600), var(--red-400));
35
+ }
36
+
37
+ .sui-Avatar.sui-avatar-orange {
38
+ background-color: light-dark(var(--orange-600), var(--orange-400));
39
+ }
40
+
41
+ .sui-Avatar.sui-avatar-yellow {
42
+ background-color: light-dark(var(--yellow-600), var(--yellow-400));
43
+ }
44
+
45
+ .sui-Avatar.sui-avatar-green {
46
+ background-color: light-dark(var(--green-600), var(--green-400));
47
+ }
48
+
49
+ .sui-Avatar.sui-avatar-cyan {
50
+ background-color: light-dark(var(--cyan-600), var(--cyan-400));
51
+ }
@@ -0,0 +1,57 @@
1
+ import {heightProps} from '../../props/height'
2
+ import {AVATAR_COLOR, AVATAR_SIZE, type AvatarColor, type AvatarSize} from '../../types/Avatar'
3
+ import {type PropDef} from '../../types/PropDef'
4
+ import type {Responsive} from '../../types/Responsive'
5
+ import {TEXT_SIZE} from '../../types/Text'
6
+
7
+ /** @public */
8
+ export interface AvatarProps extends React.ComponentProps<'figure'> {
9
+ /** Avatar color */
10
+ color?: AvatarColor
11
+ /** Avatar name, only first letter will be displayed */
12
+ name: string
13
+ /** Composite prop for setting height and font size */
14
+ size?: Responsive<AvatarSize>
15
+ /** Avatar image src */
16
+ src?: string
17
+ }
18
+
19
+ export const avatarProps: Record<string, PropDef> = {
20
+ color: {
21
+ type: 'union',
22
+ className: 'avatar',
23
+ values: AVATAR_COLOR,
24
+ },
25
+ name: {
26
+ type: 'string',
27
+ },
28
+ size: {
29
+ type: 'composite',
30
+ values: AVATAR_SIZE,
31
+ composition: {
32
+ size: {
33
+ propDef: {
34
+ type: 'union',
35
+ className: 'text-body',
36
+ values: TEXT_SIZE,
37
+ },
38
+ mapping: {
39
+ 0: 0,
40
+ 1: 1,
41
+ 2: 2,
42
+ },
43
+ },
44
+ height: {
45
+ propDef: heightProps['height'] as PropDef,
46
+ mapping: {
47
+ 0: '19px',
48
+ 1: '25px',
49
+ 2: '33px',
50
+ },
51
+ },
52
+ },
53
+ },
54
+ src: {
55
+ type: 'string',
56
+ },
57
+ }
@@ -0,0 +1,38 @@
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 AvatarCounterProps, avatarCounterProps} from './avatarCounter.props'
7
+
8
+ const avatarCounterClassName = suffixClassName('sui-AvatarCounter')
9
+
10
+ /** @public */
11
+ export function AvatarCounter({size = 1, ...props}: AvatarCounterProps) {
12
+ const {
13
+ className,
14
+ style,
15
+ 'aria-label': ariaLabel,
16
+ count,
17
+ ...rest
18
+ } = getProps({size, ...props}, avatarCounterProps)
19
+
20
+ return (
21
+ <figure
22
+ className={clsx(
23
+ avatarCounterClassName,
24
+ 'sui-display-inline-flex sui-align-items-center sui-justify-content-center sui-radius-full sui-border',
25
+ className,
26
+ )}
27
+ style={style}
28
+ data-ui="AvatarCounter"
29
+ {...rest}
30
+ >
31
+ <Text role="img" weight="semibold" aria-label={ariaLabel || `+ ${count} more`}>
32
+ {count}
33
+ </Text>
34
+ </figure>
35
+ )
36
+ }
37
+
38
+ export type {AvatarCounterProps}
@@ -0,0 +1,8 @@
1
+ .sui-AvatarCounter {
2
+ aspect-ratio: 1;
3
+ padding-inline: 0.5em;
4
+ }
5
+
6
+ .sui-AvatarCounter .sui-Text {
7
+ font-size: inherit;
8
+ }
@@ -0,0 +1,44 @@
1
+ import {heightProps} from '../../props/height'
2
+ import {AVATAR_SIZE, type AvatarSize} from '../../types/Avatar'
3
+ import {type PropDef} from '../../types/PropDef'
4
+ import {TEXT_SIZE} from '../../types/Text'
5
+
6
+ /** @public */
7
+ export interface AvatarCounterProps extends React.ComponentProps<'figure'> {
8
+ /** Count */
9
+ count: number
10
+ /** Composite prop for setting height and font size */
11
+ size?: AvatarSize
12
+ }
13
+
14
+ export const avatarCounterProps: Record<string, PropDef> = {
15
+ count: {
16
+ type: 'number',
17
+ },
18
+ size: {
19
+ type: 'composite',
20
+ values: AVATAR_SIZE,
21
+ composition: {
22
+ size: {
23
+ propDef: {
24
+ type: 'union',
25
+ className: 'text-body',
26
+ values: TEXT_SIZE,
27
+ },
28
+ mapping: {
29
+ 0: 0,
30
+ 1: 1,
31
+ 2: 2,
32
+ },
33
+ },
34
+ height: {
35
+ propDef: heightProps['height'] as PropDef,
36
+ mapping: {
37
+ 0: '19px',
38
+ 1: '25px',
39
+ 2: '33px',
40
+ },
41
+ },
42
+ },
43
+ },
44
+ }
@@ -0,0 +1,60 @@
1
+ import clsx from 'clsx'
2
+ import {Children, cloneElement, isValidElement, type ReactElement} from 'react'
3
+
4
+ import {getProps} from '../../utils/getProps'
5
+ import {suffixClassName} from '../../utils/suffixClassName'
6
+ import {AvatarCounter} from '../avatar-counter/AvatarCounter'
7
+ import type {AvatarProps} from '../avatar/avatar.props'
8
+ import {type AvatarStackProps, avatarStackProps} from './avatarStack.props'
9
+
10
+ const avatarStackClassName = suffixClassName('sui-AvatarStack')
11
+
12
+ /** @public */
13
+ export function AvatarStack({size = 1, ...props}: AvatarStackProps) {
14
+ const {
15
+ children,
16
+ className,
17
+ style,
18
+ maxLength: maxLengthProp,
19
+ size: sizeProp,
20
+ ...rest
21
+ } = getProps({size, ...props}, avatarStackProps)
22
+ const childArray = Children.toArray(children).filter(
23
+ isValidElement,
24
+ ) as ReactElement<AvatarProps>[]
25
+ const length = childArray.length
26
+ const maxLength = maxLengthProp ?? length
27
+ const visibleAvatars =
28
+ length > maxLength ? childArray.slice(length - maxLength, length) : childArray
29
+
30
+ return (
31
+ <ul
32
+ className={clsx(avatarStackClassName, 'sui-display-flex', className)}
33
+ style={style}
34
+ data-ui="AvatarStack"
35
+ {...rest}
36
+ >
37
+ {(!length || length > maxLength) && (
38
+ <li className="sui-display-flex">
39
+ <AvatarCounter
40
+ count={!length ? 0 : length - maxLength}
41
+ size={sizeProp}
42
+ aria-label={
43
+ !length
44
+ ? 'No users'
45
+ : `+ ${length - maxLength} more user${length - maxLength > 1 ? 's' : ''}`
46
+ }
47
+ />
48
+ </li>
49
+ )}
50
+
51
+ {visibleAvatars.map((child) => (
52
+ <li key={child.key} className="sui-display-flex">
53
+ {cloneElement(child, {size: sizeProp})}
54
+ </li>
55
+ ))}
56
+ </ul>
57
+ )
58
+ }
59
+
60
+ export type {AvatarStackProps}
@@ -0,0 +1,16 @@
1
+ .sui-AvatarStack {
2
+ list-style: none;
3
+ }
4
+
5
+ .sui-AvatarStack li:has([class*='sui-Avatar']) + li:has([class*='sui-Avatar']) {
6
+ margin-left: calc(-1 * var(--space-1));
7
+ }
8
+
9
+ .sui-AvatarStack li:has(+ li [class*='sui-Avatar']) {
10
+ mask-image: radial-gradient(
11
+ 50% 50% at calc(150% - var(--space-1) - 1.25px) 50%,
12
+ transparent 97.5%,
13
+ #000 100%
14
+ );
15
+ }
16
+
@@ -0,0 +1,20 @@
1
+ import {AVATAR_SIZE, type AvatarSize} from '../../types/Avatar'
2
+ import {type PropDef} from '../../types/PropDef'
3
+
4
+ /** @public */
5
+ export interface AvatarStackProps extends React.ComponentProps<'ul'> {
6
+ /** Max number of avatars to display */
7
+ maxLength?: number
8
+ /** Avatar and AvatarCounter size */
9
+ size?: AvatarSize
10
+ }
11
+
12
+ export const avatarStackProps: Record<string, PropDef> = {
13
+ maxLength: {
14
+ type: 'number',
15
+ },
16
+ size: {
17
+ type: 'union',
18
+ values: AVATAR_SIZE,
19
+ },
20
+ }
@@ -0,0 +1,53 @@
1
+ import clsx from 'clsx'
2
+ import {isValidElement, type ComponentPropsWithRef, type ElementType} from 'react'
3
+
4
+ import {getProps} from '../../utils/getProps'
5
+ import {suffixClassName} from '../../utils/suffixClassName'
6
+ import {Icon} from '../icon/Icon'
7
+ import {Text} from '../text/Text'
8
+ import {type BadgeProps, badgeProps} from './badge.props'
9
+
10
+ const badgeClassName = suffixClassName('sui-Badge')
11
+
12
+ /** @public */
13
+ export function Badge<T extends ElementType = 'span'>({
14
+ tone = 'neutral',
15
+ ...props
16
+ }: BadgeProps<T> & Omit<ComponentPropsWithRef<T>, keyof BadgeProps<T>>) {
17
+ const {
18
+ as,
19
+ children,
20
+ className,
21
+ style,
22
+ iconStart: IconStart,
23
+ text,
24
+ ...rest
25
+ } = getProps({tone, ...props}, badgeProps)
26
+ const Component = as || 'span'
27
+
28
+ const paddingClasses = IconStart ? 'sui-p1' : 'sui-px2 sui-py1'
29
+
30
+ const badgeClasses = clsx(
31
+ badgeClassName,
32
+ `${paddingClasses} sui-radius-full sui-display-inline-flex sui-align-items-center sui-gap1`,
33
+ )
34
+
35
+ return (
36
+ <Component className={clsx(badgeClasses, className)} style={style} data-ui="Badge" {...rest}>
37
+ {IconStart &&
38
+ (isValidElement(IconStart) ? (
39
+ IconStart
40
+ ) : (
41
+ <Icon icon={IconStart} marginX={-1} marginY={-2} size={0} />
42
+ ))}
43
+ {text && (
44
+ <Text size={1} trim>
45
+ {text}
46
+ </Text>
47
+ )}
48
+ {children}
49
+ </Component>
50
+ )
51
+ }
52
+
53
+ export type {BadgeProps}
@@ -0,0 +1,6 @@
1
+ .sui-Badge {
2
+ --badge-background: var(--background-high);
3
+ --badge-color: var(--foreground-high);
4
+ background-color: var(--badge-background);
5
+ color: var(--badge-color);
6
+ }
@@ -0,0 +1,31 @@
1
+ import {type ToneProps, toneProps} from '../../props/tone'
2
+ import {type PropDef} from '../../types/PropDef'
3
+
4
+ /** @public */
5
+ export interface BadgeProps<T extends React.ElementType = 'span'> extends ToneProps {
6
+ /**
7
+ * HTML element to render.
8
+ */
9
+ as?: T
10
+ /**
11
+ * Shows an icon in the start position (left side in left-to-right languages).
12
+ */
13
+ iconStart?: React.ElementType | React.ReactNode
14
+ /**
15
+ * Sets Badge's text label. Use instead of children unless you have a special use case.
16
+ */
17
+ text?: string
18
+ }
19
+
20
+ export const badgeProps: Record<string, PropDef> = {
21
+ as: {
22
+ type: 'string',
23
+ },
24
+ iconStart: {
25
+ type: 'string',
26
+ },
27
+ text: {
28
+ type: 'string',
29
+ },
30
+ ...toneProps,
31
+ }
@@ -1,3 +1,8 @@
1
+ .sui-Box {
2
+ min-width: 0;
3
+ min-height: 0;
4
+ }
5
+
1
6
  .sui-Box[class*='sui-tone'] {
2
7
  --box-background: var(--background-low);
3
8
  background-color: var(--box-background);
@@ -5,9 +5,14 @@ import type {Responsive} from '../../types/Responsive'
5
5
 
6
6
  /** @public */
7
7
  export interface BoxProps<T extends React.ElementType = 'div'> extends LayoutProps {
8
- /** Element to render */
8
+ /**
9
+ * HTML element or component to render.
10
+ */
9
11
  as?: T
10
- /** CSS **display** property */
12
+ /**
13
+ * CSS `display` property.
14
+ * @remarks Does not include `'flex'` or `'grid'`. Use the Flex or Grid components for those.
15
+ */
11
16
  display?: Responsive<DisplayBlock>
12
17
  }
13
18
 
@@ -46,7 +46,13 @@ export function Button<T extends ElementType = 'button'>({
46
46
  {...rest}
47
47
  >
48
48
  {loading && (
49
- <Flex position="absolute" inset={0} alignItems="center" justifyContent="center">
49
+ <Flex
50
+ position="absolute"
51
+ inset={0}
52
+ alignItems="center"
53
+ justifyContent="center"
54
+ data-ui="Button-Spinner"
55
+ >
50
56
  <Spinner />
51
57
  </Flex>
52
58
  )}