import { useState, useRef, useEffect } from 'react'; import { useOrg } from '../../context/OrgContext'; import type { OrgId } from '../../context/OrgContext'; import { ChevronDown } from 'lucide-react'; export function TopBar() { const { currentOrg, setOrg } = useOrg(); const [isOpen, setIsOpen] = useState(false); const menuRef = useRef(null); const triggerRef = useRef(null); const orgs: { id: OrgId; name: string }[] = [ { id: 'szl', name: 'a11oy' }, { id: 'acme', name: 'Acme Industries' }, { id: 'northwind', name: 'Northwind Labs' } ]; useEffect(() => { function handleOutsideClick(e: MouseEvent) { if (menuRef.current && !menuRef.current.contains(e.target as Node)) { setIsOpen(false); } } if (isOpen) { document.addEventListener('mousedown', handleOutsideClick); } return () => document.removeEventListener('mousedown', handleOutsideClick); }, [isOpen]); function handleKeyDown(e: React.KeyboardEvent) { if (e.key === 'Escape') { setIsOpen(false); triggerRef.current?.focus(); } } function handleOrgSelect(id: OrgId) { setOrg(id); setIsOpen(false); triggerRef.current?.focus(); } return (
A11oy
{isOpen && (
    {orgs.map(org => (
  • ))}
)}
); }