import type { FC } from 'react'; import { useEffect, useRef, useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { List, PanelRight, PanelBottom, Settings2 } from 'lucide-react'; import { useQuickLinks, QUICK_LINKS_MODE_LABELS, type QuickLinksMode } from '../lib/quicklinks'; interface DockItem { label: string; href: string; icon: FC<{ size?: number | string; className?: string }>; } interface QuickLinksDockProps { /** Items visibles del menú (para resolver icono/label de cada href fijado) */ items: DockItem[]; } const MODE_ICONS: Record> = { menu: List, right: PanelRight, bottom: PanelBottom, }; /** Selector de presentación de los accesos rápidos (menú / derecha / abajo). */ export const QuickLinksModePicker: FC<{ direction?: 'up' | 'down'; align?: 'left' | 'right' }> = ({ direction = 'up', align = 'right', }) => { const quick = useQuickLinks(); const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { if (!open) return; const close = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); }; document.addEventListener('mousedown', close); return () => document.removeEventListener('mousedown', close); }, [open]); return (
{open && (

Mostrar accesos rápidos

{(Object.keys(MODE_ICONS) as QuickLinksMode[]).map((m) => { const ModeIcon = MODE_ICONS[m]; const selected = quick.mode === m; return ( ); })}
)}
); }; /** * Barra flotante de accesos rápidos (iconos), a la derecha o abajo según * la preferencia del usuario. En modo 'menu' no se muestra (la sección * va dentro del sidebar de cada layout). */ export const QuickLinksDock: FC = ({ items }) => { const location = useLocation(); const quick = useQuickLinks(); if (quick.mode === 'menu') return null; const dockItems = quick.links .map((href) => items.find((it) => it.href === href)) .filter((it): it is DockItem => it !== undefined); const isActive = (href: string) => href === '/' ? location.pathname === '/' : location.pathname === href || location.pathname.startsWith(`${href}/`); const isRight = quick.mode === 'right'; return ( ); }; export default QuickLinksDock;