1- import { Box , CodeStyle , Container , ThemeProvider } from '@committed/components'
1+ import {
2+ Box ,
3+ CodeStyle ,
4+ Container ,
5+ ThemeProvider ,
6+ useThemeChoice ,
7+ fonts ,
8+ } from '@committed/components'
29import { Content , Header as LayoutHeader , Nav , Root } from '@committed/layout'
310import { navigate } from 'gatsby'
411import React , { Dispatch , ReactNode , useState } from 'react'
@@ -36,16 +43,22 @@ export const Layout = ({
3643 ...props
3744} : LayoutProps ) => {
3845 const [ collapsed , setCollapsed ] = useState ( ( location && location . state ) || { } )
39- useHotkeys ( 'shift+home' , ( ) => navigate ( '/' ) )
40- useHotkeys ( 'shift+p' , ( ) => navigate ( '/print' ) )
46+ const [ themeChoice , toggleThemeChoice , componentMounted ] = useThemeChoice ( )
47+
48+ useHotkeys ( 'shift+home' , ( ) => {
49+ navigate ( '/' )
50+ } )
51+ useHotkeys ( 'shift+p' , ( ) => {
52+ navigate ( '/print' )
53+ } )
4154
4255 const navigateTo = ( url ) => {
4356 navigate ( url , {
4457 state : collapsed ,
4558 } )
4659 }
4760
48- return (
61+ const component = componentMounted ? (
4962 < DocsContext . Provider
5063 value = { {
5164 pathname : location . pathname ,
@@ -55,7 +68,9 @@ export const Layout = ({
5568 } }
5669 >
5770 < ThemeProvider
58- fonts = { {
71+ choice = { themeChoice }
72+ createFonts = { ( ) => ( {
73+ ...fonts . defaultFonts ,
5974 display : {
6075 fontFamily :
6176 'Dosis, "Helvetica Neue", "Segoe UI", Helvetica, Arial, sans-serif' ,
@@ -65,27 +80,35 @@ export const Layout = ({
6580 fontFamily :
6681 'Lato, -apple-system, BlinkMacSystemFont, "San Francisco", Roboto, "Segoe UI", "Helvetica Neue"' ,
6782 } ,
68- } }
83+ } ) }
6984 >
7085 { pageContext . current && pageContext . current . title && (
7186 < SEO title = { pageContext . current . title } { ...props } />
7287 ) }
7388 < Root
74- style = { { minHeight : '100vh' } }
7589 config = { {
7690 collapsible : false ,
91+ navVariant : {
92+ xs : 'temporary' ,
93+ sm : 'permanent' ,
94+ } ,
95+ headerResponse : {
96+ xs : 'static' ,
97+ sm : 'squeezed' ,
98+ } ,
99+ contentResponse : {
100+ xs : 'static' ,
101+ sm : 'squeezed' ,
102+ } ,
77103 } }
78104 >
79105 < LayoutHeader >
80- < Header />
106+ < Header
107+ themeChoice = { themeChoice }
108+ toggleThemeChoice = { toggleThemeChoice }
109+ />
81110 </ LayoutHeader >
82- < Nav
83- header = {
84- // you can provide fixed header inside nav
85- // change null to some react element
86- ( ctx ) => null
87- }
88- >
111+ < Nav >
89112 < Sidebar location = { location } current = { id } />
90113 </ Nav >
91114 < Content >
@@ -105,5 +128,6 @@ export const Layout = ({
105128 </ Root >
106129 </ ThemeProvider >
107130 </ DocsContext . Provider >
108- )
131+ ) : null
132+ return component
109133}
0 commit comments