File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed
Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,11 @@ export default [
7474 } ,
7575 } ,
7676 {
77- files : [ 'src/generators/legacy-html/assets/*.js' ] ,
77+ files : [
78+ 'src/generators/legacy-html/assets/*.js' ,
79+ 'src/generators/web/hooks/*' ,
80+ 'src/generators/web/components/*' ,
81+ ] ,
7882 languageOptions : { globals : { ...globals . browser } } ,
7983 } ,
8084] ;
Original file line number Diff line number Diff line change 11import NavBar from '@node-core/ui-components/Containers/NavBar' ;
22import NodejsLogo from '@node-core/ui-components/Common/NodejsLogo' ;
3+ import ThemeToggle from '@node-core/ui-components/Common/ThemeToggle' ;
4+
5+ import { useTheme } from '../hooks/useTheme.mjs' ;
36
47const MDXNavBar = ( ) => {
8+ const [ theme , toggleTheme ] = useTheme ( ) ;
9+
510 return (
611 < NavBar
712 pathname = "/docs/latest/api/"
@@ -40,7 +45,10 @@ const MDXNavBar = () => {
4045 } ,
4146 ] }
4247 >
43- < p > some child</ p >
48+ < ThemeToggle
49+ onClick = { toggleTheme }
50+ aria-label = { `Switch to ${ theme === 'light' ? 'dark' : 'light' } theme` }
51+ />
4452 </ NavBar >
4553 ) ;
4654} ;
Original file line number Diff line number Diff line change 1+ import { useState , useEffect } from 'react' ;
2+
3+ /**
4+ * This hook provides theme management functionality
5+ */
6+ export const useTheme = ( ) => {
7+ const [ theme , setTheme ] = useState ( 'light' ) ;
8+
9+ useEffect ( ( ) => {
10+ // Get initial theme from HTML or fallback to system preference
11+ const htmlElement = document . documentElement ;
12+ const currentTheme = htmlElement . getAttribute ( 'data-theme' ) ;
13+
14+ const initialTheme =
15+ currentTheme ||
16+ localStorage . getItem ( 'theme' ) ||
17+ ( window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches
18+ ? 'dark'
19+ : 'light' ) ;
20+
21+ setTheme ( initialTheme ) ;
22+ htmlElement . setAttribute ( 'data-theme' , initialTheme ) ;
23+ } , [ ] ) ;
24+
25+ /**
26+ * Toggles the theme between 'light' and 'dark'.
27+ */
28+ const toggleTheme = ( ) => {
29+ const newTheme = theme === 'light' ? 'dark' : 'light' ;
30+ setTheme ( newTheme ) ;
31+ document . documentElement . setAttribute ( 'data-theme' , newTheme ) ;
32+ localStorage . setItem ( 'theme' , newTheme ) ;
33+ } ;
34+
35+ return [ theme , toggleTheme ] ;
36+ } ;
You can’t perform that action at this time.
0 commit comments