File tree Expand file tree Collapse file tree 3 files changed +23
-5
lines changed
custom-implementation/src Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 1
1
.custom-header {
2
- background-color : white;
2
+ z-index : 60 ;
3
3
}
4
4
5
5
.custom-header nav a {
Original file line number Diff line number Diff line change 1
1
'use client'
2
2
3
+ import { useEffect , useState } from 'react'
3
4
import {
4
5
ComponentConfigContext ,
5
6
HeaderV30 as SharedHeader ,
@@ -11,10 +12,23 @@ const Header = ({
11
12
logo,
12
13
links,
13
14
actions,
14
- version,
15
15
collapseOnScroll = true ,
16
16
} : // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
17
any ) => {
18
+ const html = document . getElementsByTagName ( 'html' ) [ 0 ]
19
+ const [ theme , setTheme ] = useState ( html . getAttribute ( 'class' ) )
20
+ useEffect ( ( ) => {
21
+ const observer = new MutationObserver ( ( ) => {
22
+ setTheme ( html . getAttribute ( 'class' ) )
23
+ } )
24
+
25
+ const config = { attributes : true , attributeFilter : [ 'class' ] }
26
+ observer . observe ( html , config )
27
+ return ( ) => {
28
+ observer . disconnect ( )
29
+ }
30
+ } , [ html ] )
31
+
18
32
return (
19
33
< div >
20
34
< ComponentConfigContext . Provider
@@ -25,7 +39,7 @@ any) => {
25
39
logo = { logo }
26
40
items = { links }
27
41
actions = { actions }
28
- version = { version }
42
+ version = { theme === 'dark' ? 'light' : 'dark' }
29
43
collapseOnScroll = { collapseOnScroll }
30
44
wrapperClassName = "custom-header"
31
45
/>
Original file line number Diff line number Diff line change @@ -20,16 +20,20 @@ const render = async () => {
20
20
const sidenav = document . querySelector ( 'button.fern-search-bar' )
21
21
?. parentElement as HTMLElement
22
22
23
+ const theme = document . getElementsByTagName ( 'html' ) [ 0 ] . getAttribute ( 'class' )
24
+
23
25
if ( ! document . getElementById ( 'theme-switch' ) ) {
24
26
const wrapper = document . createElement ( 'div' )
25
27
wrapper . setAttribute ( 'id' , 'theme-switch' )
26
28
sidenav . appendChild ( wrapper )
27
-
28
29
ReactDOM . render ( React . createElement ( ThemeSwitch ) , wrapper )
29
30
}
30
31
31
32
ReactDOM . render (
32
- React . createElement ( Header , { ...data . header } ) ,
33
+ React . createElement ( Header , {
34
+ ...data . header ,
35
+ version : theme == 'dark' ? 'light' : 'dark' ,
36
+ } ) ,
33
37
document . getElementById ( 'fern-header' ) ,
34
38
( ) => {
35
39
// Once the header component is loaded, make it visible
You can’t perform that action at this time.
0 commit comments