Badge

Exports

Import these components from @mbsw/ui.

Badge

Props

The tables list common props for each component. See the full types for supported prop combinations and inherited HTML and Radix props.

Badge

Badge props
PropTypeRequirement
shape'round' | 'square'Optional
size'md' | 'sm'Optional
asChildbooleanConditional
childrenReactNode | ReactElement<unknown, string | JSXElementConstructor<any>>Required

Type reference

Show full types

Full TypeScript definitions, including prop combinations and inherited props.

import { type HTMLAttributes, type ReactElement, type ReactNode, type RefAttributes } from 'react';

export type BadgeShape = 'round' | 'square';

export type BadgeSize = 'md' | 'sm';

type DataAttributes = {
    [key: `data-${string}`]: boolean | number | string | undefined;
};

type BadgeBaseProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'color'> & DataAttributes & {
    shape?: BadgeShape;
    size?: BadgeSize;
};

type NativeBadgeProps = BadgeBaseProps & {
    asChild?: false;
    children: ReactNode;
};

type SlottedBadgeProps = BadgeBaseProps & {
    asChild: true;
    children: ReactElement;
};

export type BadgeProps = (NativeBadgeProps & RefAttributes<HTMLSpanElement>) | (SlottedBadgeProps & RefAttributes<HTMLElement>);

type BadgeComponent = {
    (props: BadgeProps): ReactElement | null;
    displayName?: string;
};

export declare const Badge: BadgeComponent;