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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/forms/resources/js/components/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export default function fileUploadFormComponent({
.map((file) =>
file.source instanceof File
? file.serverId
: this.uploadedFileIndex[file.source] ?? null,
: (this.uploadedFileIndex[file.source] ?? null),
) // file.serverId is null for a file that is not yet uploaded
.filter((fileKey) => fileKey)

Expand Down
10 changes: 5 additions & 5 deletions packages/infolists/src/Components/Concerns/HasColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public function getColor(mixed $state): string | array | null
return null;
}

if (filled($color)) {
return $color;
if ($color instanceof ColorInterface) {
return $color->getColor();
}

if (! $state instanceof ColorInterface) {
return null;
if (filled($color)) {
return $color;
}

return $state->getColor();
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

if (
(@js($this instanceof \Filament\Actions\Contracts\HasActions) ? $wire.mountedActions?.length ?? 0 : 0) &&
(@js($this instanceof \Filament\Actions\Contracts\HasActions) ? ($wire.mountedActions?.length ?? 0) : 0) &&
!$wire?.__instance?.effects?.redirect
) {
event.preventDefault()
Expand Down
13 changes: 12 additions & 1 deletion packages/support/src/Concerns/HasColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Filament\Support\Concerns;

use Closure;
use Filament\Support\Contracts\HasColor as ColorInterface;

trait HasColor
{
Expand Down Expand Up @@ -41,6 +42,16 @@ public function defaultColor(string | array | Closure | null $color): static
*/
public function getColor(): string | array | null
{
return $this->evaluate($this->color) ?? $this->evaluate($this->defaultColor);
$color = $this->evaluate($this->color) ?? $this->evaluate($this->defaultColor);

if ($color instanceof ColorInterface) {
return $color->getColor();
}

if (filled($color)) {
return $color;
}

return null;
}
}
2 changes: 1 addition & 1 deletion packages/tables/src/Filters/SelectFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function multiple(bool | Closure $condition = true): static
}

/**
* @param bool | array<string> | Closure $condition
* @param bool | array<string> | Closure $condition
*/
public function searchable(bool | array | Closure $condition = true): static
{
Expand Down
18 changes: 18 additions & 0 deletions tests/src/Tables/Fixtures/ColorEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Filament\Tests\Tables\Fixtures;

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

enum ColorEnum implements ColorInterface
{
case Red;

public function getColor(): string | array | null
{
return match ($this) {
self::Red => Color::Red,
};
}
}
4 changes: 4 additions & 0 deletions tests/src/Tables/Fixtures/PostsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public function table(Table $table): Table
'red' => 'Red',
'blue' => 'Blue',
]),
Tables\Columns\TextColumn::make('colour_red')
->color(fn (): ColorEnum => ColorEnum::Red),
Tables\Columns\TextColumn::make('title2')
->sortable()
->searchable()
Expand Down Expand Up @@ -157,6 +159,8 @@ public function table(Table $table): Table
->label('My Action'),
Action::make('hasColor')
->color('primary'),
Action::make('hasEnumColor')
->color(fn () => ColorEnum::Red),
Action::make('exists'),
Action::make('existsInOrder'),
Action::make('url')
Expand Down
Loading