digital-creative / resource-navigation-tab

Organize your long pile of tables and relationships into structured pages.

Stars
3

Resource Navigation Tab

Latest Version on Packagist
Total Downloads
License

Organize your long pile of tables and relationships into structured pages.

Resource Navigation Tab in Action

Installation

You can install the package via composer:

composer require digital-creative/resource-navigation-tab

Basic Usage

First, import HasResourceNavigationTabTrait trait into your resource
and start grouping your fields with the ResourceNavigationTab object:

use DigitalCreative\ResourceNavigationTab\HasResourceNavigationTabTrait;
use DigitalCreative\ResourceNavigationTab\ResourceNavigationTab;

class ExampleNovaResource extends Resource {
 
    use HasResourceNavigationTabTrait; // Important!!

    public function fields(Request $request)
    {
        return [
            ResourceNavigationTab::make('Information', [
                Text::make('Name'),
                Text::make('Age'),
                HasMany::make('Hobbies')
            ])
            ResourceNavigationTab::make('Activities', [...]),
            ResourceNavigationTab::make('Social Interactions', [...]),
            ResourceNavigationTab::make('Settings', [...]),
        ];
    }

}

Once setup navigate to your resource detail view, and you should be presented with this card:

Resource Navigation Tab in Action

By default the main resource table (the one with the edit/delete buttons) will have the same title as your tabs,
however you can customize it by calling ->resourceTableTitle('Another title')

public function fields(Request $request)
{
    return [
        ResourceNavigationTab::make('Tab Title', [...])->resourceTableTitle('Resource Table Title'),
    ];
}

Every defined card will be shown on every tab by default,
however you can choose which card you want to show when a specific tab is selected:

use DigitalCreative\ResourceNavigationTab\HasResourceNavigationTabTrait;
use DigitalCreative\ResourceNavigationTab\ResourceNavigationTab;

class ExampleNovaResource extends Resource {
 
    public function fields(Request $request)
    {
        return [
            ResourceNavigationTab::make('Profile', []), // show all the availiable cards by default
            ResourceNavigationTab::make('Activities', [...])->removeCards([ ClientProfileCard::class, ... ]), // remove only the specified card from this tab
            ResourceNavigationTab::make('Preferences', [...])->withoutCards(), // removes all cards when this tab is active
        ];
    }

    public function cards(Request $request)
    {
        return [
            new ClientPerformaceCard(),
            new DailySalesCard(),
            new ClientProfileCard()
        ];
    }

}

License

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