Skip to content
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

Support Nova 4 #67

Merged
merged 6 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 29 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,44 @@
[![Total Downloads](https://img.shields.io/packagist/dt/digital-creative/resource-navigation-tab)](https://packagist.org/packages/digital-creative/resource-navigation-tab)
[![License](https://img.shields.io/packagist/l/digital-creative/resource-navigation-tab)](https://github.com/dcasia/resource-navigation-tab/blob/master/LICENSE)

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

![Resource Navigation Tab in Action](https://raw.githubusercontent.com/dcasia/resource-navigation-tab/master/screenshots/demo-1.png)
![Resource Navigation Tab in Action](./screenshots/dark/demo-2.png#gh-dark-mode-only)
![Resource Navigation Tab in Action](./screenshots/light/demo-2.png#gh-light-mode-only)

# Installation

You can install the package via composer:

```
```shell
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:
First, import `HasResourceNavigationTabTrait` trait into your resource and start grouping your fields with
the `ResourceNavigationField` object:

```php
use DigitalCreative\ResourceNavigationTab\HasResourceNavigationTabTrait;
use DigitalCreative\ResourceNavigationTab\ResourceNavigationTab;
use DigitalCreative\ResourceNavigationTab\ResourceNavigationField;

class ExampleNovaResource extends Resource {

use HasResourceNavigationTabTrait; // Important!!
use HasResourceNavigationTabTrait;

public function fields(Request $request)
public function fields(NovaRequest $request): array
{
return [
ResourceNavigationTab::make([
'label' => 'Information',
'behaveAsPanel' => true / false,
'fields' => [
ResourceNavigationField::make('Information')
->fields([
Text::make('Name'),
Text::make('Age'),
HasMany::make('Hobbies')
]
]),
ResourceNavigationTab::make([ 'label' => 'Activities' ]),
ResourceNavigationTab::make([ 'label' => 'Social Interactions' ]),
ResourceNavigationTab::make([ 'label' => 'Settings' ]),
HasMany::make('Hobbies'),
]),
ResourceNavigationField::make('Activities')->fields([ ... ]),
ResourceNavigationField::make('Social Interactions')->fields([ ... ]),
ResourceNavigationField::make('Settings')->fields([ ... ]),
];
}

Expand All @@ -52,54 +50,31 @@ class ExampleNovaResource extends Resource {

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

![Resource Navigation Tab in Action](https://raw.githubusercontent.com/dcasia/resource-navigation-tab/master/screenshots/demo-3.png)
![Resource Navigation Tab in Action](./screenshots/dark/demo-1.png#gh-dark-mode-only)
![Resource Navigation Tab in Action](./screenshots/light/demo-1.png#gh-light-mode-only)

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')`

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

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:
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:

```php
use DigitalCreative\ResourceNavigationTab\HasResourceNavigationTabTrait;
use DigitalCreative\ResourceNavigationTab\ResourceNavigationTab;
use DigitalCreative\ResourceNavigationTab\ResourceNavigationField;
use DigitalCreative\ResourceNavigationTab\CardMode;

class ExampleNovaResource extends Resource {

use HasResourceNavigationTabTrait;

public function fields(Request $request)
public function fields(NovaRequest $request): array
{
return [
ResourceNavigationTab::make([ 'label' => 'Profile' ]), // show all the available cards by default
ResourceNavigationTab::make([
'label' => 'Activities',
'cardMode' => CardMode::KEEP_ALL | CardMode::EXCLUDE_ALL // show all or remove all cards when this tab is active
]),
ResourceNavigationTab::make([
'label' => 'Preferences',
'cardMode' => CardMode::ONLY | CardMode::EXCEPT // show or remove only the selected cards
'cards' => [
ClientPerformanceCard::class,
ClientProfileCard::class,
]
]),
ResourceNavigationField::make('Information'), // show all the available cards by default
ResourceNavigationField::make('Activities')->withCards([ DailySalesCard::class, ClientProfileCard::class ]), // only show these cards when this tab is active
ResourceNavigationField::make('Settings')->withoutCards([ ... ]), // hide all cards when this tab is active
];
}

public function cards(Request $request)
public function cards(NovaRequest $request): array
{
return [
new ClientPerformanceCard(),
Expand All @@ -113,4 +88,4 @@ class ExampleNovaResource extends Resource {

## License

The MIT License (MIT). Please see [License File](https://raw.githubusercontent.com/dcasia/resource-navigation-tab/master/LICENSE) for more information.
The MIT License (MIT). Please see [License File](./LICENSE) for more information.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-creative/resource-navigation-tab",
"description": "Organize your long pile of tables and relationships into structured pages.",
"description": "Organize your resource fields into tabs.",
"keywords": [
"laravel",
"nova",
Expand All @@ -15,8 +15,8 @@
],
"license": "MIT",
"require": {
"php": ">=7.1.0",
"laravel/nova": "^3.12.0"
"php": ">=8.1",
"laravel/nova": "^4"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions dist/css/card.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading