{
// 子元素
children?: React.ReactNode;
// 是否为圆点样式(不显示文字)
dot?: boolean;
// 圆点颜色(仅当 dot=true 时有效)
dotColor?: string;
}
/**
* Badge 徽章组件
*/
export function Badge({
variant = "default",
size = "md",
dot = false,
dotColor,
className,
children,
...props
}: BadgeProps) {
// 圆点颜色映射
const dotColors = {
default: "bg-gray-400",
primary: "bg-primary-500",
success: "bg-success-500",
warning: "bg-warning-500",
error: "bg-error-500",
info: "bg-info-500",
};
// 确保 variant 有默认值
const actualVariant = variant ?? "default";
return (
{dot && (
)}
{!dot && children}
);
}
/**
* StatusBadge - 状态徽章
*/
export interface StatusBadgeProps extends Omit {
status: "online" | "offline" | "busy" | "away";
label?: string;
}
export function StatusBadge({ status, label, ...props }: StatusBadgeProps) {
const statusConfig = {
online: { variant: "success" as const, defaultLabel: "在线" },
offline: { variant: "default" as const, defaultLabel: "离线" },
busy: { variant: "error" as const, defaultLabel: "忙碌" },
away: { variant: "warning" as const, defaultLabel: "离开" },
};
const config = statusConfig[status];
return (
{label || config.defaultLabel}
);
}
/**
* CounterBadge - 计数徽章
*/
export interface CounterBadgeProps extends Omit {
count: number;
max?: number;
}
export function CounterBadge({ count, max = 99, ...props }: CounterBadgeProps) {
const displayCount = count > max ? `${max}+` : count;
return (
{displayCount}
);
}