import * as React from 'react'; import { cn } from '@/lib/utils'; /** * BadgeProps - Propriétés du composant Badge * * @interface BadgeProps * @extends React.HTMLAttributes */ export interface BadgeProps extends React.HTMLAttributes { /** * Texte du badge (alternative à children) */ label?: string; /** * Variant de couleur du badge * * - `cyan`: Cyan (par défaut) * - `magenta`: Magenta * - `lime`: Lime (vert) * - `gold`: Or * - `terminal`: Style terminal (monospace) * - `default`, `primary`: Alias pour cyan * - `success`: Alias pour lime * - `warning`: Alias pour gold * - `error`: Alias pour magenta * - `secondary`: Alias pour magenta * * @default 'cyan' */ variant?: | 'cyan' | 'magenta' | 'lime' | 'gold' | 'terminal' | 'default' | 'primary' | 'success' | 'warning' | 'error' | 'secondary'; /** * Icône à afficher dans le badge */ icon?: React.ReactNode; /** * Taille du badge * * - `sm`: Petit (px-2 py-0.5 text-[10px]) * - `md`: Moyen (px-2.5 py-0.5 text-[10px]) - par défaut * - `lg`: Grand (px-4 py-1 text-xs) * * @default 'md' */ size?: 'sm' | 'md' | 'lg'; /** * Si `true`, affiche un point au lieu du texte * * @default false */ dot?: boolean; /** * Nombre à afficher dans le badge (pour notifications, etc.) * Si fourni et > 0, affiche le nombre dans un badge secondaire */ count?: number; /** * Contenu du badge (alternative à label) */ children?: React.ReactNode; } /** * Badge - Composant de badge avec design system Kodo * * Composant de badge pour afficher des labels, statuts ou compteurs. * Supporte plusieurs variants de couleur, tailles et options d'affichage. * * @example * ```tsx * // Badge simple * * * // Badge avec variant * Actif * * // Badge avec icône * } label="Premium" /> * * // Badge avec compteur * Notifications * ``` * * @component * @param {BadgeProps} props - Propriétés du composant * @returns {JSX.Element} Élément span stylisé comme un badge */ export const Badge = React.forwardRef( ( { label, variant = 'cyan', icon, size = 'md', dot, count, children, className, ...props }, ref, ) => { // Map compatibility variants to Kodo variants const variantMap: Record = { default: 'cyan', primary: 'cyan', success: 'lime', warning: 'gold', error: 'magenta', secondary: 'magenta', }; const actualVariant = variantMap[variant] || variant; const styles: Record = { cyan: 'bg-muted/10 text-kodo-steel border-border/30', magenta: 'bg-kodo-magenta/10 text-kodo-magenta border-kodo-magenta/30', lime: 'bg-kodo-lime/10 text-kodo-lime border-kodo-lime/30', gold: 'bg-kodo-gold/10 text-kodo-gold border-kodo-gold/30', terminal: 'bg-kodo-terminal/10 text-kodo-terminal border-kodo-terminal/30 font-mono', }; const sizeStyles = { sm: 'px-2 py-0.5 text-xs', md: 'px-2.5 py-0.5 text-xs', lg: 'px-4 py-1 text-xs', }; const displayText = label || children; const badgeVariant = actualVariant as keyof typeof styles; return ( {dot && } {icon && {icon}} {displayText} {count !== undefined && count > 0 && ( {count} )} ); }, ); Badge.displayName = 'Badge';