this post was submitted on 03 Mar 2025
7 points (88.9% liked)
Programming
18491 readers
23 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Tokenise your styles with variable layers. Eg: put a class on your body tag for each theme, eg: dark-mode, high-contrast
Then define your components by abstract style variables, eg: button-color, heading-weight,
Then define the style variables for each theme:
body { --button-color: green; }
body.dark-mode { --button-color: blue; }
button { backgroud: var(--button-color); }
Then all you need to do is a simple JS function to set the appropriate theme class on your document body!
This way your components are compliant to your style guide, without needing to know the implementation details of your themeing Very SRP, much Demeter, such OCP
Apologies for psudocode, LMK if you have any furthers :)
would that work with the jekyll theme?
Yep! This pattern will work on any website. You only need to be able to write CSS, and apply a class to the body tag.
AFAIK Jekyll uses Liquid for template flow control - you could set the class; or even load specific CSS that way too
what if there’s loads of different elements where the colour could he changed such as texts, links, and different ohjects like the nav bar?