199ocero / radio-deck

Turn filament default radio button into a selectable card with icons, title and description.
https://filamentphp.com/plugins/jaocero-radio-deck
MIT License
63 stars 10 forks source link

Support for Enums #4

Closed hdirki closed 9 months ago

hdirki commented 9 months ago

What happened?

Great plugin! Well done. I'm trying to add a radio deck for predefined enums. I think this plugin should support enums.

How to reproduce the bug

Here's an example Enum class:

<?php

namespace App\Enums;

use Filament\Support\Contracts\HasLabel;
use Filament\Support\Contracts\HasIcon;

enum ClientType: string implements HasLabel, HasIcon
{
    case Individual = 'Individual';
    case Organisation = 'Organisation';

    public function getLabel(): ?string
    {
        $label = match ($this) {
            self::Individual => 'Individual',
            self::Organisation => 'Organisation',
        };

        return $label;
    }

    public function getIcon(): ?string
    {
        return match ($this) {
            self::Individual => 'heroicon-m-user',
            self::Organisation => 'heroicon-m-building-office',
        };
    }

}

And the use case should be like this:

RadioDeck::make('client_type')
            ->options(ClientType::class)

And that would automatically load ->descriptions() and ->icons() unless there is a way already to do this?

Package Version

1.1.1

PHP Version

8.2.1

Laravel Version

10.39.0

Which operating systems does with happen with?

macOS

Notes

No response

199ocero commented 9 months ago

You can try to use enums for ->descriptions() and ->icons() . The docs is also update so you can see it how to implement. Thanks for this!

Release: v1.1.2