Code Monkey home page Code Monkey logo

filament-badgeable-column's Introduction

Filament Badgeable Column

Latest Version on Packagist Total Downloads

With Filament Badgeable Column you append badges to your columns.

Light View

Dark View

With Tags View

Installation

You can install the package via composer:

composer require awcodes/filament-badgeable-column

Optionally, you can publish the views, translations and assets using

php artisan vendor:publish --tag="filament-badgeable-column-views"
php artisan vendor:publish --tag="filament-badgeable-column-translations"
php artisan vendor:publish --tag="filament-badgeable-column-assets"

Usage

BadgeableColumn

use Awcodes\FilamentBadgeableColumn\Components\Badge;
use Awcodes\FilamentBadgeableColumn\Components\BadgeField;
use Awcodes\FilamentBadgeableColumn\Components\BadgeableColumn;

return $table
    ->columns([
        BadgeableColumn::make('title')
            ->badges([
                Badge::make('front_page')
                    ->label('Front Page')
                    ->color('success')
                    ->visible(fn ($record): bool => $record->front_page),
                Badge::make('front_page_custom_color')
                    ->label('Badass')
                    ->color('#bada55')
                    ->visible(fn ($record): bool => $record->front_page),
                Badge::make('trashed')
                    ->label('Trashed')
                    ->color('danger')
                    ->visible(fn ($record): bool => $record->deleted_at ?? false),
                BadgeField::make('status')
                    ->options([
                        'Draft' => 'Draft',
                        'Review' => 'In Review',
                        'Published' => 'Published'
                    ])
                    ->colors([
                        'gray' => 'Draft',
                        'warning' => 'Review',
                        'success' => 'Published',
                    ])
                    ->visible(fn ($record): bool => $record->status !== Status::Published->name)
            ])
            ->searchable()
            ->sortable(),
    ]);

You can also define the array of badges via a closure, if you want the array of badges to be based on dynamic data. The closure should return an array of Badge or BadgeField objects, similar to above.

The example below assumes the records have a BelongsToMany relationship called topics, and shows how to display each topic name as a badge.

use Awcodes\FilamentBadgeableColumn\Components\Badge;
use Awcodes\FilamentBadgeableColumn\Components\BadgeField;
use Awcodes\FilamentBadgeableColumn\Components\BadgeableColumn;

return $table
    ->columns([
        BadgeableColumn::make('title')
            ->badges(function($record) {
                  return $record->topics->map(function($topic) {
                    return Badge::make($topic->name)->color($topic->color)
                  });
            })
            ->searchable()
            ->sortable(),
    ]);

Badgeable Tags Column

This is similar to the Badgeable Column except it allows you to use an array of data to simply output badges in the column. You field must return an array from the record.

use Awcodes\FilamentBadgeableColumn\Components\BadgeableTagsColumn;

BadgeableTagsColumn::make('tags')
    ->colors([
        'gray',
        'primary' => 'Dan',
        '#bada55' => 'Zep',
        'warning' => 'Dennis',
        '#0e7490' => 'Ryan',
    ]),

Wrapping

If you need to wrap the badges to keep your columns from getting too wide you can use the wrapEvery() method to tell the column where to break.

use Awcodes\FilamentBadgeableColumn\Components\BadgeableTagsColumn;

BadgeableTagsColumn::make('tags')
    ->wrapEvery(3)

Badge Shape

If you prefer to have a more "square" shape you can use the asPills() method to set the shape of the badges. The default is that each badge will be a pill shape.

use Awcodes\FilamentBadgeableColumn\Components\BadgeableTagsColumn;

BadgeableTagsColumn::make('tags')
    ->asPills(false)
    ->colors([
        'gray',
        'primary' => 'Dan',
        '#bada55' => 'Zep',
        'warning' => 'Dennis',
        '#0e7490' => 'Ryan',
    ]),

Badge Text Color

You may customize the color of the label for a badge with the textColor method. This only works with custom colors.

Badge::make('front_page_custom_color')
    ->label('Badass')
    ->color('#bada55')
    ->textColor('#ff0000')

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

filament-badgeable-column's People

Contributors

awcodes avatar dave-mills avatar dependabot[bot] avatar github-actions[bot] avatar howdu avatar thijmenkort avatar ziming avatar

Watchers

 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.