Customize the colors #176
-
Hi, FluxUI aims to solve two key problems:
By providing a “complete package” that addresses both issues, you need to be fully aligned with the two proposed solutions. In 2024, we should embrace modern approaches and avoid overwriting CSS styles with other styles, as was common during the era of WordPress themes. Instead, we should have a system that generates element properties like border radius and colors through the abstraction of CSS variables. I believe FluxUI handles the first problem very well, and any need to tweak functionality or components can be logically addressed through publishing the components. However, for changes such as adjusting border radius, lg heading size, or primary colors, we should rely on a dedicated stylesheet with CSS variables. The documentation mentions the following : [data-flux-button] {
@apply bg-zinc-800 dark:bg-zinc-400 hover:bg-zinc-700 dark:hover:bg-zinc-300;
} However, a better approach could be something like this in the tailwind.config.js : module.exports = {
theme: {
extend: {
colors: {
'flux-primary': {
300: '#A3BFFA',
400: '#7F9CF5',
700: '#2C5282',
800: '#2A4365',
},
},
},
},
}; At least for the action/primary colors. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 39 replies
-
Hmmm. I agree, but I'm not sure how easy it would be to implement. @apply is fine for a couple hacks you just can't fix for some reason, but think about styling the "switch ON" color, button backgrounds+borders+text+focus, badge colors, now add dark/light mode, and now do it in all components. Suddenly it's not so fun and you're publishing everything just to change blue to teal, zinc to gray, or creating a cumberson set of @apply rules you have to manage and maintain. Flux seems to be using nearly all the default Tailwindcss colors (see Badge variants). It's also using the default Tailwind colors Zinc for both text and PrimaryButton colors. So you can't simply re-map Zinc to Primary. The only way I can think of solving this is for Flux to create it's own brand colors, then allow you to override those (like WireUI does below) const colors = require('tailwindcss/colors')
module.exports = {
...
theme: {
extend: {
colors: {
...
primary: colors.indigo,
secondary: colors.gray,
positive: colors.emerald,
negative: colors.red,
warning: colors.amber,
info: colors.blue
},
},
},
...
} But - this would require everything in flux to be written with those brand colors. EG: default: bg-base-500; /* instead of Zinc so it can be overwritten */
primary: bg-flux-500;
secondary: bg-pulse-500;
positive: bg-boost-500;
negative: bg-glitch-500;
warning: bg-flare-500;
info: bg-signal-500; Not ideal but would be easy to customize once implemented. Maybe I'm missing something and there's a simpler way. |
Beta Was this translation helpful? Give feedback.
-
Publishing the stubs just to change the colours is a no-go, as is keeping everything monochrome when we actually have a brand and colours we're quite happy with. I think this feature should be given a bit more consideration that it currently is. |
Beta Was this translation helpful? Give feedback.
-
This was my solution. I wont be able to use zinc anymore, but that's fine by me. If we also get a
|
Beta Was this translation helpful? Give feedback.
-
What are all the elements that you would want to be a "primary" color? I can think of two off the top of my head:
Am I missing any? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Here's what I have been doing as a temporary workaround in my published version of Button, for example: In the button source, I added a $attributes = $attributes->merge([
"data-flux-variant-$variant" => "data-flux-variant-$variant"
]); Then, in the CSS (I have bg-primary defined in my Tailwind config): [data-flux-variant-primary] {
@apply bg-primary;
} |
Beta Was this translation helpful? Give feedback.
-
Hi, has there been any official movement on this? This is the most requested item, and nothing has happened since release. |
Beta Was this translation helpful? Give feedback.
-
Heads up: this is my primary focus. I'm exploring all sorts of solutions right now and will come up with something soon to at least style buttons and such. |
Beta Was this translation helpful? Give feedback.
-
What about using variables in the Tailwind config so brand colors can be configured in PHP, similar to Filament?
You could offer preset constants people can use, or they can use custom values. This approach means more possibilities for dynamic theming. For example a multitenant app where tenants can choose their own color. |
Beta Was this translation helpful? Give feedback.
-
YES - I figured it out! This has been bugging me for months. It might not be what Caleb goes with, but it's simple, unique, very poweful, and now its finally out of my head. Flux at it's core is 99% zinc. Do a CTRL+F here and you'll see (769 matches!): And it works well. So... what if we lean into this and re-mapped zinc to be a dynamic var-based tailwind theme? The steps below are basically what I do in my own app, but adapted to Flux. This is an excellent article I found earlier breaking down the concept in more detail: Everyone interested please follow along step by step:
colors: {
flux: {
50: 'rgb(var(--flux-50, 250 250 250) / <alpha-value>)',
100: 'rgb(var(--flux-100, 244 244 245) / <alpha-value>)',
200: 'rgb(var(--flux-200, 228 228 231) / <alpha-value>)',
300: 'rgb(var(--flux-300, 212 212 216) / <alpha-value>)',
400: 'rgb(var(--flux-400, 161 161 170) / <alpha-value>)',
500: 'rgb(var(--flux-500, 113 113 122) / <alpha-value>)',
600: 'rgb(var(--flux-600, 82 82 91) / <alpha-value>)',
700: 'rgb(var(--flux-700, 63 63 70) / <alpha-value>)',
800: 'rgb(var(--flux-800, 39 39 42) / <alpha-value>)',
900: 'rgb(var(--flux-900, 24 24 27) / <alpha-value>)',
950: 'rgb(var(--flux-950, 9 9 11) / <alpha-value>)',
},
}
// here
@props([
'color' => null,
])
// and here
$classes = Flux::classes()
->add($color ? "flux-{$color}" : '')
<div>
<style>
.flux-purple {
--flux-50: 241 242 252;
--flux-100: 229 230 250;
--flux-200: 209 209 244;
--flux-300: 181 180 237;
--flux-400: 158 150 227;
--flux-500: 140 124 216;
--flux-600: 114 86 197;
--flux-700: 107 82 176;
--flux-800: 88 68 143;
--flux-900: 73 61 114;
--flux-950: 43 35 67;
}
</style>
<div class="space-x-2 p-4">
<flux:button>Default</flux:button>
<flux:button variant="primary">Primary</flux:button>
<flux:button variant="filled">Filled</flux:button>
<flux:button variant="danger">Danger</flux:button>
<flux:button variant="ghost">Ghost</flux:button>
<flux:button variant="subtle">Subtle</flux:button>
</div>
<div class="space-x-2 p-4">
<flux:button color="purple">Default</flux:button>
<flux:button variant="primary" color="purple">Primary</flux:button>
<flux:button variant="filled" color="purple">Filled</flux:button>
<flux:button variant="danger" color="purple">Danger</flux:button>
<flux:button variant="ghost" color="purple">Ghost</flux:button>
<flux:button variant="subtle" color="purple">Subtle</flux:button>
</div>
</div>
Now, this is not a panacea, but it's pretty close....
So... the flux components that would support this would need to be somewhat refactored. Danger can be removed, and instead you can just pass you color="red" or color="danger". But you can also leave it so it's not a breaking change. ->add(match ($variant) { // Background color...
'primary' => 'bg-flux-800 hover:bg-flux-900 dark:bg-white dark:hover:bg-flux-100',
'filled' => 'bg-flux-800/5 hover:bg-flux-800/10 dark:bg-white/10 dark:hover:bg-white/20',
'outline' => 'bg-white hover:bg-flux-50 dark:bg-flux-700 dark:hover:bg-flux-600/75',
'danger' => 'bg-red-500 hover:bg-red-600 dark:bg-red-600 dark:hover:bg-red-500',
'ghost' => 'bg-transparent hover:bg-flux-800/5 dark:hover:bg-white/15',
'subtle' => 'bg-transparent hover:bg-flux-800/5 dark:hover:bg-white/15',
}) So it's mostly upside as I see it! Update: Another thought comes to mind. The color prop could accept a #hex value. Since we're using PHP, this means you could compute colors on the fly (I already do this in my app). All you'd need is to detect the hash in the prop and run a function to generate the |
Beta Was this translation helpful? Give feedback.
-
Ok, Flux has colors now. Thanks everyone for upvoting this and helping me prioritize! |
Beta Was this translation helpful? Give feedback.
Ok, Flux has colors now. Thanks everyone for upvoting this and helping me prioritize!
https://fluxui.dev/themes