Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for color interface to be used in color #14343

Closed
wants to merge 4 commits into from

Conversation

howdu
Copy link
Contributor

@howdu howdu commented Sep 25, 2024

Description

Allow for Enum with ColorInterface to be returned from closure.

TextColumn::make('test')
   ->color(fn (?string $state): ColorEnum => $state ? ColorEnum::Success : ColorEnum::Danger)

E.g

use Filament\Support\Colors\Color;
use Filament\Support\Contracts\HasColor as ColorInterface;

enum ColorEnum: string implements ColorInterface
{
    case Danger = 'danger';
    case Success = 'success';

    public function getColor(): string|array|null
    {
        return match ($this) {
            self::Danger => Color::Red,
            self::Success => Color::Green,
        };
    }
}

Visual changes

Without this change it always entered the filled if statement and throws error.
Screenshot 2024-09-24 at 20 02 41

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

@zepfietje zepfietje added this to the v4 milestone Sep 26, 2024
@zepfietje zepfietje changed the title 4.x Allow for color interface to be used in color Allow for color interface to be used in color Sep 26, 2024
@zepfietje
Copy link
Member

What exactly would be the use case of this, @howdu?

@howdu
Copy link
Contributor Author

howdu commented Sep 27, 2024

Actually sorry yeah reconsidering this it's not needed.

@howdu howdu closed this Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants