refactor(Badge): forward native span props via spread
This commit is contained in:
@@ -1,14 +1,10 @@
|
|||||||
import type { ReactNode } from 'react';
|
import type { ComponentPropsWithoutRef } from 'react';
|
||||||
import { cn } from '$shared/lib';
|
import { cn } from '$shared/lib';
|
||||||
|
|
||||||
export type BadgeVariant = 'default' | 'primary' | 'secondary' | 'outline';
|
export type BadgeVariant = 'default' | 'primary' | 'secondary' | 'outline';
|
||||||
export type BadgeSize = 'xs' | 'sm' | 'md';
|
export type BadgeSize = 'xs' | 'sm' | 'md';
|
||||||
|
|
||||||
interface Props {
|
interface Props extends Pick<ComponentPropsWithoutRef<'span'>, 'children' | 'className' | 'style'> {
|
||||||
/**
|
|
||||||
* Badge content
|
|
||||||
*/
|
|
||||||
children: ReactNode;
|
|
||||||
/**
|
/**
|
||||||
* Visual variant
|
* Visual variant
|
||||||
* @default 'default'
|
* @default 'default'
|
||||||
@@ -19,10 +15,6 @@ interface Props {
|
|||||||
* @default 'sm'
|
* @default 'sm'
|
||||||
*/
|
*/
|
||||||
size?: BadgeSize;
|
size?: BadgeSize;
|
||||||
/**
|
|
||||||
* Additional CSS classes
|
|
||||||
*/
|
|
||||||
className?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const VARIANTS: Record<BadgeVariant, string> = {
|
const VARIANTS: Record<BadgeVariant, string> = {
|
||||||
@@ -41,9 +33,17 @@ const SIZES: Record<BadgeSize, string> = {
|
|||||||
/**
|
/**
|
||||||
* Small label for categorization or status.
|
* Small label for categorization or status.
|
||||||
*/
|
*/
|
||||||
export function Badge({ children, variant = 'default', size = 'sm', className }: Props) {
|
export function Badge({ children, variant = 'default', size = 'sm', className, ...rest }: Props) {
|
||||||
return (
|
return (
|
||||||
<span className={cn('inline-block uppercase tracking-wider', SIZES[size], VARIANTS[variant], className)}>
|
<span
|
||||||
|
className={cn(
|
||||||
|
'inline-flex items-center leading-none uppercase tracking-wider',
|
||||||
|
SIZES[size],
|
||||||
|
VARIANTS[variant],
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user