import React, { forwardRef, ReactNode, HTMLAttributes } from 'react'; import { cn } from '../../lib/utils'; // Card variants type CardVariant = 'elevated' | 'flat' | 'bordered'; // Card props interface interface CardProps extends HTMLAttributes { variant?: CardVariant; children?: ReactNode; padding?: 'none' | 'sm' | 'md' | 'lg' | 'xl'; hoverable?: boolean; shadow?: boolean; } // Card header props interface CardHeaderProps extends Omit, 'title'> { title?: ReactNode; subtitle?: ReactNode; icon?: ReactNode; action?: ReactNode; } // Card body props interface CardBodyProps extends HTMLAttributes { children?: ReactNode; } // Card footer props interface CardFooterProps extends HTMLAttributes { children?: ReactNode; align?: 'left' | 'center' | 'right'; } // Card image props interface CardImageProps extends HTMLAttributes { src: string; alt?: string; height?: 'sm' | 'md' | 'lg' | 'xl'; position?: 'top' | 'background'; } // Helper function to get variant styles const getVariantStyles = (variant: CardVariant) => { switch (variant) { case 'elevated': return 'bg-white shadow-lg shadow-gray-200/50 border border-gray-100'; case 'flat': return 'bg-white shadow-sm border border-gray-100'; case 'bordered': return 'bg-white border-2 border-gray-200'; default: return 'bg-white shadow-md border border-gray-100'; } }; // Helper function to get padding styles const getPaddingStyles = (padding: CardProps['padding']) => { switch (padding) { case 'none': return ''; case 'sm': return 'p-3'; case 'md': return 'p-4'; case 'lg': return 'p-6'; case 'xl': return 'p-8'; default: return 'p-4'; } }; // Helper function to get image height const getImageHeight = (height: CardImageProps['height']) => { switch (height) { case 'sm': return 'h-32'; case 'md': return 'h-48'; case 'lg': return 'h-64'; case 'xl': return 'h-80'; default: return 'h-48'; } }; // Main Card Component export const Card = forwardRef( ( { variant = 'elevated', padding = 'md', hoverable = false, shadow = true, className = '', children, ...props }, ref ) => { return (
{children}
); } ); Card.displayName = 'Card'; // Card Header Component export const CardHeader = forwardRef( ({ title, subtitle, icon, action, className = '', children, ...props }, ref) => { return (
{icon &&
{icon}
}
{title && (
{title}
)} {subtitle && (
{subtitle}
)} {children}
{action &&
{action}
}
); } ); CardHeader.displayName = 'CardHeader'; // Card Body Component export const CardBody = forwardRef( ({ className = '', children, ...props }, ref) => { return (
{children}
); } ); CardBody.displayName = 'CardBody'; // Card Footer Component export const CardFooter = forwardRef( ({ align = 'left', className = '', children, ...props }, ref) => { const alignmentClasses = { left: 'justify-start', center: 'justify-center', right: 'justify-end', }; return (
{children}
); } ); CardFooter.displayName = 'CardFooter'; // Card Image Component export const CardImage = forwardRef( ({ src, alt, height = 'md', position = 'top', className = '', ...props }, ref) => { const heightClasses = getImageHeight(height); if (position === 'background') { return (
{/* eslint-disable-next-line @next/next/no-img-element */} {alt
); } return (
{/* eslint-disable-next-line @next/next/no-img-element */} {alt
); } ); CardImage.displayName = 'CardImage'; // Export types for external use export type { CardProps, CardHeaderProps, CardBodyProps, CardFooterProps, CardImageProps, CardVariant };