Search by

versioon / nova-inline-badge-field

Tarpsvo

A Laravel Nova inline badge field.

Package info

github.com/Versioon/nova-inline-badge-field

pkg:composer/versioon/nova-inline-badge-field

Statistics

Installs: 569

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.3 2026-09-15 08:35 UTC

This package is not auto-updated.

Last update: 2026-09-15 08:41:29 UTC


README

Latest Version on Packagist Total Downloads

This Laravel Nova package adds an inline badge field to Nova's arsenal of fields.

Requirements

  • php: >=8.0
  • laravel/nova: ^5.0

Features

A Select field on Form views that renders as a colored badge on Index and Detail views. Clicking the badge opens a native <select>; picking a value sends a Nova update request for the resource and re-colors the badge inline — no need to open the edit form.

Demo

Installation

Install the package in to a Laravel app that uses Nova via composer:

composer require versioon/nova-inline-badge-field

Usage

General

The field extends Nova's Select field, so options() defines the dropdown choices used on both the form and the inline editor. map() maps each value to a badge type (success, info, danger, warning, or a custom type registered via types()).

use Versioon\NovaInlineBadgeField\InlineBadge;

public function fields(Request $request) {
    InlineBadge::make('Status')
        ->options([
            'draft' => 'Draft',
            'published' => 'Published',
            'archived' => 'Archived',
        ])
        ->map([
            'draft' => 'warning',
            'published' => 'success',
            'archived' => 'danger',
        ]),
}

Customizing badges

The following Badge-style helpers are available in addition to everything inherited from Select:

InlineBadge::make('Status')
    ->options([...])

    // Map field values to built-in or custom badge types.
    ->map(['draft' => 'warning', 'published' => 'published'])

    // Register custom badge types and their CSS classes.
    ->types([
        'published' => 'bg-green-100 text-green-600 dark:bg-green-500 dark:text-green-900',
    ])

    // Or color badge types with hex/rgb values instead of CSS classes.
    ->textColors([
        'published' => '#166534',
        'warning' => 'rgb(146, 64, 14)',
    ])
    ->badgeColors([
        'published' => '#dcfce7',
        'warning' => 'rgba(254, 243, 199, 0.9)',
    ])

    // Override the label shown on the badge per value...
    ->labels(['published' => 'Live'])
    // ...or resolve it with a callback.
    ->label(fn ($value) => ucfirst($value))

    // Show an icon on the badge (defaults provided for the built-in types).
    ->withIcons()
    ->icons(['published' => 'check-circle']),

If a value isn't present in map()/types(), the badge renders without a color class.

textColors() and badgeColors() are keyed by badge type (the value from map(), or the raw value if it isn't mapped) and accept hex (#rgb, #rrggbb, with optional alpha) or rgb()/rgba() strings; anything else throws an InvalidArgumentException. They're applied as inline styles, so they override colors from the type's CSS classes and apply in both light and dark mode. Labels fall back to the matching options() label, then to the raw value.

Credits

License

Nova Inline Badge Field is open-sourced software licensed under the MIT license.