Group the main menu into role-aware popover groups

Replace the flat link row with disclosure groups (Työt, Oma kirjaus,
Asiakkaat ja myynti, Hallinto, Ylläpito) built by App\View\MainMenu from
Gate abilities, and add menu links for new job, quick sales list and
workflow templates.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-24 19:14:11 +02:00
co-authored by Claude Sonnet 5.5
parent 18598cc08e
commit 48030e7689
10 changed files with 283 additions and 64 deletions
+4
View File
@@ -27,3 +27,7 @@
--color-primary-700: #3730a3;
--color-primary-800: #312e81;
}
[x-cloak] {
display: none !important;
}
@@ -0,0 +1,59 @@
@props(['group'])
{{--
A main menu group: a disclosure button that opens a panel of links (WAI-ARIA disclosure navigation, not role="menu").
Escape and a click outside close it, and so does moving focus out of the group. The current section is
marked with an underline and hidden text, not colour alone, and the current link has aria-current="page".
--}}
<div
class="relative"
x-data="{ open: false }"
x-on:nav-group-opened.window="if ($event.detail !== '{{ $group['key'] }}') open = false"
x-on:keydown.escape="if (open) { open = false; $refs.trigger.focus() }"
x-on:click.outside="open = false"
x-on:focusout="if (open && ! $el.contains($event.relatedTarget)) open = false"
>
<button
type="button"
x-ref="trigger"
x-on:click="open = ! open; if (open) $dispatch('nav-group-opened', '{{ $group['key'] }}')"
x-bind:aria-expanded="open.toString()"
aria-expanded="false"
aria-controls="nav-group-{{ $group['key'] }}"
@class([
'flex items-center gap-1 rounded-md px-3 py-2 text-sm font-medium focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700',
'text-zinc-900 underline decoration-2 underline-offset-8 dark:text-white' => $group['current'],
'text-zinc-600 hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-300 dark:hover:bg-zinc-700 dark:hover:text-white' => ! $group['current'],
])
>
{{ $group['label'] }}
@if ($group['current'])
<span class="sr-only">{{ __('layout.current_section') }}</span>
@endif
<x-icon name="chevron-down" class="size-4 transition-transform" x-bind:class="{ 'rotate-180': open }" aria-hidden="true" />
</button>
<ul
id="nav-group-{{ $group['key'] }}"
x-show="open"
x-cloak
class="z-40 mt-1 min-w-56 rounded-md border border-zinc-200 bg-white p-1 shadow-lg sm:absolute sm:start-0 dark:border-zinc-600 dark:bg-zinc-800"
>
@foreach ($group['items'] as $item)
<li>
<a
href="{{ route($item['route']) }}"
wire:navigate
@if ($item['current']) aria-current="page" @endif
@class([
'block rounded-md px-3 py-2 text-sm font-medium focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700',
'bg-zinc-100 text-zinc-900 underline decoration-2 underline-offset-4 dark:bg-zinc-700 dark:text-white' => $item['current'],
'text-zinc-700 hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-200 dark:hover:bg-zinc-700 dark:hover:text-white' => ! $item['current'],
])
>
{{ $item['label'] }}
</a>
</li>
@endforeach
</ul>
</div>
+3 -47
View File
@@ -55,53 +55,9 @@
</a>
<nav aria-label="{{ __('layout.main_menu') }}" class="flex flex-1 flex-wrap items-center gap-1">
@include('partials.nav-item', ['route' => 'jobs.index', 'pattern' => ['jobs.index', 'jobs.show', 'jobs.create', 'jobs.edit'], 'label' => __('layout.jobs')])
@include('partials.nav-item', ['route' => 'jobs.board', 'pattern' => 'jobs.board', 'label' => __('layout.board')])
@include('partials.nav-item', ['route' => 'jobs.calendar', 'pattern' => 'jobs.calendar', 'label' => __('layout.calendar')])
@include('partials.nav-item', ['route' => 'time.week', 'pattern' => ['time.week', 'time.task'], 'label' => __('layout.time')])
@include('partials.nav-item', ['route' => 'expenses.mine', 'pattern' => 'expenses.*', 'label' => __('layout.expenses')])
@can('sales.use')
@include('partials.nav-item', ['route' => 'sales.sell', 'pattern' => 'sales.*', 'label' => __('layout.quick_sale')])
@endcan
@can('jobs.manage')
@include('partials.nav-item', ['route' => 'jobs.quick', 'pattern' => 'jobs.quick', 'label' => __('layout.quick_intake')])
@endcan
@can('time.approve-others')
@include('partials.nav-item', ['route' => 'time.approvals', 'pattern' => 'time.approvals', 'label' => __('layout.approvals')])
@endcan
@can('billing.manage')
@include('partials.nav-item', ['route' => 'billing.index', 'pattern' => 'billing.*', 'label' => __('layout.billing')])
@endcan
@can('customers.use')
@include('partials.nav-item', ['route' => 'customers.index', 'pattern' => 'customers.*', 'label' => __('layout.customers')])
@endcan
@can('catalog.manage')
@include('partials.nav-item', ['route' => 'catalog.index', 'pattern' => ['catalog.index', 'catalog.service-units.*', 'catalog.services.*', 'catalog.work-types.*'], 'label' => __('layout.catalog')])
@include('partials.nav-item', ['route' => 'catalog.prices', 'pattern' => ['catalog.prices', 'catalog.products.*', 'catalog.vat-rates.*', 'catalog.price-list'], 'label' => __('layout.prices')])
@elsecan('catalog.view-prices')
@include('partials.nav-item', ['route' => 'catalog.price-list', 'pattern' => 'catalog.price-list', 'label' => __('layout.prices')])
@endcan
@can('users.manage')
@include('partials.nav-item', ['route' => 'users.index', 'pattern' => 'users.*', 'label' => __('layout.users')])
@endcan
@can('settings.manage')
@include('partials.nav-item', ['route' => 'settings.company', 'pattern' => 'settings.company', 'label' => __('layout.company')])
@include('partials.nav-item', ['route' => 'settings.holidays', 'pattern' => 'settings.holidays', 'label' => __('layout.holidays')])
@endcan
@foreach (app(\App\View\MainMenu::class)->groups(auth()->user()) as $group)
<x-nav-group :group="$group" />
@endforeach
</nav>
<div class="flex flex-wrap items-center gap-3">
@@ -1,15 +0,0 @@
{{-- Main menu link. The current page is marked with aria-current and an underline, not colour alone. --}}
@php($current = request()->routeIs(...(array) $pattern))
<a
href="{{ route($route) }}"
wire:navigate
@if ($current) aria-current="page" @endif
@class([
'rounded-md px-3 py-2 text-sm font-medium focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700',
'text-zinc-900 underline decoration-2 underline-offset-8 dark:text-white' => $current,
'text-zinc-600 hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-300 dark:hover:bg-zinc-700 dark:hover:text-white' => ! $current,
])
>
{{ $label }}
</a>