import React, { HTMLAttributes } from "react"; import { Colors } from "../colors"; import { Ribbon, RibbonProps } from '../Ribbon' import { BoxSkeleton, BoxSkeletonProps } from '../Skeleton' export interface CardProps extends HTMLAttributes{ header?: string; subtitle?: string; padding?: 'default' | 'sm' | 'md' | 'lg'; borderless?: boolean; hoverable?: boolean; image?: string | BoxSkeletonProps; statusColor?: Colors; statusPosition?: 'top' | 'start' | 'bottom'; stacked?: boolean; hoverEffect?: 'pop' | 'rotate'; rotate?: 'left' | 'right'; lightHeader?: boolean; active?: boolean; inactive?: boolean; ribbon?: RibbonProps; stamp?: React.ReactNode; color?: Colors; light?: boolean; progress?: number; imageAlign?: 'left' | 'right' | 'top' | 'bottom'; footer?: React.ReactNode; transparentFooter?: boolean; imageClasses?: string; actions?: React.ReactNode[]; } const Card = ({ className = '', padding = 'default', header, borderless, hoverable, children, image, subtitle, statusColor, statusPosition, ribbon, hoverEffect, stacked, rotate, color, light, active, inactive, lightHeader, stamp, imageAlign = 'top', progress, transparentFooter, footer, actions, imageClasses = '', ...props }: CardProps) => { const classes = [ 'card', imageAlign && ['left', 'right'].includes(imageAlign) && 'd-flex flex-column', stacked && 'card-stacked', padding && padding !== 'default' && `card-${padding}`, borderless && 'card-borderless', hoverable && 'card-link', rotate && ['left', 'right'].includes(rotate) && `card-rotate-${rotate}`, hoverEffect && ['pop', 'rotate'].includes(hoverEffect) && `card-link-${hoverEffect}`, active && 'card-active', inactive && 'card-inactive', color && `bg-${color}${light ? '-lt' : ''}`, className ].filter(Boolean).join(' '); const headerClasses = [ 'card-header', lightHeader && 'card-header-light' ].filter(Boolean).join(' '); if (['left', 'right'].includes(imageAlign)) { return (
{(statusColor || statusPosition) &&
}
{typeof image === 'object' && } {typeof image === 'string' && }
{ribbon && } {stamp &&
{stamp}
} {(header || (actions && actions?.length > 0)) &&

{header}

{subtitle && {subtitle}} {actions &&
{actions?.map(action => action)}
}
}

{children}

{(progress && progress > 0 && progress < 100) &&
}
{footer &&
}
) } else { return (
{(statusColor || statusPosition) &&
} {typeof image === 'object' && imageAlign === 'top' && } {typeof image === 'string' && imageAlign === 'top' && } {ribbon && } {stamp &&
{stamp}
} {header &&

{header}

{subtitle && {subtitle}}
}
{children} {(progress && progress > 0 && progress < 100) &&
}
{image && imageAlign === 'bottom' && typeof image === 'string' && } {footer &&
}
) } } export default Card;