@@ -4,68 +4,29 @@ import { css } from '@emotion/core';
4
4
import {
5
5
CookieConsentDialog ,
6
6
GlobalHeader ,
7
- GlobalFooter ,
7
+ Layout ,
8
+ Logo ,
9
+ SearchInput ,
8
10
} from '@newrelic/gatsby-theme-newrelic' ;
9
- import { graphql , useStaticQuery } from 'gatsby' ;
10
11
import MobileHeader from '../components/MobileHeader' ;
11
- import Sidebar from '../components/Sidebar' ;
12
+ import { Link } from 'gatsby' ;
13
+ import Navigation from '../components/Navigation' ;
12
14
import '../components/styles.scss' ;
13
- import usePageContext from '../hooks/usePageContext' ;
14
15
import { useLocation } from '@reach/router' ;
15
- import { useMeasure } from 'react-use' ;
16
-
17
- const MainLayout = ( { children } ) => {
18
- const {
19
- site : { layout, siteMetadata } ,
20
- } = useStaticQuery ( graphql `
21
- query {
22
- site {
23
- layout {
24
- contentPadding
25
- maxWidth
26
- }
27
- siteMetadata {
28
- repository
29
- }
30
- }
31
- }
32
- ` ) ;
33
16
17
+ const MainLayout = ( { children, pageContext } ) => {
34
18
const location = useLocation ( ) ;
35
- const { fileRelativePath } = usePageContext ( ) ;
36
- const [ headerRef , { height } ] = useMeasure ( ) ;
19
+ const [ searchTerm , setSearchTerm ] = useState ( '' ) ;
20
+ const { fileRelativePath } = pageContext ;
37
21
const [ isMobileNavOpen , setIsMobileNavOpen ] = useState ( false ) ;
38
- const isComponentDoc = fileRelativePath . includes (
39
- 'src/markdown-pages/components'
40
- ) ;
41
- const editUrl = isComponentDoc
42
- ? null
43
- : `${ siteMetadata . repository } /blob/main/${ fileRelativePath } ` ;
44
22
45
23
useEffect ( ( ) => {
46
24
setIsMobileNavOpen ( false ) ;
47
25
} , [ location . pathname ] ) ;
48
26
49
27
return (
50
- < div
51
- css = { css `
52
- --sidebar-width : 300px ;
53
-
54
- min-height : 100vh ;
55
- display : grid;
56
- grid-template-rows : auto 1fr ;
57
- ` }
58
- >
59
- < div
60
- ref = { headerRef }
61
- css = { css `
62
- position : sticky;
63
- z-index : 99 ;
64
- top : 0 ;
65
- ` }
66
- >
67
- < GlobalHeader editUrl = { editUrl } />
68
- </ div >
28
+ < >
29
+ < GlobalHeader />
69
30
< MobileHeader
70
31
css = { css `
71
32
@media (min-width : 761px ) {
@@ -75,70 +36,60 @@ const MainLayout = ({ children }) => {
75
36
isOpen = { isMobileNavOpen }
76
37
toggle = { ( ) => setIsMobileNavOpen ( ! isMobileNavOpen ) }
77
38
/>
78
- < div
39
+ < Layout
79
40
css = { css `
80
- --global-header-height : ${ height } px;
81
-
82
41
display : ${ isMobileNavOpen ? 'none' : 'grid' } ;
83
- grid-template-areas :
84
- 'sidebar content'
85
- 'sidebar footer' ;
86
- grid-template-columns : var (--sidebar-width ) minmax (0 , 1fr );
87
- grid-template-rows : 1fr auto;
88
- grid-gap : ${ layout . contentPadding } ;
89
- width : 100% ;
90
- max-width : ${ layout . maxWidth } ;
91
- margin : 0 auto;
92
-
93
- @media screen and (max-width : 760px ) {
94
- grid-template-columns : minmax (0 , 1fr );
95
- }
96
42
` }
97
43
>
98
- < Sidebar
99
- css = { css `
100
- position : fixed;
101
- top : var (--global-header-height );
102
- width : var (--sidebar-width );
103
- height : calc (100vh - var (--global-header-height ));
104
- overflow : auto;
44
+ < Layout . Sidebar >
45
+ < div
46
+ css = { css `
47
+ background : var (--primary-background-color );
48
+ position : sticky;
49
+ top : -2rem ;
50
+ z-index : 10 ;
51
+ margin : -2rem -0.5rem 1rem ;
52
+ padding : 1rem 0.5rem ;
53
+ ` }
54
+ >
55
+ < Link
56
+ css = { css `
57
+ display : block;
58
+ margin-bottom : 1rem ;
59
+ ` }
60
+ to = "/"
61
+ >
62
+ < Logo
63
+ css = { css `
64
+ display : block;
65
+ width : 150px ;
105
66
106
- @media (max-width : 760px ) {
107
- display : none;
108
- }
109
- ` }
110
- />
111
- < div
112
- css = { css `
113
- grid-area : sidebar;
114
- ` }
115
- />
116
- < article
117
- data-swiftype-name = "body"
118
- data-swiftype-type = "text"
119
- css = { css `
120
- grid-area : content;
121
- padding-top : ${ layout . contentPadding } ;
122
- padding-right : ${ layout . contentPadding } ;
123
- ` }
124
- >
125
- { children }
126
- </ article >
127
- < GlobalFooter
128
- fileRelativePath = { fileRelativePath }
129
- css = { css `
130
- grid-area : footer;
131
- margin-left: - ${ layout . contentPadding } ;
132
- ` }
133
- />
134
- </ div >
67
+ @media screen and (max-width : 760px ) {
68
+ width : 160px ;
69
+ }
70
+ ` }
71
+ />
72
+ </ Link >
73
+ < SearchInput
74
+ placeholder = "Filter navigation"
75
+ onClear = { ( ) => setSearchTerm ( '' ) }
76
+ onChange = { ( e ) => setSearchTerm ( e . target . value ) }
77
+ value = { searchTerm }
78
+ />
79
+ </ div >
80
+ < Navigation searchTerm = { searchTerm } />
81
+ </ Layout . Sidebar >
82
+ < Layout . Main > { children } </ Layout . Main >
83
+ < Layout . Footer fileRelativePath = { fileRelativePath } />
84
+ </ Layout >
135
85
< CookieConsentDialog />
136
- </ div >
86
+ </ >
137
87
) ;
138
88
} ;
139
89
140
90
MainLayout . propTypes = {
141
91
children : PropTypes . node . isRequired ,
92
+ pageContext : PropTypes . object . isRequired ,
142
93
} ;
143
94
144
95
export default MainLayout ;
0 commit comments