@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/dist/index.d.ts +25 -0
- package/dist/index.js +47 -1
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/badge/Badge.tsx +53 -0
- package/src/components/badge/badge.css +6 -0
- package/src/components/badge/badge.props.ts +31 -0
- package/src/components/index.css +1 -0
- package/src/index.ts +1 -0
- package/src/version.ts +2 -2
package/package.json
CHANGED
|
@@ -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,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
|
+
}
|
package/src/components/index.css
CHANGED
package/src/index.ts
CHANGED
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 = '
|
|
3
|
-
export const HASH = '
|
|
2
|
+
export const VERSION = '500alpha9'
|
|
3
|
+
export const HASH = 'fd663f'
|