How to set color for labeled text ? #1715
Replies: 2 comments
-
Here is an example of how I have done it for colouring rows: public function configure(): void
{
$this->setTrAttributes(fn($row) => [
'style' => 'background-color: ' . ($row->some_conditions ? 'white' : 'black') . ';',
]);
} Example of it in use using Enums: public function configure(): void
{
$this->setTrAttributes(fn($row) => [
'style' => 'background-color: ' . $row->flag?->getColor() . '; color: ' . (\App\Helpers\ColorHelper::isColorDark($row->flag?->getColor()) ? 'white' : 'black') . ';',
]);
}
enum ApplicationFlagEnum: int
{
case CONTRACT_REQUIRED = 0;
case AWAITING_RESPONSE = 1;
case RESOLVED = 2;
case HIGH_RISK = 3;
public function getName(): string
{
return match ($this) {
self::CONTRACT_REQUIRED => 'Contact Required',
self::AWAITING_RESPONSE => 'Awaiting Response',
self::RESOLVED => 'Resolved',
self::HIGH_RISK => 'High Risk',
};
}
public function getColor(): string
{
return match ($this) {
self::CONTRACT_REQUIRED => '#FF0000',
self::AWAITING_RESPONSE => '#0E00FF',
self::RESOLVED => '#1DFF01',
self::HIGH_RISK => '#B60600',
};
}
}
My colour helper: https://gist.github.com/mrl22/faacd7bd534f68cb97e3a27a5b547684 |
Beta Was this translation helpful? Give feedback.
-
Some pointers Use setTdAttributes to set classes for a column Use setAdditionalSelects, to add columns/fields that don't exist as a non-label column to the query (so that you can use the values). If you are still stuck, share your whole table component and I'll give you some guidance. |
Beta Was this translation helpful? Give feedback.
-
In laravel/livewire 10 app I added rappasoft/laravel-livewire-tables ^3.2.5 and in tyable
want to make coloreb label in which text and color are rendered from enum field :
It looks like :
https://img001.prntscr.com/file/img001/Fe2brgAvQZy3y74hvWr2Qg.png
In which way can I set text color/ background color for labeled text ?
Beta Was this translation helpful? Give feedback.
All reactions