82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
import { forwardRef, type HTMLAttributes, type ReactNode } from 'react';
|
|
import { cn } from '../../lib/cn';
|
|
import {
|
|
Card as UiCard,
|
|
CardAction,
|
|
CardDescription,
|
|
CardFooter as UiCardFooter,
|
|
CardHeader as UiCardHeader,
|
|
CardTitle,
|
|
} from '../ui/card';
|
|
import { CountBadge } from '../Badge/Badge';
|
|
|
|
export interface CardProps extends HTMLAttributes<HTMLElement> {
|
|
/** Element to render as; `section` for dashboard panels, `article` for group cards. */
|
|
as?: 'div' | 'section' | 'article' | 'form' | 'aside';
|
|
/** Inner padding. `none` lets rows run edge to edge (settings, task list). */
|
|
padding?: 'none' | 'sm' | 'md';
|
|
/** Classes for the inner surface. */
|
|
innerClassName?: string;
|
|
}
|
|
|
|
/**
|
|
* The design's signature double frame: a dark 5px rim around a raised surface.
|
|
* Use it for dashboard panels, settings sections, auth forms and group cards.
|
|
*/
|
|
export const Card = forwardRef<HTMLElement, CardProps>(function Card(
|
|
{ as: Tag = 'section', padding = 'md', className, innerClassName, children, ...props },
|
|
ref,
|
|
) {
|
|
return (
|
|
<Tag
|
|
ref={ref as never}
|
|
className={cn('flex min-w-0 rounded-[18px] border border-line-frame bg-frame p-[5px]', className)}
|
|
{...props}
|
|
>
|
|
<UiCard
|
|
className={cn(
|
|
padding === 'md' && 'gap-3.5 px-[22px] py-5',
|
|
padding === 'sm' && 'gap-4 px-[18px] pt-[18px] pb-4',
|
|
innerClassName,
|
|
)}
|
|
>
|
|
{children}
|
|
</UiCard>
|
|
</Tag>
|
|
);
|
|
});
|
|
|
|
export interface CardHeaderProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
title: ReactNode;
|
|
/** id for the heading, so the card can be `aria-labelledby` it. */
|
|
titleId?: string;
|
|
count?: ReactNode;
|
|
/** Secondary line under the title. */
|
|
subtitle?: ReactNode;
|
|
/** Right side: filters, "more" button, add button. */
|
|
actions?: ReactNode;
|
|
/** Heading level. */
|
|
level?: 2 | 3;
|
|
}
|
|
|
|
export function CardHeader({ title, titleId, count, subtitle, actions, level = 2, ...props }: CardHeaderProps) {
|
|
const H = level === 2 ? 'h2' : 'h3';
|
|
return (
|
|
<UiCardHeader {...props}>
|
|
<div className="min-w-0">
|
|
<div className="flex items-center gap-2">
|
|
<CardTitle asChild>
|
|
<H id={titleId}>{title}</H>
|
|
</CardTitle>
|
|
{count !== undefined && <CountBadge>{count}</CountBadge>}
|
|
</div>
|
|
{subtitle && <CardDescription className="mt-1">{subtitle}</CardDescription>}
|
|
</div>
|
|
{actions && <CardAction>{actions}</CardAction>}
|
|
</UiCardHeader>
|
|
);
|
|
}
|
|
|
|
/** Footer row that pins its content to the bottom of a card. */
|
|
export const CardFooter = UiCardFooter;
|