-
-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dark theme #2456
base: develop
Are you sure you want to change the base?
Add dark theme #2456
Conversation
Please remove the /dist folder changes from your PR for easier review. Thanks |
@grandeljay You have now completely deleted the /dist folder. So if we would merge it, the /dist folder gets deleted.
|
@lubber-de I've copied the |
The /dist folder from the develop branch does not contain the flyout component (yet), because the dist folder will only be updated on a new release. Same for the /dist/themes folder. Please don't commit them I again suggest to reset your branch to the current develop branch and only do the changes inside the /src folder. |
it is still 2.8.8 inside the develop branch. 2.9.0 beta-xxxxx is set on the nightly builds only. |
Ok, thanks. All the changes should be gone now. If I remember correctly you said there is no way to make this I'd have to create a CSS file and import it, like you mentioned here. If that's the case, maybe I shouldn't be creating the dark theme like I have now and instead go for a CSS file |
I know there are a few considerations around implementing a dark mode, but just to add my 2 cents… Maintaining Using Dark Mode |
Ok, I've been giving this a lot of thought. There is no elegant, low maintenance way of doing this so far I am trying something like this: /**
* Dark mode
*
* Adds .inverted to all components.
*/
function ready() {
const darkModePreference = window.matchMedia("(prefers-color-scheme: dark)");
if (darkModePreference.matches) {
const usedComponents = ["container", "grid", "button", "calendar", "card", "checkbox", "dimmer", "divider", "dropdown", "form", "header", "icon", "image", "input", "label", "list", "loader", "menu", "message", "modal", "placeholder", "popup", "progress", "segment", "sidebar", "statistics", "step", "tab", "table", "text", "toast", "api", "transition"];
usedComponents.forEach(usedComponent => {
let uiComponents = document.querySelectorAll('.ui.' + usedComponent);
uiComponents.forEach(component => {
if (component.classList.contains('inverted')) {
component.classList.remove('inverted');
} else {
component.classList.add('inverted');
}
});
});
}
}
document.addEventListener("DOMContentLoaded", ready); It's quite primitive but it allows me to use a dark mode without hard-coding a bunch of CSS markup. This also scales well with fomantic updates/changes. 90% looks good to me, I can do some manual tweaks in my own CSS then. Thoughts? |
Nice approach! However, there are still many components, which do not have an inverted variant which possibly results into remaining visual issue when also the background is switched to something like black. |
Thanks! Would you still consider this? IMO it's the smartest solution yet. It would theoretically work with all themes!
Adding missing inverted variant could be done in FUI to solve this. I think that would be the "proper" way of doing things in this case. |
Clever - could potentially also use on the docs to toggle examples between normal and inverted (fomantic/Fomantic-UI-Docs#339) this could then identify where inverted may be missing or where this may need tweaking further (such as black backgrounds for segments, as lubber pointed out, and think about what happens if a child node contains another coloured item eg. A white segment within a black one) |
For a proper "default dark" theme switchable feature, i believe we really have to rework all components and move many switchable color values to css variables. Then provide a core css file and 2 "colors only" default "themes" which contain color differences only. Then it is only a matter of adding/removing one single class like "dark" to the body rather than the need to iterate through the whole DOM and switching lots of classes (what happens on dynamically changed DOM nodes?) But, for the time being and the current state of FUI themes, your approach seems valid "enough" for whom it works out nicely. Whenever we would start telling people this is the "official" way to do it, they will start claiming what combinations will not look nice, and so on.
Well, it is most probably more than just adding more inverted variants. Using your approach would mean , all possible combinations have to visually work out just as nice as the current default theme only does. |
In an attempt to finish what was started at #1436
I initially said I would attempt to continue where @AhmedEid3 left off but I was struggling a bit so I decided to start over. So far I have just swapped the default colors with the inverted ones but the result looks promising in the /examples/theming.html
Feel free to already let me know your thoughts