89 lines
3.4 KiB
TypeScript
89 lines
3.4 KiB
TypeScript
import { Link } from '@inertiajs/react';
|
|
import type { ProcurementGroup } from '@/lib/procurement-navigation';
|
|
|
|
export function ProcurementMenuResults({
|
|
groups,
|
|
dashboard,
|
|
onNavigate,
|
|
onEscape,
|
|
}: {
|
|
groups: ProcurementGroup[];
|
|
dashboard: boolean;
|
|
onNavigate: () => void;
|
|
onEscape: () => void;
|
|
}) {
|
|
const count = groups.reduce(
|
|
(total, group) => total + group.entries.length,
|
|
dashboard ? 1 : 0,
|
|
);
|
|
const linkClass =
|
|
'block rounded-md px-3 py-2 text-sm hover:bg-accent focus-visible:bg-accent focus-visible:outline-2 focus-visible:outline-ring';
|
|
return (
|
|
<section
|
|
id="sgc-menu-results"
|
|
aria-label="Resultados da pesquisa do menu"
|
|
onKeyDown={(event) => {
|
|
if (event.key === 'Escape') {
|
|
event.preventDefault();
|
|
onEscape();
|
|
}
|
|
}}
|
|
className="absolute top-full left-0 z-50 mt-2 max-h-[min(65vh,32rem)] w-[min(36rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border bg-popover p-2 text-popover-foreground shadow-lg"
|
|
>
|
|
<p
|
|
role="status"
|
|
className="px-3 py-2 text-sm text-muted-foreground"
|
|
>
|
|
{count
|
|
? `${count} ${count === 1 ? 'opção disponível' : 'opções disponíveis'}.`
|
|
: 'Nenhuma opção encontrada. Tente outra palavra.'}
|
|
</p>
|
|
{dashboard && (
|
|
<Link
|
|
href="/dashboard"
|
|
className={linkClass}
|
|
onClick={onNavigate}
|
|
>
|
|
Painel inicial
|
|
</Link>
|
|
)}
|
|
{groups.map((group) => (
|
|
<div key={group.id}>
|
|
<h2 className="px-3 pt-3 pb-1 text-xs font-semibold text-muted-foreground">
|
|
{group.label}
|
|
</h2>
|
|
<ul>
|
|
{group.entries.map((entry) => (
|
|
<li key={entry.id}>
|
|
{entry.fullPage ? (
|
|
<a
|
|
href={entry.path}
|
|
className={linkClass}
|
|
onClick={onNavigate}
|
|
>
|
|
{entry.label}
|
|
<span className="block text-xs text-muted-foreground">
|
|
{entry.section ?? group.label}
|
|
</span>
|
|
</a>
|
|
) : (
|
|
<Link
|
|
href={entry.path}
|
|
className={linkClass}
|
|
onClick={onNavigate}
|
|
>
|
|
{entry.label}
|
|
<span className="block text-xs text-muted-foreground">
|
|
{entry.section ?? group.label}
|
|
</span>
|
|
</Link>
|
|
)}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
))}
|
|
</section>
|
|
);
|
|
}
|