import { cn } from "@suphark/ui/lib/utils"; import type { ComponentProps, ReactNode } from "react"; import { CollapsibleListSection, type CollapsibleProps } from "./collapsible-section"; export type ListSectionTone = "default" | "danger" | "success" | "accent" | "muted"; const TONE: Record = { default: "text-foreground/90", danger: "text-destructive", success: "text-success", accent: "text-primary", muted: "text-muted-foreground", }; /** หัวกลุ่มของรายการ: ชื่อ (สีตาม tone) + จำนวน + ปุ่มขวา + เส้นบางใต้หัว — ใช้เดี่ยว ๆ หรือผ่าน `ListSection` */ export function ListSectionHeader({ title, count, action, tone = "default", as: Heading = "h2", className, }: { title: ReactNode; count?: number; action?: ReactNode; tone?: ListSectionTone; as?: "h2" | "h3" | "h4" | "p"; className?: string; }) { return (
{title} {typeof count === "number" && ( {count} )}
{action}
); } /** * กลุ่มของรายการแบบ "ไม่มีกล่อง" (รูปแบบ List): หัวกลุ่ม + เส้นบาง + แถวคั่นด้วยเส้น — ยกจาก `SectionPanel plain` ของ pi-done * แถวข้างในคั่นเส้นให้เอง (`divide-y`) · อยากได้กล่องใช้ `SectionCard` * * ทำทั้งหมด}> * {tasks.map((t) => )} * */ export function ListSection({ title, count, action, tone, headingAs, children, className, collapsible = false, initialOpen, open, onOpenChange, storageKey, ...props }: Omit, "title"> & CollapsibleProps & { title: ReactNode; count?: number; action?: ReactNode; tone?: ListSectionTone; headingAs?: "h2" | "h3" | "h4" | "p"; /** หัวกลุ่มเป็นปุ่มหุบ/ขยาย (`initialOpen`, `open`/`onOpenChange`, `storageKey`) */ collapsible?: boolean; }) { if (collapsible) { return ( {children} ); } return (
{children}
); }