New Theme "daisyUI" #1974
Replies: 1 comment 2 replies
-
I think it's important to note that the reason Tailwind is so popular, particularly with this package, is the ability to over-ride the defaults with ease, for example, changing the background colour of a table cell, based on the value: This example would change the background colour of the "Total" field/column, based on whether it's less than 501 (red), 501-999 (amber), or 1000+ (green) public function configure(): void
{
// Column is the "Total" Field, and the value of Total is Less Than or Equal to 500 - Set Background of Table Cell to Red
$this->setTdAttributes(function(Column $column, $row, $columnIndex, $rowIndex) {
if ($column->isField('total') && $row->total <= 500) {
return [
'class' => 'bg-red-500 text-white',
];
} // Column is the "Total" Field, and the value of Total is Between 501 and 999 - Set Background of Table Cell to Amber
else if ($column->isField('total') && $row->total > 500 && $row->total < 1000) {
return [
'class' => 'bg-amber-500 text-white',
];
} // Column is the "Total" Field, and the value of Total is 1000 or more - Set Background of Cell to Green
else if ($column->isField('total') && $row->total >= 1000) {
return [
'class' => 'bg-green-500 text-white',
];
}
return [];
});
} Daisy under the hood simply uses tailwind's apply directive, and doesn't actually ADD anything. The whole idea behind the level of customisation present, is that someone can choose precisely which classes to apply. A significant number of the elements now have options to override JUST the colours, or JUST the styling classes, meaning it's easier to adjust individual element colours, without worrying about breaking anything. I'd understand completely if the package didn't allow for customisation of classes/attributes on almost every element! My concern is - we'd add in a "daisy" theme (which would be a ton of Tailwind apply directives effectively), and developers would then have to create their own apply directive based classes, to override, and if we change something in the core theme, they'd have to hold off on updating (and thus miss out on new features), until they're able to add it in. Then dealing with the troubleshooting that comes with "Why isn't setTdAttributes producing the right result for me with Daisy, when I've used the keithnd6-td class?" I dunno, maybe I'm missing something here! Feel free to reach out on the Discord to discuss properly, and feel free to open a PR for review, but as far as I can tell, it'll make customising individual elements more difficult. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone! We've been experimenting with adding more themes under the Tailwind umbrella.
The package already offers enough customizability to override most of the table rows and columns' CSS classes, but we wanted to go further. So, we added a whole new theme: "daisyUI". This is a component library built on top of Tailwind that uses semantic class names instead of core utility classes.
Why did we do this?
Beyond adding new themes for users, we noticed that maintaining CSS classes across Tailwind can become unwieldy.
Imagine a scenario where you need to change the background color for an active selected row. This would require the maintainer to search and replace that specific Tailwind color for the active selection, both for light and dark modes. While it's manageable when there aren't many instances, it can quickly become complex.
I agree this example might be too simplistic, but take this example and consider the various components across the package and apply this same example to all those components, now it suddenly starts to not be as fun and simple 😅.
Advantages
theme=”daisyui”
and everything should still be fine with their default tailwind config.Bootstrap
theme 😄 by playing with the configs.Disadvantages
composer test
.1.Probably, the guide to adding a new theme in the package has been
config('livewire-tables.theme') === 'tailwind’, $isTailwind and $component->isTailwind()
these gave an indicator of where Tailwind was used and therefore helped in showing were we needed to add any daisyUI specific configurations.Showcase
Here are some of the examples from when using the accompanying demo repo
laravel-livewire-tables
We have implemented this into our project with success, we would like to know if we could create a pull request for this feature?
Beta Was this translation helpful? Give feedback.
All reactions