amidesfahani/nova-toggle

A Boolean Toggle Switch Field

dev-main 2022-06-04 22:00 UTC

This package is auto-updated.

Last update: 2024-11-05 03:08:57 UTC


README

A drop in replacement for the default Boolean field

Installation

Same as most other Nova Packages

composer require amidesfahani/nova-toggle

Usage

The Toggle has all the same options as the Boolean field so you can set the values to be stored in the Model.

use Amid\NovaToggle\Toggle;
Toggle::make('Active')
    ->inlineOnIndex()
    ->inlineOnDetail()
    ->trueText('On')
    ->falseText('Off')
    ->textOnIndex()

In addition you can set visual parameters

Labels

You can show both, or each state label

Toggle::make('Active')
    ->showLabels() //Both labels
    ->showOnlyTrueLabel() //True label only
    ->showOnlyFalseLabel() //False label only

Size

You can set the width and height. Setting the width will auto scale the height, but you can override this with ->height(). Defaults are 60 (px) and 26 (px)

Toggle::make('Active')
    ->width(80)
    ->height(45) //To override scaling

Colors

You can set wither or both of the background colours for the Toggle. By default True is the Nova 'Success Green' [ var(--success) ] and false is a Grey 60 [ var(--60) ]

Toggle::make('Active')
    ->trueColor('pink')
    ->falseColor('#fcfcfc')

Speed

You can set the animation speed in ms with

Toggle::make('Active')
    ->speed(500)

The default is 300ms

Toggle on index

You can activate the toggle on index as well with

Toggle::make('Active')
    ->inlineOnIndex()

Original Package

Licence

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.