@@ -22,18 +22,22 @@ export interface Props {
22
22
platform : ReturnType < typeof usePlatform > ;
23
23
}
24
24
25
+ interface AsideProps {
26
+ title : string | undefined ;
27
+ onClose ?: ( ) => void ;
28
+ children : ComponentChildren ;
29
+ }
30
+
25
31
const Aside = (
26
- { title, onClose, children } : {
27
- title : string ;
28
- onClose ?: ( ) => void ;
29
- children : ComponentChildren ;
30
- } ,
32
+ { title, onClose, children } : AsideProps ,
31
33
) => (
32
34
< div class = "bg-base-100 grid grid-rows-[auto_1fr] h-full divide-y max-w-[100vw]" >
33
35
< div class = "flex justify-between items-center" >
34
- < h1 class = "px-4 py-3" >
35
- < span class = "font-medium text-2xl" > { title } </ span >
36
- </ h1 >
36
+ { title && (
37
+ < h1 class = "px-4 py-3 font-medium text-2xl" >
38
+ { title }
39
+ </ h1 >
40
+ ) }
37
41
{ onClose && (
38
42
< Button class = "btn btn-ghost" onClick = { onClose } >
39
43
< Icon id = "XMark" size = { 24 } strokeWidth = { 2 } />
@@ -55,46 +59,109 @@ const Aside = (
55
59
function Drawers ( { menu, searchbar, children, platform } : Props ) {
56
60
const { displayCart, displayMenu, displaySearchDrawer } = useUI ( ) ;
57
61
62
+ const onClose = ( ) => {
63
+ displaySearchDrawer . value = false ;
64
+ displayMenu . value = false ;
65
+ displayCart . value = false ;
66
+ } ;
67
+
58
68
return (
59
- < Drawer // left drawer
60
- open = { displayMenu . value || displaySearchDrawer . value }
61
- onClose = { ( ) => {
62
- displayMenu . value = false ;
63
- displaySearchDrawer . value = false ;
64
- } }
65
- aside = {
66
- < Aside
67
- onClose = { ( ) => {
68
- displayMenu . value = false ;
69
- displaySearchDrawer . value = false ;
70
- } }
71
- title = { displayMenu . value ? "Menu" : "Buscar" }
72
- >
73
- { displayMenu . value && < Menu { ...menu } /> }
74
- { searchbar && displaySearchDrawer . value && (
75
- < div class = "w-screen" >
76
- < Searchbar { ...searchbar } />
69
+ < >
70
+ < Drawer // Search from Left
71
+ open = { displaySearchDrawer . value }
72
+ onClose = { onClose }
73
+ aside = {
74
+ < div class = "bg-base-100 grid grid-rows-[auto_1fr] h-full divide-y max-w-[100vw]" >
75
+ < div class = "flex justify-between items-center" >
76
+ < h1 class = "px-4 py-3 font-medium text-2xl" >
77
+ Buscar
78
+ </ h1 >
79
+ { onClose && (
80
+ < Button class = "btn btn-ghost" onClick = { onClose } >
81
+ < Icon id = "XMark" size = { 24 } strokeWidth = { 2 } />
82
+ </ Button >
83
+ ) }
77
84
</ div >
78
- ) }
79
- </ Aside >
80
- }
81
- >
82
- < Drawer // right drawer
85
+ < Suspense
86
+ fallback = {
87
+ < div class = "w-screen flex items-center justify-center" >
88
+ < span class = "loading loading-ring" />
89
+ </ div >
90
+ }
91
+ >
92
+ { searchbar && displaySearchDrawer . value && (
93
+ < div class = "w-screen" >
94
+ < Searchbar { ...searchbar } />
95
+ </ div >
96
+ ) }
97
+ </ Suspense >
98
+ </ div >
99
+ }
100
+ >
101
+ { children }
102
+ </ Drawer >
103
+
104
+ < Drawer // Menu from Left
105
+ open = { displayMenu . value }
106
+ onClose = { onClose }
107
+ aside = {
108
+ < div class = "bg-base-100 grid grid-rows-[auto_1fr] h-full divide-y max-w-[100vw]" >
109
+ < div class = "flex justify-between items-center" >
110
+ < h1 class = "px-4 py-3 font-medium text-2xl" >
111
+ Menu
112
+ </ h1 >
113
+ { onClose && (
114
+ < Button class = "btn btn-ghost" onClick = { onClose } >
115
+ < Icon id = "XMark" size = { 24 } strokeWidth = { 2 } />
116
+ </ Button >
117
+ ) }
118
+ </ div >
119
+ < Suspense
120
+ fallback = {
121
+ < div class = "w-screen flex items-center justify-center" >
122
+ < span class = "loading loading-ring" />
123
+ </ div >
124
+ }
125
+ >
126
+ { displayMenu . value && < Menu { ...menu } /> }
127
+ </ Suspense >
128
+ </ div >
129
+ }
130
+ >
131
+ { children }
132
+ </ Drawer >
133
+
134
+ < Drawer // Cart from Right
83
135
class = "drawer-end"
84
136
open = { displayCart . value !== false }
85
- onClose = { ( ) => displayCart . value = false }
137
+ onClose = { onClose }
86
138
aside = {
87
- < Aside
88
- title = "Minha sacola"
89
- onClose = { ( ) => displayCart . value = false }
90
- >
91
- < Cart platform = { platform } />
92
- </ Aside >
139
+ < div class = "bg-base-100 grid grid-rows-[auto_1fr] h-full divide-y max-w-[100vw]" >
140
+ < div class = "flex justify-between items-center" >
141
+ < h1 class = "px-4 py-3 font-medium text-2xl" >
142
+ Carrinho
143
+ </ h1 >
144
+ { onClose && (
145
+ < Button class = "btn btn-ghost" onClick = { onClose } >
146
+ < Icon id = "XMark" size = { 24 } strokeWidth = { 2 } />
147
+ </ Button >
148
+ ) }
149
+ </ div >
150
+ < Suspense
151
+ fallback = {
152
+ < div class = "w-screen flex items-center justify-center" >
153
+ < span class = "loading loading-ring" />
154
+ </ div >
155
+ }
156
+ >
157
+ < Cart platform = { platform } />
158
+ </ Suspense >
159
+ </ div >
93
160
}
94
161
>
95
162
{ children }
96
163
</ Drawer >
97
- </ Drawer >
164
+ </ >
98
165
) ;
99
166
}
100
167
0 commit comments