honda/navigation

This package is abandoned and no longer maintained. The author suggests using the felixdorn/laravel-navigation package instead.

navigation

0.2.1 2021-11-11 18:07 UTC

This package is auto-updated.

Last update: 2022-09-18 14:53:30 UTC


README

Tests Formats Version Total Downloads License

Installation

Requires PHP 8.0+

You can install the package via composer:

composer require honda/navigation

Usage

Creating a navigation bar

use Felix\Navigation\Navigation;

Navigation::macro('theName', function (Navigation $navigation) {
    // ...
});

Rendering a navigation bar

use Felix\Navigation\Navigation;

Navigation::theName();

Items

Href

If you pass a route name like login or articles.index, the actual path will be resolved. You may pass additional context to the route resolver.

If you pass anything else, it will be rendered as-is.

$item->href('articles.index');
$item->href('articles.edit', ['article' => 1]);
$item->href('https://repo.new');

Icon

This package integrates seamlessly with Blade Icons.

$item->icon('heroicon-eye');

Force active state

This will bypass a potentially defined active pattern and force the item to be rendered as an active one.

$item->alwaysActive();

Active pattern

Mark an item as active based on an advanced pattern. The resolved route path is used if no active pattern is provided. Check out URL Pattern Matcher for more details.

$item->activePattern('/articles/*');

Conditionally rendered items

use Felix\Navigation\Item;

$navigation->addIf($isAdmin, 'Settings', function (Item $item) {
    // ...
});
$navigation->addUnless($isReader, 'Articles', function (Item $item) {
    // ...
});

Section

Add a section

use Felix\Navigation\Item;
use Felix\Navigation\Section;

$navigation->addSection('Name', function (Section $section) {
    $section->add('Child', function (Item $item) {
        // ...
    });
});

Conditionally rendered sections

use Felix\Navigation\Section;

$navigation->addSectionIf($isAdmin, 'Admin', function (Section $section) {
    // ...
});
$navigation->addSectionUnless($isReader, 'Bookmarks', function (Section $section) {
    // ...
});

Blade Components

We provide a component called <x-navigation-sidebar />, feel free to use it as-is (needs AlpineJS to be fully functional).

// app/View/Components/Topbar.php
use Felix\Navigation\Components\Component;
class Topbar extends Component {
    public function viewName() : string{
         return 'components.topbar';
    }
}

You get access to an $items variables that contains a Navigation object.

Now in your views :

<x-topbar :items="\Felix\Navigation\Navigation::myName()"/>

Testing

composer test

Navigation for Laravel was created by Félix Dorn under the MIT license.