Giter Site home page Giter Site logo

nova-badge-field's Introduction

Laravel Nova Badge Field

Works with Nova 4!


This is a simple Laravel Nova Badge field. It extends the Select field and allows a simple mapping of colors to values to display a "Badge" on the index and details pages. Can be customized with tailwind classes

Details Page

details page select

Index

index badge

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require timothyasp/nova-badge-field

For Nova v1 - v3 support, use "timothyasp/nova-badge-field": "^1.04" in your composer.json

Usage

In addition to any of the Select field options and presentation methods, here are a few Badge specific customizations this package provides.

To customize the text color of the badge, set the color attribute on the option. If there isn't an option set, it defaults to setting the background color and the text color is set to a contrasting white/black color based on the brightness of the background.

use Timothyasp\Badge\Badge;

$options = [
    'option1' => 'Option 1',
    'option2' => 'Option 2'
];

Badge::make('Field')
   ->options($options)
   ->colors([
      'option1' => '#ffffff',
      'option2' => '#000000'
   ]);

If you prefer to use the label as the display text on the index and detail pages, you can use the ->displayUsingLabels() option.

use Timothyasp\Badge\Badge;

$options = [
  'Option 1' => 1,
  'Option 2' => 2
];

Badge::make('Field')
   ->options($options)
   ->colors([
      'Option 1' => '#ffffff',
      'Option 2' => '#000000'
   ])->displayUsingLabels();

Finally, if you need even more customization on the badge display, use the extraClasses method to pass along any additional Tailwind classes to customize the appearance of the Badge.

This is useful if you'd like to customize the badges to be stacking instead of inline, when using the Stack field.

use Timothyasp\Badge\Badge;

$options = [
    'option1' => 'Option 1',
    'option2' => 'Option 2'
];

Badge::make('Field')
    ->options($options)
    ->extraClasses('mr-2 text-4xl flex');

Credits

Built for QuizGriz - the #1 online trivia and quiz game site

License

The MIT License (MIT). Please see License File for more information.

nova-badge-field's People

Contributors

batformat avatar shaneshipston avatar timothyasp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nova-badge-field's Issues

Disable specific options

Hi @timothyasp,

Thank you for this package!

I am using this package to display/update the state of orders by administrators.

Consider the following states for an order:
cart -> pending_payment -> processing -> completed

I want to disable options cart and pending_paymentwhen an order state is `processing.

Is there any way to disable some displayed options?

Field value documentation

Hey Tim,

I can't seem to replace the displayed value, with a label

Here's a snippet:

Badge::make('Tier', 'tier')
->options(['1' => 'T1', '2' => 'T2'])
->colors([
   "1" => [
      "background" => '#333,
      "color" => '#fff',
   ],
   "2" => [
      "background" => '#fff',
      "color" => '#333',
   ]
]),

I, for the life of me, can't seem to get T1/T2 to display over the colors key.

I'll write up a block for your README once we get this cleared up ;)

How can i set the font colour?

Laravel Nova 4.16
Laravel 9.36

How do i set the text colour?
Is there an option to set the text colour and not rely on the contrast black/white?
Thanks.

Badge not found

Hello,

I get the following error, when I try to use your Badge.

Badge not found.

Outline style

Would be great if you could add the option to define the border / border-color:

   ->colors([
      'option1' => [
          'background' => '#ffffff',
          'color' => '#ffa500',
          'border-color' => '#ffa500' // default: 1px solid
          'border' => '1px solid #ffa500', // full controll
      ],

or full style control:

   ->colors([
      'option1' => [
          'style' => 'color: #ffa500; border: 1px solid #ffa500'
      ],

or outline option, which uses color and background:

->outline()

e.g. to get an outline style like this

alert-incidents 2020-06-23 11-40-32

alert-incidents 2020-06-23 11-40-47

don't show in index

hi, i have this code

image

in edit and the view i can see my select
image

but in index no
image

Set color and background for all values except defined

Hi!
I'm looking for a next thing.
I set color and background for 2 values, that I know they could be there.
And third value is a datetime, which could have any value, so I cant predict its value and add it to options array.
How to define common color for all these values that were not defined as known options?

Allow using displayUsingLabels

I'm using this component to display a boolean field with green or red, but want to show a custom label (Active / Disabled). This component extends from select, should be easy to use displayUsingLabels feature. Thanks!

Badges Don't Respect Nova's Text Alignment Methods

For smaller badges that may not take up the entire column space, I tried adding Nova's built in methods:

->textAlign('center') and ->withMeta(['textAlign' => 'center'])

However because the badges are using spans, they do not center inside the column correctly.

I imagine there is some custom css needed when text alignment changes are detected

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.