// frontend/src/components/Card.tsx import type { ReactNode } from 'react' type CardVariant = | 'basic' | 'edge-to-edge-mobile' | 'with-header' | 'with-footer' | 'with-header-footer' | 'with-gray-header' | 'with-gray-footer' | 'with-gray-header-footer' | 'gray-footer' | 'gray-body' | 'well' | 'well-on-gray' | 'well-edge-to-edge-mobile' type CardHeaderVariant = | 'simple' | 'with-action' | 'with-description' | 'with-description-action' | 'with-avatar-actions' | 'with-avatar-meta-actions' | 'custom' type CardProps = { children?: ReactNode header?: ReactNode footer?: ReactNode headerVariant?: CardHeaderVariant headerTitle?: ReactNode headerDescription?: ReactNode headerMeta?: ReactNode headerAction?: ReactNode headerActions?: ReactNode headerAvatar?: ReactNode variant?: CardVariant className?: string headerClassName?: string bodyClassName?: string footerClassName?: string } function classNames(...classes: Array) { return classes.filter(Boolean).join(' ') } export default function Card({ children, header, footer, headerVariant = 'custom', headerTitle, headerDescription, headerMeta, headerAction, headerActions, headerAvatar, variant = 'basic', className, headerClassName, bodyClassName, footerClassName, }: CardProps) { const isEdgeToEdgeMobile = variant === 'edge-to-edge-mobile' || variant === 'well-edge-to-edge-mobile' const isWell = variant === 'well' || variant === 'well-on-gray' || variant === 'well-edge-to-edge-mobile' const hasGrayHeader = variant === 'with-gray-header' || variant === 'with-gray-header-footer' const hasGrayFooter = variant === 'with-gray-footer' || variant === 'with-gray-header-footer' || variant === 'gray-footer' const hasDivider = variant === 'with-header' || variant === 'with-footer' || variant === 'with-header-footer' || variant === 'with-gray-header' || variant === 'with-gray-footer' || variant === 'with-gray-header-footer' const renderedHeader = renderHeader() const hasHeader = Boolean(renderedHeader) && (variant === 'with-header' || variant === 'with-header-footer' || variant === 'with-gray-header' || variant === 'with-gray-header-footer' || variant === 'gray-body') const hasFooter = Boolean(footer) && (variant === 'with-footer' || variant === 'with-header-footer' || variant === 'with-gray-footer' || variant === 'with-gray-header-footer' || variant === 'gray-footer') function renderHeader() { if (header) { return header } if (!headerTitle && !headerDescription && !headerAction && !headerActions && !headerAvatar && !headerMeta) { return null } const actions = headerActions ?? headerAction if (headerVariant === 'with-action') { return (

{headerTitle}

{actions && (
{actions}
)}
) } if (headerVariant === 'with-description-action') { return (

{headerTitle}

{headerDescription && (

{headerDescription}

)}
{actions && (
{actions}
)}
) } if (headerVariant === 'with-description') { return ( <>

{headerTitle}

{headerDescription && (

{headerDescription}

)} ) } if (headerVariant === 'with-avatar-actions') { return (
{headerAvatar && (
{headerAvatar}
)}

{headerTitle}

{headerDescription && (

{headerDescription}

)}
{actions && (
{actions}
)}
) } if (headerVariant === 'with-avatar-meta-actions') { return (
{headerAvatar && (
{headerAvatar}
)}

{headerTitle}

{headerMeta && (

{headerMeta}

)}
{actions && (
{actions}
)}
) } return (

{headerTitle}

) } return (
{hasHeader && (
{renderedHeader}
)}
{children}
{hasFooter && (
{footer}
)}
) }