-
Notifications
You must be signed in to change notification settings - Fork 61
fix(react): reflect system theme in toggle icon #1013
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@nodejs/doc-kit-generator-react': patch | ||
| --- | ||
|
|
||
| Show the active light or dark theme icon when the system preference is selected. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { describe, it } from 'node:test'; | ||
|
|
||
| import { getDisplayedTheme } from '../theme.mjs'; | ||
|
|
||
| describe('getDisplayedTheme', () => { | ||
| it('uses the resolved system scheme for the initial system preference', () => { | ||
| assert.strictEqual(getDisplayedTheme('system', true), 'dark'); | ||
| assert.strictEqual(getDisplayedTheme('system', false), 'light'); | ||
| }); | ||
|
|
||
| it('preserves explicit user preferences', () => { | ||
| assert.strictEqual(getDisplayedTheme('dark', false), 'dark'); | ||
| assert.strictEqual(getDisplayedTheme('light', true), 'light'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * Resolves the theme preference that should be represented by the toggle icon. | ||
| * | ||
| * The selector still stores `system` as the user preference, but its trigger | ||
| * should show the light or dark icon that is currently applied to the page. | ||
| * | ||
| * @param {'system'|'light'|'dark'} preference - The stored theme preference. | ||
| * @param {boolean} systemSupportsDarkMode - Whether the OS currently prefers dark mode. | ||
| * @returns {'light'|'dark'} The theme currently displayed by the page. | ||
| */ | ||
| export const getDisplayedTheme = (preference, systemSupportsDarkMode) => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a react hook. |
||
| if (preference === 'system') { | ||
| return systemSupportsDarkMode ? 'dark' : 'light'; | ||
| } | ||
|
|
||
| return preference; | ||
| }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @avivkeller I'm fairly sure this can be done on ui-components side? I thought this was done over there already, wondering if a change here is really needed. TRhe solution also doesn feel elegant... |
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 seems like an unrelate rename.