Files
qiming/qiming-xagi-frontend-templates/packages/react-vite/src/components/ui/card.tsx
2026-06-01 13:43:09 +08:00

103 lines
2.6 KiB
TypeScript

import * as React from 'react';
import { cn } from '@/lib/utils';
// Root card container props
export interface CardProps extends React.HTMLAttributes<HTMLDivElement> {}
// Header region props
export interface CardHeaderProps extends React.HTMLAttributes<HTMLDivElement> {}
// Main body props
export interface CardContentProps extends React.HTMLAttributes<HTMLDivElement> {}
// Footer region props
export interface CardFooterProps extends React.HTMLAttributes<HTMLDivElement> {}
// Title typography props
export interface CardTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {}
// Subtitle / description props
export interface CardDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {}
/**
* Card — groups related content and actions.
*/
const Card = React.forwardRef<HTMLDivElement, CardProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
'rounded-lg border border-gray-200 bg-white text-gray-950 shadow-sm',
className
)}
{...props}
/>
)
);
Card.displayName = 'Card';
/** Top section inside a card (title + description). */
const CardHeader = React.forwardRef<HTMLDivElement, CardHeaderProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn('flex flex-col space-y-1.5 p-6', className)}
{...props}
/>
)
);
CardHeader.displayName = 'CardHeader';
/** Card heading. */
const CardTitle = React.forwardRef<HTMLParagraphElement, CardTitleProps>(
({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn(
'text-2xl font-semibold leading-none tracking-tight',
className
)}
{...props}
/>
)
);
CardTitle.displayName = 'CardTitle';
/** Muted supporting text below the title. */
const CardDescription = React.forwardRef<
HTMLParagraphElement,
CardDescriptionProps
>(({ className, ...props }, ref) => (
<p ref={ref} className={cn('text-sm text-gray-500', className)} {...props} />
));
CardDescription.displayName = 'CardDescription';
/** Primary content area. */
const CardContent = React.forwardRef<HTMLDivElement, CardContentProps>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('p-6 pt-0', className)} {...props} />
)
);
CardContent.displayName = 'CardContent';
/** Footer actions row. */
const CardFooter = React.forwardRef<HTMLDivElement, CardFooterProps>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn('flex items-center p-6 pt-0', className)}
{...props}
/>
)
);
CardFooter.displayName = 'CardFooter';
export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardDescription,
CardContent,
};