Code Monkey home page Code Monkey logo

nova-action-button's Introduction

Nova Action Button

Latest Version on Packagist Licence Total Downloads

This package allows you to execute an action directly on your resource table view.

Installation

composer require pdmfc/nova-action-button

Usage

use App\Nova\Actions\ChangeRole;
use Pdmfc\NovaFields\ActionButton;

//...

public function fields()
{
    return [
        ActionButton::make('Action')
            ->action(ChangeRole::class, $this->id)
            //->action(new ChangeRole(), $this->id) using a new instance
    ];
}

The action() method requires two params - the action class name or a new instance, and the target resource id.

Basic example

Disabling button

You can use the native Laravel nova readonly() method to prevent users from clicking the button:

ActionButton::make('Action')
    ->action(ChangeRole::class, $this->id)
    ->readonly(function () {
        return $this->role->name === 'admin';
    })

Disabling the button

Change the button text

To edit the button text content, use the text() method.

->text('Execute')

Enable the loading animation on button and change color

To enable the loading animation on button and change color, use showLoadingAnimation() and loadingColor('#fff') method.

->showLoadingAnimation()
->loadingColor('#fff') # default is #000

Add a svg to the button

In order to add a svg to the button, you first need to create a vue component containing a svg and then pass the component name to the svg() method.

->svg('VueComponentName')

Change button color

To change button color, use buttonColor('#21b970') method.

->buttonColor('#21b970') # default is .btn-primary color

Caveats

  • Currently, in order to use this field, you still have to declare the action in your resource actions() method.

How to contribute

  • clone the repo
  • on composer.json of a laravel nova application add the following:
{
    //...

    "require" {
        "pdmfc/nova-action-button: "*"
    },

    //...
    "repositories": [
        {
            "type": "path",
            "url": "../path_to_your_package_folder"
        }
    ],
}
  • run composer update pdmfc/nova-action-button

You're now ready to start contributing!

Changelog

Please see CHANGELOG for more information on what has changed recently.

nova-action-button's People

Contributors

msouto346 avatar felipereisdev avatar skoyah avatar aaronflorey avatar mgoncalves76 avatar msoutopdmfc avatar infostreams avatar henriquespin avatar kayacekovic 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.