@@ -2,6 +2,7 @@ import { Icon } from '@teambit/evangelist.elements.icon';
2
2
import classNames from 'classnames' ;
3
3
import { useSearchParams } from 'react-router-dom' ;
4
4
import React , { useCallback , useEffect , useState } from 'react' ;
5
+ import { DrawerUI } from '@teambit/ui-foundation.ui.tree.drawer' ;
5
6
import { MenuWidgetIcon } from '@teambit/ui-foundation.ui.menu-widget-icon' ;
6
7
import { Tooltip } from '@teambit/design.ui.tooltip' ;
7
8
import { useNavigate , useLocation } from '@teambit/base-react.navigation.link' ;
@@ -48,6 +49,17 @@ export function CompositionsPanel({
48
49
className,
49
50
...rest
50
51
} : CompositionsPanelProps ) {
52
+ // setup drawer state
53
+ const [ openDrawerList , onToggleDrawer ] = useState ( [ 'COMPOSITIONS' , 'LIVE_CONTROLS' ] ) ;
54
+ const handleDrawerToggle = ( id : string ) => {
55
+ const isDrawerOpen = openDrawerList . includes ( id ) ;
56
+ if ( isDrawerOpen ) {
57
+ onToggleDrawer ( ( list ) => list . filter ( ( drawer ) => drawer !== id ) ) ;
58
+ return ;
59
+ }
60
+ onToggleDrawer ( ( list ) => list . concat ( id ) ) ;
61
+ } ;
62
+
51
63
// setup from props
52
64
const shouldAddNameParam = useNameParam || ( isScaling && includesEnvTemplate === false ) ;
53
65
@@ -124,41 +136,57 @@ export function CompositionsPanel({
124
136
) ;
125
137
126
138
return (
127
- < div >
128
- < ul { ...rest } className = { classNames ( className ) } >
129
- { compositions . map ( ( composition ) => {
130
- const href = shouldAddNameParam
131
- ? `${ url } &name=${ composition . identifier } `
132
- : `${ url } &${ composition . identifier } ` ;
133
- return (
134
- < li
135
- key = { composition . identifier }
136
- className = { classNames ( styles . linkWrapper , composition === active && styles . active ) }
137
- >
138
- < a className = { styles . panelLink } onClick = { ( ) => handleSelect ( composition ) } >
139
- < span className = { styles . box } > </ span >
140
- < span className = { styles . name } > { composition . displayName } </ span >
141
- </ a >
142
- < div className = { styles . right } >
143
- < MenuWidgetIcon
144
- className = { styles . codeLink }
145
- icon = "Code"
146
- tooltipContent = "Code"
147
- onClick = { onCompositionCodeClicked ( composition ) }
148
- />
149
- < Tooltip content = "Open in new tab" placement = "bottom" >
150
- < a className = { styles . panelLink } target = "_blank" rel = "noopener noreferrer" href = { href } >
151
- < Icon className = { styles . icon } of = "open-tab" />
152
- </ a >
153
- </ Tooltip >
154
- </ div >
155
- </ li >
156
- ) ;
157
- } ) }
158
- </ ul >
159
- { controlsTimestamp && (
160
- < LiveControls defs = { controlsDefs } values = { consolesValues } onChange = { onLiveControlsUpdate } />
161
- ) }
139
+ < div className = { classNames ( styles . container ) } >
140
+ < DrawerUI
141
+ isOpen = { openDrawerList . includes ( 'COMPOSITIONS' ) }
142
+ onToggle = { ( ) => handleDrawerToggle ( 'COMPOSITIONS' ) }
143
+ name = "COMPOSITIONS"
144
+ className = { classNames ( styles . tab ) }
145
+ >
146
+ < ul { ...rest } className = { classNames ( className ) } >
147
+ { compositions . map ( ( composition ) => {
148
+ const href = shouldAddNameParam
149
+ ? `${ url } &name=${ composition . identifier } `
150
+ : `${ url } &${ composition . identifier } ` ;
151
+ return (
152
+ < li
153
+ key = { composition . identifier }
154
+ className = { classNames ( styles . linkWrapper , composition === active && styles . active ) }
155
+ >
156
+ < a className = { styles . panelLink } onClick = { ( ) => handleSelect ( composition ) } >
157
+ < span className = { styles . box } > </ span >
158
+ < span className = { styles . name } > { composition . displayName } </ span >
159
+ </ a >
160
+ < div className = { styles . right } >
161
+ < MenuWidgetIcon
162
+ className = { styles . codeLink }
163
+ icon = "Code"
164
+ tooltipContent = "Code"
165
+ onClick = { onCompositionCodeClicked ( composition ) }
166
+ />
167
+ < Tooltip content = "Open in new tab" placement = "bottom" >
168
+ < a className = { styles . panelLink } target = "_blank" rel = "noopener noreferrer" href = { href } >
169
+ < Icon className = { styles . icon } of = "open-tab" />
170
+ </ a >
171
+ </ Tooltip >
172
+ </ div >
173
+ </ li >
174
+ ) ;
175
+ } ) }
176
+ </ ul >
177
+ </ DrawerUI >
178
+ < DrawerUI
179
+ isOpen = { openDrawerList . includes ( 'LIVE_CONTROLS' ) }
180
+ onToggle = { ( ) => handleDrawerToggle ( 'LIVE_CONTROLS' ) }
181
+ className = { classNames ( styles . tab ) }
182
+ name = "LIVE CONTROLS"
183
+ >
184
+ { controlsTimestamp ? (
185
+ < LiveControls defs = { controlsDefs } values = { consolesValues } onChange = { onLiveControlsUpdate } />
186
+ ) : (
187
+ < div className = { styles . noLiveControls } > No live controls available for this composition</ div >
188
+ ) }
189
+ </ DrawerUI >
162
190
</ div >
163
191
) ;
164
192
}
0 commit comments