1
1
'use client' ;
2
2
3
3
import { css , cx } from '@emotion/css' ;
4
- import React from 'react' ;
4
+ import React , {
5
+ Dispatch ,
6
+ PropsWithChildren ,
7
+ SetStateAction ,
8
+ useState ,
9
+ } from 'react' ;
5
10
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider' ;
6
11
import { color , spacing } from '@leafygreen-ui/tokens' ;
7
12
13
+ import {
14
+ DisplayMode ,
15
+ Drawer ,
16
+ DrawerStackProvider ,
17
+ } from '@leafygreen-ui/drawer' ;
18
+
8
19
import {
9
20
DarkModeToggle ,
10
21
Footer ,
@@ -13,9 +24,14 @@ import {
13
24
} from '@/components/global' ;
14
25
import { useMediaQuery } from '@/hooks' ;
15
26
import { SIDE_NAV_WIDTH } from '@/constants' ;
27
+ import IconButton from '@leafygreen-ui/icon-button' ;
28
+ import Icon from '@leafygreen-ui/icon' ;
29
+ import { ChatbotComponent } from '@/components/chatbot' ;
16
30
17
31
export default function Template ( { children } : { children : React . ReactNode } ) {
18
32
const { darkMode } = useDarkMode ( ) ;
33
+ const [ isDrawerOpen , setDrawerOpen ] = useState ( true ) ;
34
+
19
35
const [ isMobile ] = useMediaQuery ( [ '(max-width: 640px)' ] , {
20
36
fallback : [ false ] ,
21
37
} ) ;
@@ -31,41 +47,87 @@ export default function Template({ children }: { children: React.ReactNode }) {
31
47
: color . light . background . primary . default } ;
32
48
` }
33
49
>
34
- < SideNavigation />
50
+ < TempDrawerLayout open = { isDrawerOpen } setOpen = { setDrawerOpen } >
51
+ < SideNavigation />
35
52
36
- < div
37
- className = { css `
38
- width : 100% ;
39
- padding-top : ${ spacing [ 400 ] } px;
40
- padding-right : ${ spacing [ 400 ] } px;
41
- display : flex;
42
- justify-content : flex-end;
43
- gap : ${ spacing [ 150 ] } px;
44
- position : absolute;
45
- top : 0 ;
46
- right : 0 ;
47
- ` }
48
- >
49
- < UserMenu / >
50
- < DarkModeToggle />
51
- </ div >
53
+ < div
54
+ className = { css `
55
+ width : 100% ;
56
+ padding-top : ${ spacing [ 400 ] } px;
57
+ padding-right : ${ spacing [ 400 ] } px;
58
+ display : flex;
59
+ justify-content : flex-end;
60
+ gap : ${ spacing [ 150 ] } px;
61
+ ` }
62
+ >
63
+ < UserMenu />
64
+ < IconButton onClick = { ( ) => setDrawerOpen ( ! isDrawerOpen ) } >
65
+ < Icon glyph = "Sparkle" / >
66
+ </ IconButton >
67
+ < DarkModeToggle />
68
+ </ div >
52
69
53
- < div
54
- className = { cx (
55
- css `
56
- height : 100% ;
57
- margin-left : ${ isMobile
58
- ? 0
59
- : `${ SIDE_NAV_WIDTH } px` } ; // SideNav override}))}
60
- padding-left : ${ spacing [ 1000 ] } px;
61
- padding-right : ${ spacing [ 1000 ] } px;
62
- padding-top : ${ spacing [ 1600 ] } px;
63
- ` ,
64
- ) }
65
- >
66
- { children }
67
- < Footer />
68
- </ div >
70
+ < div
71
+ className = { cx (
72
+ css `
73
+ height : 100% ;
74
+ margin-left : ${ isMobile
75
+ ? 0
76
+ : `${ SIDE_NAV_WIDTH } px` } ; // SideNav override}))}
77
+ padding-left : ${ spacing [ 1000 ] } px;
78
+ padding-right : ${ spacing [ 1000 ] } px;
79
+ padding-top : ${ spacing [ 1600 ] } px;
80
+ ` ,
81
+ ) }
82
+ >
83
+ { children }
84
+ < Footer />
85
+ </ div >
86
+ </ TempDrawerLayout >
69
87
</ div >
70
88
) ;
71
89
}
90
+
91
+ /**
92
+ * Temporary Drawer Layout component.
93
+ * To be removed when the next major Drawer version is ready.
94
+ */
95
+ const TempDrawerLayout = ( {
96
+ children,
97
+ open,
98
+ setOpen,
99
+ } : PropsWithChildren < {
100
+ open : boolean ;
101
+ setOpen : Dispatch < SetStateAction < boolean > > ;
102
+ } > ) => {
103
+ return (
104
+ < div
105
+ className = { cx (
106
+ css `
107
+ width : 100% ;
108
+ display : grid;
109
+ grid-template-columns : auto 0 ;
110
+ transition : grid-template-columns 0.2s ease-in-out;
111
+ ` ,
112
+ {
113
+ [ css `
114
+ grid-template-columns : auto 384px ;
115
+ ` ] : open ,
116
+ } ,
117
+ ) }
118
+ >
119
+ < div > { children } </ div >
120
+
121
+ < DrawerStackProvider >
122
+ < Drawer
123
+ open = { open }
124
+ onClose = { ( ) => setOpen ( false ) }
125
+ title = "LeafyGreen AI"
126
+ displayMode = { DisplayMode . Embedded }
127
+ >
128
+ < ChatbotComponent />
129
+ </ Drawer >
130
+ </ DrawerStackProvider >
131
+ </ div >
132
+ ) ;
133
+ } ;
0 commit comments