Code Monkey home page Code Monkey logo

nova-toggle's Introduction

Toggle Field

A drop in replacement for the default Boolean field

Toggle In Action

Installation

Same as most other Nova Packages

composer require davidpiesse/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 Davidpiesse\NovaToggle\Toggle;
Toggle::make('Active')
    ->trueValue('On')
    ->falseValue('Off')

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

To set the text you can use either or both of the following. You must also set the visibility of the labels as described above.

Toggle::make('Active')
    ->showLabels()
    ->trueLabel('Tru Dat')
    ->falseLabel('Nah Dawg')

The defaults are 'True' and 'False'

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')
    ->editableIndex()

nova-toggle's People

Contributors

bernhardh avatar bolechen avatar daguilarm avatar davidpiesse avatar lucidlogic 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.