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
docs: fix no-js dark theme bugs #18071
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
@media (prefers-color-scheme: dark) { | ||
.no-js { | ||
pre[class*="language-"] { | ||
color: var(--color-neutral-100); | ||
} | ||
|
||
.token { | ||
&.comment, | ||
.prolog, | ||
.doctype, | ||
.cdata { | ||
color: #8e9fae; | ||
} | ||
} | ||
|
||
.logo-component { | ||
fill: #fff; | ||
} | ||
|
||
#logo-center { | ||
opacity: 0.6; | ||
} | ||
|
||
.rule__categories, | ||
.rule__status { | ||
background: var(--body-background-color); | ||
} | ||
|
||
.alert { | ||
&.alert--warning { | ||
color: var(--color-rose-300); | ||
background-color: var(--color-rose-900); | ||
border: 1px solid var(--color-rose-300); | ||
|
||
.alert__type { | ||
color: var(--color-rose-200); | ||
} | ||
} | ||
|
||
&.alert--important { | ||
color: var(--color-warning-300); | ||
background-color: var(--color-warning-900); | ||
border: 1px solid var(--color-warning-300); | ||
|
||
.alert__type { | ||
color: var(--color-warning-200); | ||
} | ||
} | ||
|
||
&.alert--tip { | ||
color: var(--color-success-300); | ||
background-color: var(--color-success-900); | ||
border: 1px solid var(--color-success-300); | ||
|
||
.alert__type { | ||
color: var(--color-success-200); | ||
} | ||
} | ||
} | ||
|
||
.alert__type, | ||
.alert__learn-more { | ||
.alert--warning & { | ||
color: var(--color-rose-200); | ||
} | ||
|
||
.alert--important & { | ||
color: var(--color-warning-200); | ||
} | ||
|
||
.alert--tip & { | ||
color: var(--color-success-200); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ | |
@import "carbon-ads"; | ||
|
||
@import "utilities"; | ||
|
||
@import "no-js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Refactor] This adds in a new set of styles that only get hit in dark mode, and may only be tested in production by users with JavaScript disabled. Even if many users are visiting the site with JS disabled, that's still an extra source of truth for these comments. IMO it's not great having an additional (so, at least 2 total) place to manage these styles.
Instead, would it be feasible to figure out why some of the existing styles aren't loading in? E.g. if dark-mode-only styles are only loaded by JS, maybe they can be loaded in with pure HTML/CSS instead?
Sorry if I missed a previous explanation. I looked through the past PR comments and didn't see anything. I also filed #18076 for tracking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback and suggestion Yes, you are correct this added a new set of styles that are only used when js is disabled and the preferred theme is dark.
An additional place to these styles I am getting it?
do you mean a new file specifically for handling no-js mode?Instead, would it be feasible to figure out why some of the existing styles aren't loading in? E.g. if dark-mode-only styles are only loaded by JS, maybe they can be loaded in with pure HTML/CSS instead?
There is no existing style targeting drak mode with js disabled which is why it falls back to default styles. The styles that are not applied are related to JS.
For example:
let's take the ESLint logo - it is an SVG element. The default style works well in light mode.
eslint/docs/src/_includes/components/logo.html
Lines 11 to 20 in aadfb60
For the dark mode styles specified explicitly based on the data-theme attribute (which gets added based on the user choice)
eslint/docs/src/_includes/components/logo.html
Lines 2 to 10 in aadfb60
If JavaScript is turned off and the chosen theme is light, there is no problem as the default logo functions correctly. However, when the preferred mode is dark, the absence of styles for this scenario results in a fallback to the light mode style, leading to the issue. To resolve this, I have specifically included styles that target the dark theme when JavaScript is disabled.
Additionally, let's examine the behaviour of various elements in a dark theme when JavaScript is disabled. The code block background colour toggles flawlessly between dark and light modes even without JavaScript, Because property value is not hard-coded
eslint/docs/src/assets/scss/syntax-highlighter.scss
Lines 48 to 50 in b844324
Variable
--lightest-background-color
value is toggled based on the themelight theme:
eslint/docs/src/assets/scss/tokens/themes.scss
Line 129 in b844324
dark theme:
eslint/docs/src/assets/scss/tokens/themes.scss
Line 152 in b844324
preferred theme dark and js disabled:
eslint/docs/src/assets/scss/tokens/themes.scss
Line 108 in b844324
Preferred them light and js disabled:
eslint/docs/src/assets/scss/tokens/themes.scss
Line 87 in b844324
Using variables we can solve this issue. Refer: #18077
I believe this provides clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, thanks! +1 to #18077's approach, I'll approve over there.