Coder Social home page Coder Social logo

sten / filament-navigation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ryangjchandler/filament-navigation

0.0 0.0 0.0 1.07 MB

Build structured navigation menus in Filament.

License: MIT License

JavaScript 3.27% PHP 82.37% CSS 0.26% Blade 14.10%

filament-navigation's Introduction

Build structured navigation menus in Filament.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This plugin for Filament provides a Navigation resource that allows to build structural navigation menus with ease.

Installation

Begin by installing this package via Composer:

composer require ryangjchandler/filament-navigation

Run Migration:

php artisan migrate

Publish the package's assets:

php artisan vendor:publish --tag="filament-navigation-assets"

Usage

The NavigationResource is automatically registered with Filament so no configuration is required to start using it.

If you wish to customise the navigation group, sort or icon, you can use the respective NavigationResource::navigationGroup(), NavigationResource::navigationSort() and NavigationResource::navigationIcon() methods.

Data structure

Each navigation menu is required to have a name and handle. The handle should be unique and used to retrieve the menu.

Items are stored inside of a JSON column called items. This is a recursive data structure that looks like:

[
    {
        "label": "Home",
        "type": "external-link",
        "data": {
            "url": "/",
            "target": "_blank",
        },
        "children": [
            // ...
        ],
    }
]

The recursive structure makes it really simple to render nested menus / dropdowns:

<ul>
    @foreach($menu->items as $item)
        <li>
            {{ $item['label'] }}

            @if($item['children'])
                <ul>
                    {{-- Render the item's children here... --}}
                </ul>
            @endif
        </li>
    @endforeach
</ul>

Retrieving a navigation object

To retrieve a navigation object, provide the handle to the RyanChandler\FilamentNavigation\Facades\FilamentNavigation::get() method.

use RyanChandler\FilamentNavigation\Facades\FilamentNavigation;

$menu = FilamentNavigation::get('main-menu');

Custom item types

Out of the box, this plugin comes with a single "item type" called "External link". This item type expects a URL to be provided and an optional "target" (same tab or new tab).

It's possible to extend the plugin with custom item types. Custom item types have a name and an array of Filament field objects that will be displayed inside of the "Item" modal.

This API allows you to deeply integrate navigation menus with your application's own entities and models.

use RyanChandler\FilamentNavigation\Facades\FilamentNavigation;

FilamentNavigation::addItemType('Post link', [
    Select::make('post_id')
        ->searchable()
        ->options(function () {
            return Post::pluck('title', 'id');
        })
]);

All custom fields for the item type can be found inside of the data property on the item.

The Navigation field type

This plugin also provides a custom Filament field that can be used to search and select a navigation menu inside other forms and resources.

use RyanChandler\FilamentNavigation\Filament\Fields\NavigationSelect;

->schema([
    NavigationSelect::make('navigation_id'),
])

By default, this field will not be searchable and the value for each option will be the menu id.

To make the field searchable, call the ->searchable() method.

->schema([
    NavigationSelect::make('navigation_id')
        ->searchable(),
])

If you wish to change the value for each option, call the ->optionValue() method.

->schema([
    NavigationSelect::make('navigation_id')
        ->optionValue('handle'),
])

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

filament-navigation's People

Contributors

ryangjchandler avatar dependabot[bot] avatar github-actions[bot] avatar danielbehrendt avatar bumbummen99 avatar blackmunk avatar flxsource avatar howdu avatar mynamespace avatar fdt2k avatar digitall-it avatar happytodev avatar koupisbean avatar justrau avatar devmatheus avatar kristories avatar lordjoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.