"use client"; import { useRef, useState, type ReactElement, type ReactNode } from "react"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; export type SettingsSection = { id: string; label: string; icon: ReactNode; /** The current choice, shown under the label so the menu reads without opening each section. */ value?: string; /** How many things are on or changed here. */ count?: number; /** The section lays out its own padding. */ flush?: boolean; content: ReactNode; }; /** The composer's one settings menu: sections on the left, the open section on the right, tabs across the top on phones. */ export function ComposerSettings({ trigger, sections, label, footer }: { trigger: ReactElement; sections: readonly SettingsSection[]; label: string; footer?: ReactNode }) { const [selected, setSelected] = useState(sections[0]?.id); const tabs = useRef(new Map()); // Sections come and go with the workflow: fall back to the first when the open one leaves. const active = sections.find((section) => section.id === selected) ?? sections[0]; const move = (from: number, step: number) => { const next = sections[(from + step + sections.length) % sections.length]; setSelected(next.id); tabs.current.get(next.id)?.focus(); }; return ( {trigger}
{sections.map((section, index) => { const isActive = section.id === active?.id; return ( ); })}
{footer &&
{footer}
}
{active?.content}
); }