@sanity/ui 5.0.0-alpha.8 → 5.0.0-alpha.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": "5.0.0-alpha.8",
3
+ "version": "5.0.0-alpha.9",
4
4
  "description": "Sanity UI Library",
5
5
  "keywords": [
6
6
  "components",
@@ -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,4 @@
1
+ @import './badge/badge.css';
1
2
  @import './box/box.css';
2
3
  @import './button/button.css';
3
4
  @import './card/card.css';
package/src/index.ts CHANGED
@@ -62,3 +62,4 @@ export type {TextSize} from './types/Text'
62
62
  export type {TextAlign} from './types/TextAlign'
63
63
  export type {FontWeight} from './types/FontWeight'
64
64
  export type {Tone} from './types/Tone'
65
+ export * from './components/badge/Badge'
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 = '500alpha8'
3
- export const HASH = 'ff7a34'
2
+ export const VERSION = '500alpha9'
3
+ export const HASH = 'fd663f'