Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

collapsible-section-header.tsx

49 lines1.7 KB

1import type { ComponentProps, ReactNode } from "react";
2import { ChevronDownIcon } from "lucide-react";
3import { cn } from "../../lib/utils";
4​
5const tones = {
6 muted: { label: "text-sidebar-muted-foreground/60", line: "bg-sidebar-border/60" },
7 info: { label: "text-blue-600 dark:text-blue-400", line: "bg-blue-500/20 dark:bg-blue-400/15" },
8 emphasized: { label: "text-sidebar-foreground/80", line: "bg-sidebar-foreground/25" },
9 accent: { label: "text-primary", line: "bg-primary/50" },
10} as const;
11​
12/** Callers own the section state and content; this owns all header geometry. */
13export function CollapsibleSectionHeader({
14 children,
15 expanded,
16 tone = "muted",
17 accessory,
18 ...buttonProps
19}: Omit<ComponentProps<"button">, "className" | "style" | "aria-expanded"> & {
20 expanded: boolean;
21 tone?: keyof typeof tones;
22 accessory?: ReactNode;
23}) {
24 return (
25 <button
26 {...buttonProps}
27 type="button"
28 aria-expanded={expanded}
29 className={cn(
30 "flex h-8 w-full cursor-pointer items-center gap-2 rounded-md px-2 text-left text-xs font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
31 tones[tone].label,
32 )}
33 >
34 <span className="shrink-0">{children}</span>
35 <span aria-hidden className={cn("h-px min-w-2 flex-1", tones[tone].line)} />
36 {accessory}
37 <ChevronDownIcon
38 aria-hidden
39 className={cn("size-3 shrink-0 transition-transform", !expanded && "rotate-180")}
40 />
41 </button>
42 );
44​
45export function SectionHeaderStatus({ children }: { children: ReactNode }) {
46 return (
47 <span className="shrink-0 text-3xs leading-none text-destructive-foreground">{children}</span>
48 );