Available Colors from new Color class to array?
Is there a way to get an array of all the available tailwind colors at shade 500 using this new Color class? Just trying to find a simple way to have some options for a color picker thats just buttons with the different colors. Also, do all the colors have to be registered or can we access all the core tailwind colors directly?
20 Replies
hmm, trying to think how i would want to store it in the db. im basically looking at having preselected colors options for categories that will show as badges. So obviousyl the color choice would use shade 500/10 for background and 700 for the text
Is there a way to get an array of all the available tailwind colors at shade 500 using this new Color class?Something like this?
Maybe it’s my version, but couldn’t use all() or any type of query on it.
Looks like
all()
was added in v3.0.15
if I'm reading this corectly:
https://github.com/filamentphp/filament/commit/e069570d773040dc972d8ec85bbaac984bf4bc79yep, just saw that. thanks! Guess i need to extend the alpha version and add that method. Also, looks like it should be:
I think your
filter()
does the same but obviously you know what you're doing 😜@Patrick Boivin one worked in tinker, the other return all colors and all their shades 😛
Yes, that's what your
map()
is fixing if I'm reading this rightcorrect. That you were implying a change wasnt needed. I get that isset() and ?? false are the same though.
With that said, im not sure this is even useful to me as I need to store the color so i can use with ->color() on class, but i dont think thats possible as those require class names.
i think im just going to have to add whatever 8-12 colors to my tailwind config. ugh
Do you mean referencing the Color class constants?
Like Color::Blue, etc.
yes, just created a basic color selector that looks like. I did something like , but now that i stored the value of 'Red' or if i stored the rgb value instead, i still really have no way to utilize those in lets say a BadgeColumn:make()->color() or within a blade component that has a
:class
make sense?
i think its simply not a use case for the color class and im simply forced to have precreated classes in the tailwind config
Ok yeah, makes sense
Have you explored
FilamentColor::register()
?
Not sure if you could register custom aliases for the specific colors you wantIm sure i could, but im not sure what value that gives me over simply adding them to the tailwind config
I think it would make the colors available in
->color()
, without having to update the tailwind config