Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/generators/legacy-html/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,10 @@ kbd {
outline: var(--brand3) dotted 2px;
}

.theme-toggle-btn svg {
pointer-events: none;
}

@media only screen and (width >= 601px) {
#gtoc > ul > li {
display: inline;
Expand Down
1 change: 1 addition & 0 deletions src/generators/legacy-html/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<div class="header-container">
<h1>Node.js __VERSION__ documentation</h1>
<button
type="button"
class="theme-toggle-btn"
id="theme-toggle-btn"
title="Toggle dark mode/light mode"
Expand Down
7 changes: 2 additions & 5 deletions src/generators/web/ui/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Logo from '#theme/Logo';
* NavBar component that displays the headings, search, etc.
*/
export default () => {
const [theme, toggleTheme] = useTheme();
const [theme, changeTheme] = useTheme();

return (
<NavBar
Expand All @@ -22,10 +22,7 @@ export default () => {
navItems={[]}
>
<SearchBox />
<ThemeToggle
onClick={toggleTheme}
aria-label={`Switch to ${theme === 'light' ? 'dark' : 'light'} theme`}
/>
<ThemeToggle onChange={changeTheme} currentTheme={theme} />
<a
href={`https://github.com/${STATIC_DATA.repository}`}
aria-label={`${STATIC_DATA.title} GitHub`}
Expand Down
16 changes: 5 additions & 11 deletions src/generators/web/ui/hooks/useTheme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,12 @@ export const useTheme = () => {
}, []);

/**
* Callback function to toggle between 'light' and 'dark' themes.
* Callback function to change the theme.
*/
const toggleTheme = useCallback(() => {
setTheme(prev => {
// Determine the next theme based on the current theme.
const next = prev === 'light' ? 'dark' : 'light';
// Apply the new theme.
applyTheme(next);
// Return the new theme to update the state.
return next;
});
const changeTheme = useCallback(newTheme => {
setTheme(newTheme);
applyTheme(newTheme);
}, []);

return [theme, toggleTheme];
return [theme, changeTheme];
};
Loading