Skip to content
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

T345056: dark mode #186

Merged
merged 13 commits into from Mar 6, 2024
Merged

T345056: dark mode #186

merged 13 commits into from Mar 6, 2024

Conversation

medied
Copy link
Contributor

@medied medied commented Feb 22, 2024

https://phabricator.wikimedia.org/T345056

Demo: https://wikimedia.github.io/wikipedia-preview/T345056-dark-mode/

This the first step for supporting dark mode in the Wordpress plugin: the dark mode feature will be native to the core library and the plugin requests it as necessary. I've made the spanish demo page an example with the dark view, for simplicity.

@medied medied marked this pull request as ready for review February 23, 2024 18:34
style/preview.less Outdated Show resolved Hide resolved
@stephanebisson
Copy link
Collaborator

There are several "line too long" warnings that should be addressed here.

@hueitan
Copy link
Member

hueitan commented Feb 29, 2024

loading state, can we make cta bar not invert?
image

.wikipediapreview-header-closebtn {
filter: unset;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Some of the duplication with less mixins could be avoided with CSS custom properties (are they okay to use in this project?). Example:

/* Define default light theme custom properties */
:root {
  --background-color: #ffffff;
  --text-color: #000000;
}

/* Override custom properties for dark theme based on media query preference */
@media (prefers-color-scheme: dark) {
  :root {
    --background-color: #000000;
    --text-color: #ffffff;
  }
}

/* Explicit class for light theme */
.light-theme {
  --background-color: #ffffff;
  --text-color: #000000;
}

/* Explicit class for dark theme */
.dark-theme {
  --background-color: #000000;
  --text-color: #ffffff;
}

/* Use custom properties */
body {
  background-color: var(--background-color);
  color: var(--text-color);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see why it wouldn't be okay to use them, I refactored to use CSS custom properties and indeed it seems a bit cleaner (this way seems to be more of a standard - https://web.dev/articles/prefers-color-scheme#stylesheet_architecture), thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

:root represent the whole document, probably the <html> or <body> tag. It's important to remember that this is a small component hosted within any website. If we want to use an approach like that, everything has to be prefixed so that even if it bleeds into the host, it has no side effects on it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

LESS variables would probably give you a similar coding style but with actual isolation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that's a good point, I can update using LESS variables and maybe prefix it anyway as something like --wikipediapreview-primary-background-color

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving it with prefixes for now, let's make a decision next week

Copy link
Member

Choose a reason for hiding this comment

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

this looks good now i think, but can we still use mixin() here so we don't repeat the --var settings?

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to repeat the styles for the "light" variants? Aren't those the defaults?

Copy link
Member

Choose a reason for hiding this comment

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

can we also write in README to explain how the site owner custom their dark mode styling?

custom code like this, and explain what's the var there

@media (prefers-color-scheme: dark) {
	.wikipediapreview {
		--wikipediapreview-primary-background-color: #202122;
	        --wikipediapreview-secondary-background-color: #202122;
		--wikipediapreview-primary-color: #eaecf0;
		--wikipediapreview-filter-setting: invert(1);
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great feedback all, thanks

README.md Show resolved Hide resolved
README.md Outdated
@media (prefers-color-scheme: dark) {
.wikipediapreview {
--wikipediapreview-primary-background-color: #202122;
--wikipediapreview-secondary-background-color: #202122;
Copy link
Member

Choose a reason for hiding this comment

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

indent

README.md Show resolved Hide resolved
@hueitan hueitan merged commit 24586e5 into main Mar 6, 2024
2 checks passed
@hueitan hueitan deleted the T345056-dark-mode branch March 6, 2024 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants