-
Notifications
You must be signed in to change notification settings - Fork 0
feat/brave nav #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/brave nav #35
Changes from all commits
8ce8943
bbcdd17
d05dc11
9606430
ef29de0
7a091af
4ad90c9
aba11da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,96 @@ | |
| <x-brave-read-speaker /> | ||
| ``` | ||
|
|
||
| ### Nav | ||
|
|
||
| Navigation component with optional dropdowns. Provides the right ARIA attributes and keyboard navigation for accessibility. | ||
|
|
||
| Dropdown visibility is controlled via `aria-expanded`. Use it in combination with the `group` class on the parent item and `group-has-aria-expanded` variants to show/hide the dropdown. | ||
|
|
||
| **Dropdown modes** | ||
|
|
||
| - `click` (default) — opens on click | ||
| - `hover` - opens on hover, closes when the mouse leaves the item | ||
|
|
||
| For accessibility, the `<x-brave::nav>` component requires an `aria-label`. | ||
|
|
||
| Example usage with Navi: | ||
|
|
||
| ```blade | ||
| @php($menu = \Log1x\Navi\Navi::make()->build('primary_navigation')) | ||
|
|
||
| @if ($menu->isNotEmpty()) | ||
| <x-brave::nav aria-label="{{ __('Primaire navigatie', 'sage') }}"> | ||
|
Check failure on line 135 in README.md
|
||
| <x-brave::nav.list> | ||
|
Check failure on line 136 in README.md
|
||
| @foreach ($menu->all() as $item) | ||
|
Check failure on line 137 in README.md
|
||
| <x-brave::nav.item class="group"> | ||
|
Check failure on line 138 in README.md
|
||
| <x-brave::nav.link :item="$item" class="text-blue-500" activeClass="text-red-500"> | ||
|
Check failure on line 139 in README.md
|
||
| {!! $item->label !!} | ||
|
Check failure on line 140 in README.md
|
||
| @if ($item->children) | ||
|
Check failure on line 141 in README.md
|
||
| <i class="fa-light fa-chevron-down"></i> | ||
|
Check failure on line 142 in README.md
|
||
| @endif | ||
|
Check failure on line 143 in README.md
|
||
| </x-brave::nav.link> | ||
|
Check failure on line 144 in README.md
|
||
|
|
||
| @if ($item->children) | ||
| <x-brave::nav.dropdown mode="hover" @class([ | ||
| 'invisible absolute bg-white', | ||
| 'group-has-aria-expanded:visible', | ||
| ])> | ||
| @foreach ($item->children as $child) | ||
| <x-brave::nav.item> | ||
| <x-brave::nav.link :item="$child" class="text-blue-500" activeClass="text-red-500"> | ||
| {!! $child->label !!} | ||
| </x-brave::nav.link> | ||
| </x-brave::nav.item> | ||
| @endforeach | ||
| </x-brave::nav.dropdown> | ||
| @endif | ||
| </x-brave::nav.item> | ||
| @endforeach | ||
| </x-brave::nav.list> | ||
| </x-brave::nav> | ||
| @endif | ||
|
|
||
| ``` | ||
|
|
||
| Usage without Navi: | ||
|
|
||
| ```blade | ||
| <x-brave::nav aria-label="Main navigation"> | ||
| <x-brave::nav.list> | ||
| <x-brave::nav.item> | ||
| <x-brave::nav.link href="/contact" :isActive="true" activeClass="text-red-500"> | ||
| First item | ||
| </x-brave::nav.link> | ||
| </x-brave::nav.item> | ||
|
|
||
| <x-brave::nav.item class="group"> | ||
| <x-brave::nav.link href="#" :hasChildren="true"> | ||
| Dropdown | ||
| </x-brave::nav.link> | ||
|
|
||
| {{-- Change mode via mode="hover" --}} | ||
| <x-brave::nav.dropdown mode="hover" @class([ | ||
| 'invisible absolute bg-white', | ||
| 'group-has-aria-expanded:visible', | ||
| ])> | ||
| <x-brave::nav.item> | ||
| <x-brave::nav.link href="/contact"> | ||
| Dropdown item 1 | ||
| </x-brave::nav.link> | ||
| </x-brave::nav.item> | ||
|
|
||
| <x-brave::nav.item> | ||
| <x-brave::nav.link href="/"> | ||
| Dropdown item 2 | ||
| </x-brave::nav.link> | ||
| </x-brave::nav.item> | ||
| </x-brave::nav.dropdown> | ||
| </x-brave::nav.item> | ||
| </x-brave::nav.list> | ||
| </x-brave::nav> | ||
| ``` | ||
|
|
||
| ## About us | ||
|
|
||
| [](https://www.yard.nl/werken-bij/) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| @props([ | ||
| 'mode' => 'click', | ||
| ]) | ||
|
|
||
| <ul | ||
| {!! $attributes->merge([ | ||
| 'class' => 'brave-nav-dropdown brave-nav-dropdown-on-' . $mode, | ||
| 'data-mode' => $mode, | ||
| ]) !!}> | ||
| {{ $slot }} | ||
| </ul> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| @props(['ariaLabel']) | ||
|
|
||
| <nav | ||
| {{ $attributes->merge([ | ||
| 'aria-label' => $ariaLabel, | ||
| 'class' => 'brave-nav', | ||
| ]) }}> | ||
| {{ $slot }} | ||
| </nav> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <li | ||
| {!! $attributes->merge([ | ||
| 'class' => 'brave-nav-item', | ||
| ]) !!}> | ||
| {{ $slot }} | ||
| </li> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| @props([ | ||
| 'item' => null, | ||
| 'href' => null, | ||
| 'isActive' => false, | ||
| 'activeClass' => null, | ||
| 'hasChildren' => null, | ||
| ]) | ||
|
|
||
| @php | ||
| $hasChildren = $hasChildren ?? !empty($item?->children); | ||
|
|
||
| $href = $item?->url ?? $href; | ||
| $label = !$slot->isEmpty() ? $slot : ($item?->label ?? ''); | ||
|
|
||
| $isActive = $isActive | ||
| || ($item?->active ?? false) | ||
| || ($item?->activeParent ?? false); | ||
|
|
||
| $baseAttributes = $attributes | ||
| ->class([ | ||
| 'brave-nav-link', | ||
| 'brave-nav-link-has-children' => $hasChildren, | ||
| 'brave-nav-link-is-active' => $isActive, | ||
| $activeClass => $isActive && $activeClass, | ||
| $item?->classes ?? null, | ||
| ]) | ||
| ->merge([ | ||
| 'aria-current' => $isActive ? 'page' : null, | ||
| ]); | ||
| @endphp | ||
|
|
||
| @if ($hasChildren) | ||
| <button {{ $baseAttributes }}> | ||
|
YvetteNikolov marked this conversation as resolved.
|
||
| {{ $label }} | ||
| </button> | ||
| @else | ||
| <a {{ $baseAttributes->merge(['href' => $href]) }}> | ||
| {{ $label }} | ||
| </a> | ||
| @endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <ul | ||
| {!! $attributes->merge([ | ||
| 'class' => 'brave-nav-list', | ||
| ]) !!}> | ||
| {{ $slot }} | ||
| </ul> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yard\Brave\Components; | ||
|
|
||
| use Illuminate\Contracts\View\Factory; | ||
| use Illuminate\View\Component; | ||
| use Illuminate\View\View; | ||
|
|
||
| class Nav extends Component | ||
| { | ||
| public function render(): Factory|View | ||
| { | ||
| return view('brave::components.nav.index'); | ||
| } | ||
|
YvetteNikolov marked this conversation as resolved.
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.