All Projects → inspheric → Nova Indicator Field

inspheric / Nova Indicator Field

A colour-coded indicator field for Laravel Nova

Projects that are alternatives of or similar to Nova Indicator Field

Laravel Nova Excel
🚀 Supercharged Excel exports for Laravel Nova Resources
Stars: ✭ 259 (+139.81%)
Mutual labels:  laravel, laravel-package, nova
Awesome Nova
🎉 A curated list of awesome things related to Laravel Nova
Stars: ✭ 92 (-14.81%)
Mutual labels:  laravel, nova
Laravel Rest Api
Powerful RestAPI plugin for Laravel
Stars: ✭ 90 (-16.67%)
Mutual labels:  laravel, laravel-package
Cray
A Laravel package to help you generate nearly complete CRUD pages like crazy!
Stars: ✭ 108 (+0%)
Mutual labels:  laravel, laravel-package
Bigbluebutton
Package that provides easily communicate between bigbluebutton server and laravel framework
Stars: ✭ 85 (-21.3%)
Mutual labels:  laravel, laravel-package
Laravel Id Generator
Easy way to generate custom ID from database table in Laravel framework.
Stars: ✭ 88 (-18.52%)
Mutual labels:  laravel, laravel-package
Admin One Laravel Dashboard
Admin One — Free Laravel Dashboard (Bulma Buefy Vue.js SPA)
Stars: ✭ 94 (-12.96%)
Mutual labels:  laravel, laravel-package
Laravel Console Logger
Logging and Notifications for Laravel Console Commands.
Stars: ✭ 79 (-26.85%)
Mutual labels:  laravel, laravel-package
Laravel Tracer
Shows the path of each blade file loaded in a template
Stars: ✭ 96 (-11.11%)
Mutual labels:  laravel, laravel-package
Laravel Google Translate
This package makes using the Google Translate API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.
Stars: ✭ 97 (-10.19%)
Mutual labels:  laravel, laravel-package
Laravel Excel
🚀 Supercharged Excel exports and imports in Laravel
Stars: ✭ 10,417 (+9545.37%)
Mutual labels:  laravel, laravel-package
Laravel Enum
Elegant Enum implementation for Laravel
Stars: ✭ 107 (-0.93%)
Mutual labels:  laravel, laravel-package
Laravel Schedule List
Laravel package to add command to list all scheduled artisan commands
Stars: ✭ 84 (-22.22%)
Mutual labels:  laravel, laravel-package
Laravel Sync Migration
Developer tool helps to sync migrations without refreshing the database
Stars: ✭ 89 (-17.59%)
Mutual labels:  laravel, laravel-package
Laravel Url Shortener
Powerful URL shortening tools in Laravel
Stars: ✭ 80 (-25.93%)
Mutual labels:  laravel, laravel-package
Dropzone Laravel Image Upload
Laravel 5.2 and Dropzone.js auto image uploads with removal links
Stars: ✭ 92 (-14.81%)
Mutual labels:  laravel, laravel-package
Collapsible Resource Manager
A custom sidebar menu with collapsible groups
Stars: ✭ 100 (-7.41%)
Mutual labels:  laravel, nova
Laravel Pdf
A Simple package for easily generating PDF documents from HTML. This package is specially for laravel but you can use this without laravel.
Stars: ✭ 79 (-26.85%)
Mutual labels:  laravel, laravel-package
Eloquent Approval
Approval process for Laravel Eloquent models
Stars: ✭ 79 (-26.85%)
Mutual labels:  laravel, laravel-package
Lara Lens
Laravel package for display diagnostic (config, database, http connections...)
Stars: ✭ 96 (-11.11%)
Mutual labels:  laravel, laravel-package

Laravel Nova Indicator Field

A colour-coded indicator field for Laravel Nova

Latest Version on Packagist Total Downloads

Installation

Install the package into a Laravel app that uses Nova with Composer:

composer require inspheric/nova-indicator-field

Usage

Add the field to your resource in the fields method:

use Inspheric\Fields\Indicator;

Indicator::make('Status'),

The field extends the base Laravel\Nova\Fields\Field field, so all the usual methods are available.

Options

Labels

Add your desired status labels:

Indicator::make('Status')
    ->labels([
        'banned' => 'Banned',
        'active' => 'Active',
        'invited' => 'Invited',
        'inactive' => 'Inactive',
    ])

The array key is the raw field value and the array value is the desired label.

You can, of course use the Laravel trans() or __() functions to translate the labels.

If a label is not defined for a value that appears in the field, the "unknown" label will be used (see below).

Without Labels

If you do not need to specify a different label, you can simply display the raw field value:

Indicator::make('Status')
    ->withoutLabels()

Unknown Label

Specify the label when the raw field value does not correspond to one of the labels you defined:

Indicator::make('Status')
    ->unknown('Unknown')

You can, of course use the Laravel trans() or __() functions to translate the unknown label.

If this is not set, an em dash will be displayed instead.

This setting does not apply when withoutLabels() has been used. In that case, an unknown label will display with its raw value.

Should Hide

The indicator can be hidden if the field value is equal to a given value(s) or a callback:

Indicator::make('Status')
    ->shouldHide('active')
Indicator::make('Status')
    ->shouldHide(['invited', 'requested'])
Indicator::make('Status')
    ->shouldHide(function($value) {
        return $value == 'inactive';
    })

This is useful if you only want to highlight particular values in the grid and hide others, e.g. you want banned users to be displayed with a red indicator and label, and for active (not banned) users, you don't want the indicator displayed at all.

Should Hide If No

The indicator can be hidden if the field value is anything that PHP considers as falsy, i.e. false, 0, null or '':

Indicator::make('Status')
    ->shouldHideIfNo()

This is a shortcut for a common scenario for the above shouldHide() method.

Colours

Named Colours

Add your desired status colours:

Indicator::make('Status')
    ->colors([
        'banned' => 'red',
        'active' => 'green',
        'invited' => 'blue',
        'inactive' => 'grey',
    ])

The array key is the raw field value and the array value is the desired colour.

If a colour is not specified for a status, it will be displayed as grey.

The available colours are the default "base" colours from Tailwind, with the addition of black:

  • 'black' #22292F
  • 'grey' or 'gray' #B8C2CC
  • 'red' #E3342F
  • 'orange' #F6993F
  • 'yellow' #FFED4A
  • 'green' #38C172
  • 'teal' #4DC0B5
  • 'blue' #3490DC
  • 'indigo' #6574CD
  • 'purple' #9561E2
  • 'pink' #F66D9B

As well as the following Nova variable colours:

  • 'success' var(--success)
  • 'warning' var(--warning)
  • 'danger' var(--danger)
  • 'info' var(--info)

Colour classes are not validated against the lists above, so if you enter an invalid colour, it will fall back to grey.

Literal Colours

You can also use your own hexadecimal, RGB/RGBA or HSL/HSLA literal colours or variables, as in CSS:

Indicator::make('Status')
    ->colors([
        '...' => '#ff0000',
        '...' => 'rgb(0, 255, 0)',
        '...' => 'rgba(0, 0, 0, 0.5)',
        '...' => 'hsl(120, 100%, 50%)',
        '...' => 'hsla(120, 100%, 50%, 0.5)',
        '...' => 'var(--success)',
    ])

Literal colours are not validated, so if you enter an invalid CSS colour, it will fall back to grey.

Additional Colour Classes

If you want to specify your own colours as reusable classes, you can serve your own CSS file using Nova's Asset functionality. The classes must be prefixed with indicator-:

.indicator-yourcolourname {
    background: #000000;
}

Which you would use in the field definition without the 'indicator-' prefix, as:

Indicator::make('Status')
    ->colors([
        'yourstatus' => 'yourcolourname',
    ])

Appearance

The field is displayed similarly to the built-in Laravel\Nova\Fields\Boolean field, with the ability to have more than a true/false value, and different labels and colours defined.

Index

index-field

Detail

detail-field

Form

(Same as detail.)

The indicator is not displayed on forms by default. If you choose to display it as a form field with showOnUpdate(), the indicator is not editable and does not write back to the server, as it is intended to come from a read-only or derived model attribute.

If you do need an editable status field, you might want to add your own additional Laravel\Nova\Fields\Select field to your resource, referencing the same attribute name, and with onlyOnForms() set.

Donate

💜 If you like this package, you can show your appreciation by donating any amount via PayPal to support ongoing development.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].