import React, { useEffect, useRef, useState } from 'react'; import { Check, ChevronDown } from 'lucide-react'; import { CountBadge } from './CountBadge'; export interface ListSwitcherItem { id: string; title: string; icon?: string; count?: number; } interface ListSwitcherProps { // Shown on the button: the list that is open now label: string; items: ListSwitcherItem[]; activeId: string; onSelect: (id: string) => void; } // Title of the open list in the phone header (Doku/ui-patterns.md): a tap opens all lists to switch to export const ListSwitcher: React.FC = ({ label, items, activeId, onSelect }) => { const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { if (!open) return; const close = (e: Event) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); }; const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') setOpen(false); }; document.addEventListener('pointerdown', close); document.addEventListener('keydown', onKey); return () => { document.removeEventListener('pointerdown', close); document.removeEventListener('keydown', onKey); }; }, [open]); return (
{open && (
{items.map((item) => { const active = item.id === activeId; return ( ); })}
)}
); };