components/linyi/card.tsx
@base-ui/reactclass-variance-authority
"use client"; import * as React from "react";import { useRender } from "@base-ui/react/use-render";import { mergeProps } from "@base-ui/react/merge-props";import { cva, type VariantProps } from "class-variance-authority";import { cn } from "@/lib/cn"; export const cardVariants = cva( "relative flex flex-col rounded-panel border text-fg transition-[border-color,background-color,box-shadow,transform] duration-180 ease-[cubic-bezier(0.16,1,0.3,1)] motion-reduce:transition-none", { variants: { variant: { surface: "bg-surface border-line shadow-panel", well: "bg-well border-line-well", interactive: [ "bg-surface border-line shadow-panel cursor-pointer outline-none", "hover:border-line-strong hover:bg-surface-hover", "active:scale-[0.99]", "focus-visible:ring-2 focus-visible:ring-accent/35 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas", ].join(" "), }, padding: { none: "p-0", sm: "p-4", md: "p-5", lg: "p-6", }, }, defaultVariants: { variant: "surface", padding: "md", }, }); export interface CardProps extends useRender.ComponentProps<"div">, VariantProps<typeof cardVariants> {} export function Card({ className, variant = "surface", padding = "md", render, ref, ...props}: CardProps) { const defaultProps: useRender.ElementProps<"div"> = { className: cn(cardVariants({ variant, padding }), className), }; return useRender({ defaultTagName: "div", render, ref, props: mergeProps<"div">(defaultProps, props), });} export function CardHeader({ className, ...props}: React.ComponentPropsWithRef<"div">) { return ( <div className={cn("flex items-start justify-between gap-3", className)} {...props} /> );} export function CardTitle({ className, ...props}: React.ComponentPropsWithRef<"h3">) { return ( <h3 className={cn( "text-sm font-semibold tracking-tight text-fg leading-snug", className )} {...props} /> );} export function CardDescription({ className, ...props}: React.ComponentPropsWithRef<"p">) { return ( <p className={cn("mt-1 text-xs leading-relaxed text-fg-secondary", className)} {...props} /> );} export function CardAction({ className, ...props}: React.ComponentPropsWithRef<"div">) { return ( <div className={cn("shrink-0 flex items-center gap-1.5", className)} {...props} /> );} export function CardContent({ className, ...props}: React.ComponentPropsWithRef<"div">) { return <div className={cn("mt-4 flex-1", className)} {...props} />;} export function CardFooter({ className, ...props}: React.ComponentPropsWithRef<"div">) { return ( <div className={cn( "mt-4 flex items-center justify-between gap-3 border-t border-line pt-3.5", className )} {...props} /> );}