honda / navigation
navigation
Installs: 1 421
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- honda/url-pattern-matcher: ^1.0.1
- honda/url-resolver: 1.0.0
- illuminate/contracts: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- orchestra/testbench: ^6.13
- pestphp/pest: ^1.0.5
- phpstan/phpstan: ^0.12.48
- symfony/var-dumper: ^5.2.0
This package is auto-updated.
Last update: 2022-09-18 14:53:30 UTC
README
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.