Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import React from 'react';
import { cn } from '@/lib/core';
import { CardProps } from '@/types/ui';
/**
* Card Component
*
* A flexible container component for grouping related content.
* Supports multiple visual variants and interactive states.
*
* @example
* ```tsx
* <Card variant="elevated" hoverable>
* <h3>Card Title</h3>
* <p>Card content goes here</p>
* </Card>
*
* <Card variant="bordered" padding="lg">
* <CardHeader>
* <h2>Product Name</h2>
* </CardHeader>
* <CardBody>
* <p>Product description</p>
* </CardBody>
* </Card>
* ```
*/
export const Card = React.forwardRef<HTMLDivElement, CardProps>(
(
{
variant = 'default',
hoverable = false,
clickable = false,
padding = 'md',
rounded = 'lg',
className,
children,
...props
},
ref
) => {
const baseStyles = `transition-all duration-200`;
const variantStyles = {
default: 'bg-white dark:bg-gray-800',
bordered: 'bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700',
elevated: 'bg-white dark:bg-gray-800 shadow-md',
ghost: 'bg-transparent',
'shadow-1': 'bg-white dark:bg-gray-800 shadow-1',
flat: 'bg-gray-50 dark:bg-gray-700'};
const paddingStyles = {
none: '',
sm: 'p-3',
md: 'p-4',
lg: 'p-6'};
const roundedStyles = {
none: 'rounded-none',
sm: 'rounded',
md: 'rounded-md',
lg: 'rounded-lg'};
const interactiveStyles = hoverable
? 'hover:shadow-lg hover:-translate-y-0.5'
: '';
const cursorStyle = clickable ? 'cursor-pointer' : '';
return (
<div
ref={ref}
className={cn(
baseStyles,
roundedStyles[rounded],
variantStyles[variant],
paddingStyles[padding],
interactiveStyles,
cursorStyle,
className
)}
{...props}
>
{children}
</div>
);
}
);
Card.displayName = 'Card';
/**
* CardHeader Component
*
* Optional header section for Card with consistent styling.
*/
export const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, children, ...props }, ref) => (
<div
ref={ref}
className={cn('mb-4 pb-4 border-b border-gray-200 dark:border-gray-700', className)}
{...props}
>
{children}
</div>
));
CardHeader.displayName = 'CardHeader';
/**
* CardBody Component
*
* Main content area for Card.
*/
export const CardBody = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, children, ...props }, ref) => (
<div ref={ref} className={cn('', className)} {...props}>
{children}
</div>
));
CardBody.displayName = 'CardBody';
/**
* CardFooter Component
*
* Optional footer section for Card with consistent styling.
*/
export const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, children, ...props }, ref) => (
<div
ref={ref}
className={cn('mt-4 pt-4 border-t border-gray-200 dark:border-gray-700', className)}
{...props}
>
{children}
</div>
));
CardFooter.displayName = 'CardFooter';
// ============================================================================
// COMPOUND COMPONENT PATTERN
// ============================================================================
/**
* Compound Card Component
*
* Alternative usage with compound component pattern:
* @example
* ```tsx
* <CompoundCard>
* <CompoundCard.Header>Title</CompoundCard.Header>
* <CompoundCard.Body>Content</CompoundCard.Body>
* <CompoundCard.Footer>Actions</CompoundCard.Footer>
* </CompoundCard>
* ```
*/
export const CompoundCard = Object.assign(Card, {
Header: CardHeader,
Body: CardBody,
Footer: CardFooter,
});
export default Card;
|