@@ -7,14 +7,19 @@ import {
7
7
internalProperty ,
8
8
TemplateResult ,
9
9
html ,
10
+ query ,
10
11
} from 'lit-element' ;
11
12
import { get , translate } from 'lit-translate' ;
12
13
13
14
import '@material/mwc-button' ;
14
15
import '@material/mwc-dialog' ;
16
+ import '@material/mwc-icon-button' ;
15
17
import '@material/mwc-icon-button-toggle' ;
18
+ import '@material/mwc-menu' ;
16
19
import { Dialog } from '@material/mwc-dialog' ;
20
+ import { IconButton } from '@material/mwc-icon-button' ;
17
21
import { List } from '@material/mwc-list' ;
22
+ import { Menu } from '@material/mwc-menu' ;
18
23
19
24
import 'ace-custom-element' ;
20
25
import {
@@ -31,6 +36,8 @@ import {
31
36
Delete ,
32
37
Create ,
33
38
identity ,
39
+ WizardMenuActor ,
40
+ newSubWizardEvent ,
34
41
} from './foundation.js' ;
35
42
36
43
function dialogInputs ( dialog ?: Dialog ) : WizardInput [ ] {
@@ -84,10 +91,10 @@ export class WizardDialog extends LitElement {
84
91
@internalProperty ( )
85
92
pageIndex = 0 ;
86
93
87
- @queryAll ( 'mwc-dialog' )
88
- dialogs ! : NodeListOf < Dialog > ;
89
- @queryAll ( wizardInputSelector )
90
- inputs ! : NodeListOf < WizardInput > ;
94
+ @queryAll ( 'mwc-dialog' ) dialogs ! : NodeListOf < Dialog > ;
95
+ @ queryAll ( wizardInputSelector ) inputs ! : NodeListOf < WizardInput > ;
96
+ @query ( '.actions-menu' ) actionsMenu ! : Menu ;
97
+ @ query ( 'mwc-icon-button[icon="more_vert"]' ) menuButton ! : IconButton ;
91
98
92
99
/** The `Dialog` showing the active [[`WizardPage`]]. */
93
100
get dialog ( ) : Dialog | undefined {
@@ -150,6 +157,20 @@ export class WizardDialog extends LitElement {
150
157
return true ;
151
158
}
152
159
160
+ /** Triggers sub-wizard or editor-action with valid manu action */
161
+ async menuAct ( action ?: WizardMenuActor ) : Promise < boolean > {
162
+ if ( ! action ) return false ;
163
+
164
+ const wizardActions = action ( ) ;
165
+
166
+ wizardActions . forEach ( wa =>
167
+ isWizardFactory ( wa )
168
+ ? this . dispatchEvent ( newSubWizardEvent ( wa ) )
169
+ : this . dispatchEvent ( newActionEvent ( wa ) )
170
+ ) ;
171
+ return true ;
172
+ }
173
+
153
174
private onClosed ( ae : CustomEvent < { action : string } | null > ) : void {
154
175
if ( ! ( ae . target instanceof Dialog && ae . detail ?. action ) ) return ;
155
176
if ( ae . detail . action === 'close' ) this . dispatchEvent ( newWizardEvent ( ) ) ;
@@ -181,21 +202,60 @@ export class WizardDialog extends LitElement {
181
202
this . act ( this . wizard [ this . pageIndex ] . primary ! . action )
182
203
) ;
183
204
}
205
+
206
+ if ( this . actionsMenu )
207
+ this . actionsMenu . anchor = < HTMLElement > this . menuButton ;
208
+ }
209
+
210
+ renderMenu ( page : WizardPage ) : TemplateResult {
211
+ const someIconsDefined = page . menuActions ?. some (
212
+ menuAction => menuAction . icon
213
+ ) ;
214
+
215
+ return html ` <mwc- icon- butto n
216
+ icon= "more_vert"
217
+ @click = ${ ( ) => {
218
+ if ( ! this . actionsMenu . open ) this . actionsMenu . show ( ) ;
219
+ else this . actionsMenu . close ( ) ;
220
+ } }
221
+ > </ mwc- icon- butto n>
222
+ <mwc- menu class= "actions-menu" corner = "BOTTOM_RIGHT" menuCorner = "END" >
223
+ ${ page . menuActions ! . map (
224
+ menuAction =>
225
+ html `<mwc- lis t- item
226
+ .graphic = ${ someIconsDefined ? 'icon' : null }
227
+ @click = ${ ( ) => this . menuAct ( menuAction . action ) }
228
+ >
229
+ <span> ${ menuAction . label } </ span>
230
+ ${ menuAction . icon
231
+ ? html `<mwc- icon slot= "graphic" > ${ menuAction . icon } </ mwc- icon> `
232
+ : html `` }
233
+ </ mwc- lis t- item> `
234
+ ) }
235
+ </ mwc- menu> ` ;
184
236
}
185
237
186
238
renderPage ( page : WizardPage , index : number ) : TemplateResult {
239
+ const showCodeToggleButton =
240
+ page . element && localStorage . getItem ( 'mode' ) === 'pro' ;
241
+
187
242
return html `<mwc- dialog
188
243
defaultAction= "close"
189
244
?open= ${ index === this . pageIndex }
190
245
heading= ${ page . title }
191
246
@closed = ${ this . onClosed }
192
247
>
193
- ${ page . element && localStorage . getItem ( 'mode' ) === 'pro'
194
- ? html `<mwc- icon- butto n- to ggle
195
- onicon= "code"
196
- officon = "code_off"
197
- @click = ${ ( ) => this . requestUpdate ( ) }
198
- > </ mwc- icon- butto n- to ggle> `
248
+ ${ showCodeToggleButton || page . menuActions
249
+ ? html `<nav>
250
+ ${ showCodeToggleButton
251
+ ? html `<mwc- icon- butto n- to ggle
252
+ onicon= "code"
253
+ officon = "code_off"
254
+ @click = ${ ( ) => this . requestUpdate ( ) }
255
+ > </ mwc- icon- butto n- to ggle> `
256
+ : '' }
257
+ ${ page . menuActions ? this . renderMenu ( page ) : '' }
258
+ </ nav> `
199
259
: '' }
200
260
<div id= "wizard-content" >
201
261
${ this . code && page . element
@@ -270,14 +330,14 @@ export class WizardDialog extends LitElement {
270
330
--mdc-dialog-max-width : 92vw ;
271
331
}
272
332
273
- mwc-dialog > mwc-icon-button-toggle {
333
+ mwc-dialog > nav {
274
334
position : absolute;
275
335
top : 8px ;
276
336
right : 14px ;
277
337
color : var (--base00 );
278
338
}
279
339
280
- mwc-dialog > mwc-icon-button-toggle [on ] {
340
+ mwc-dialog > nav > mwc-icon-button-toggle [on ] {
281
341
color : var (--mdc-theme-primary );
282
342
}
283
343
0 commit comments