Card
A flexible card component with header, content, and footer sections
registry/preskok/ui/preskok-ui/card.tsx
"use client"
import { twMerge } from "cn"
const Card = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => {
return (
<div
data-slot="card"
className={twMerge(
"group/card text-foreground **:data-[slot=table-header]:bg-muted/50 flex flex-col gap-(--gutter) rounded-lg border py-(--gutter) shadow-xs [--gutter:--spacing(6)] has-[table]:overflow-hidden has-[table]:not-has-data-[slot=card-footer]:pb-0 has-[table]:**:data-[slot=card-footer]:border-t **:[table]:overflow-hidden",
className
)}
{...props}
/>
)
}
interface HeaderProps extends React.HTMLAttributes<HTMLDivElement> {
title?: string
description?: string
}
const CardHeader = ({
className,
title,
description,
children,
...props
}: HeaderProps) => (
<div
data-slot="card-header"
className={twMerge(
"grid auto-rows-min grid-rows-[auto_auto] items-start gap-1 px-(--gutter) has-data-[slot=card-action]:grid-cols-[1fr_auto]",
className
)}
{...props}
>
{title && <CardTitle>{title}</CardTitle>}
{description && <CardDescription>{description}</CardDescription>}
{!title && typeof children === "string" ? (
<CardTitle>{children}</CardTitle>
) : (
children
)}
</div>
)
const CardTitle = ({ className, ...props }: React.ComponentProps<"div">) => {
return (
<div
data-slot="card-title"
className={twMerge("text-base/6 font-semibold text-balance", className)}
{...props}
/>
)
}
const CardDescription = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => {
return (
<div
{...props}
data-slot="card-description"
className={twMerge(
"text-muted-foreground row-start-2 text-sm/6 text-pretty",
className
)}
{...props}
/>
)
}
const CardAction = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => {
return (
<div
data-slot="card-action"
className={twMerge(
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
className
)}
{...props}
/>
)
}
const CardContent = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => {
return (
<div
data-slot="card-content"
className={twMerge("px-(--gutter) has-[table]:border-t", className)}
{...props}
/>
)
}
const CardFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => {
return (
<div
data-slot="card-footer"
className={twMerge(
"flex items-center px-(--gutter) group-has-[table]/card:pt-(--gutter) [.border-t]:pt-6",
className
)}
{...props}
/>
)
}
export {
Card,
CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
}
- Where it goes
- navbarfooter
DependenciesBundle weight · light
cn@^0.2.4