import { forwardRef, type HTMLAttributes, type ReactNode } from 'react';
import { motion, type HTMLMotionProps } from 'framer-motion';
import { Slot } from '@radix-ui/react-slot';
import { cva, type VariantProps } from 'class-variance-authority';
import { cn } from '@/lib/utils';
import { usePlatform } from '@/platform';
import { buttonTap, buttonHover, springTransition } from '@/components/motion/transitions';
const cardVariants = cva(
[
'relative overflow-hidden',
'border border-dark-700/40 bg-dark-900/70',
'rounded-[var(--bento-radius)]',
'transition-[border-color,background-color,box-shadow,transform,opacity] duration-200',
// Glass border inset
'shadow-[inset_0_1px_0_0_rgba(255,255,255,0.05)]',
],
{
variants: {
size: {
sm: 'p-3',
md: 'p-4',
lg: 'p-5 sm:p-6',
xl: 'p-6 sm:p-8',
},
variant: {
default: '',
glass: 'backdrop-blur-linear bg-dark-900/50',
solid: 'bg-dark-900',
outline: 'bg-transparent',
},
interactive: {
true: [
'cursor-pointer',
'hover:border-dark-600/50 hover:bg-dark-800/60',
'active:scale-[0.98]',
],
false: '',
},
glow: {
true: 'hover:border-accent-500/30 hover:shadow-glow',
false: '',
},
},
defaultVariants: {
size: 'lg',
variant: 'default',
interactive: false,
glow: false,
},
},
);
export interface CardProps
extends Omit, 'children'>,
VariantProps {
children: ReactNode;
asChild?: boolean;
haptic?: boolean;
}
export const Card = forwardRef(
(
{
children,
className,
size,
variant,
interactive,
glow,
asChild = false,
haptic: enableHaptic = true,
onClick,
...props
},
ref,
) => {
const { haptic } = usePlatform();
const handleClick = (e: React.MouseEvent) => {
if (interactive && enableHaptic) {
haptic.impact('light');
}
onClick?.(e);
};
const classes = cn(cardVariants({ size, variant, interactive, glow }), className);
if (asChild) {
return (
{children}
);
}
if (interactive) {
return (
{children}
);
}
return (
{children}
);
},
);
Card.displayName = 'Card';
// Card Header
export type CardHeaderProps = HTMLAttributes;
export const CardHeader = forwardRef(
({ className, ...props }, ref) => (
),
);
CardHeader.displayName = 'CardHeader';
// Card Title
export type CardTitleProps = HTMLAttributes;
export const CardTitle = forwardRef(
({ className, ...props }, ref) => (
),
);
CardTitle.displayName = 'CardTitle';
// Card Description
export type CardDescriptionProps = HTMLAttributes;
export const CardDescription = forwardRef(
({ className, ...props }, ref) => (
),
);
CardDescription.displayName = 'CardDescription';
// Card Content
export type CardContentProps = HTMLAttributes;
export const CardContent = forwardRef(
({ className, ...props }, ref) => ,
);
CardContent.displayName = 'CardContent';
// Card Footer
export type CardFooterProps = HTMLAttributes;
export const CardFooter = forwardRef(
({ className, ...props }, ref) => (
),
);
CardFooter.displayName = 'CardFooter';