Skip to content

Conversation

@andjsch
Copy link
Contributor

@andjsch andjsch commented Nov 11, 2025

This PR refactors how the theming works in regards to light and dark variants.

Instead of creating dark theme CSS classes, the default (light-mode) CSS theme classes are overridden within :root when dark mode is active.

This allows to introduce dark mode variants for all color config options, simply by prepending dark- in front of them without needing to introduce a dark-something class on a component.

For example: Till now you could only set a primary color or all grays globally. Now you can set different colors for the modes:

'theme' => [
    'dark-primary' => Color::Indigo[700],
    'primary' => Color::Indigo[500],
    'grays' => Color::Slate,
    'dark-grays' => Color::Zinc,
];

Before:

<button class="bg-ui-accent-bg dark:bg-dark-ui-accent-bg">I am a simple example</button>

After:

<button class="bg-ui-accent-bg">I am a simple example</button>

@andjsch andjsch changed the title Feature refactor css color variables [6.x] Refactor CSS color variables Nov 11, 2025
@andjsch andjsch marked this pull request as draft November 11, 2025 15:07
@andjsch andjsch marked this pull request as ready for review November 11, 2025 17:16
@jackmcdade
Copy link
Member

I like the idea but I don't think Tailwind will parse these variables when do you this. 🤔

@andjsch
Copy link
Contributor Author

andjsch commented Nov 11, 2025

@jackmcdade Works fine. Initially it didn't but I figured it out with one of the last commits. Gave it some thorough testing and couldn't find any problems so far.

But if this will eventually be merged I'd appreciate some more eyes in case I haven't found all occurrences of the classes that aren't needed anymore.

The idea was to not overcomplicate the dark mode with additional classes and make all variables configurable, dark and light.

@jackmcdade
Copy link
Member

Okay cool, I'll have a tinker and see what I can find. I also had this possible angle to make "themes" just CSS files and maybe get rid of the config thing entirely. #12947 Not sure how this would play nicely with that, but I was on the fence w/ that one anyway.

@andjsch
Copy link
Contributor Author

andjsch commented Nov 11, 2025

I think both can work together. In the end we still print out native CSS with this config. Only difference with this PR is, that we override the CSS variables for dark mode when dark mode is active.

Take a look at the head partial for reference, it's still pure CSS with less CSS variables. I'd still fancy your file approach for more sophisticated theming if one is in the need. That would give anyone ultimate theming capabilities 😆

Copy link

@JayGeorge JayGeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good to me, thanks for your work on this, Andreas :). I've played around with it and it's all working OK with the dark overrides.

While playing with the different hues I noticed some stray hard coded gray values so I fixed those.

@andjsch
Copy link
Contributor Author

andjsch commented Nov 13, 2025

Fixes #13027

@duncanmcclean duncanmcclean linked an issue Nov 13, 2025 that may be closed by this pull request
@andjsch
Copy link
Contributor Author

andjsch commented Nov 14, 2025

@jasonvarga If we want to make the newly added focus-outline to be override-able, we should add a dark-focus-outline as well.

@jasonvarga
Copy link
Member

If we want to make the newly added focus-outline to be override-able, we should add a dark-focus-outline as well.

I've adjusted the logic so adding a dark- variant to your config will work even if we don't have it in the default array.

@jasonvarga jasonvarga merged commit 971b35b into statamic:master Nov 14, 2025
18 checks passed
@andjsch andjsch deleted the feature-refactor-css-color-variables branch November 14, 2025 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[6.x] Reading time doesn't use chosen grays from theming

4 participants