@@ -9,14 +9,23 @@ import {
9
9
import {
10
10
FILEUPLOAD_BROWSE ,
11
11
FILEUPLOADER_TITLE ,
12
+ VALUE_STATE_SUCCESS ,
13
+ VALUE_STATE_INFORMATION ,
14
+ VALUE_STATE_ERROR ,
15
+ VALUE_STATE_WARNING ,
12
16
} from "./generated/i18n/i18n-defaults.js" ;
17
+
13
18
import Input from "./Input.js" ;
19
+ import Popover from "./Popover.js" ;
14
20
15
21
// Template
16
22
import FileUploaderTemplate from "./generated/templates/FileUploaderTemplate.lit.js" ;
23
+ import FileUploaderPopoverTemplate from "./generated/templates/FileUploaderPopoverTemplate.lit.js" ;
17
24
18
25
// Styles
19
26
import FileUploaderCss from "./generated/themes/FileUploader.css.js" ;
27
+ import ResponsivePopoverCommonCss from "./generated/themes/ResponsivePopoverCommon.css.js" ;
28
+ import ValueStateMessageCss from "./generated/themes/ValueStateMessage.css.js" ;
20
29
21
30
/**
22
31
* @public
@@ -128,6 +137,13 @@ const metadata = {
128
137
type : ValueState ,
129
138
defaultValue : ValueState . None ,
130
139
} ,
140
+
141
+ /**
142
+ * @private
143
+ */
144
+ focused : {
145
+ type : Boolean ,
146
+ } ,
131
147
} ,
132
148
managedSlots : true ,
133
149
slots : /** @lends sap.ui.webcomponents.main.FileUploader.prototype */ {
@@ -142,6 +158,23 @@ const metadata = {
142
158
propertyName : "content" ,
143
159
type : HTMLElement ,
144
160
} ,
161
+
162
+ /**
163
+ * Defines the value state message that will be displayed as pop up under the <code>ui5-file-uploader</code>.
164
+ * <br><br>
165
+ *
166
+ * <b>Note:</b> If not specified, a default text (in the respective language) will be displayed.
167
+ * <br>
168
+ * <b>Note:</b> The <code>valueStateMessage</code> would be displayed,
169
+ * when the <code>ui5--file-uploader</code> is in <code>Information</code>, <code>Warning</code> or <code>Error</code> value state.
170
+ * @type {HTMLElement[] }
171
+ * @since 1.0.0-rc.9
172
+ * @slot
173
+ * @public
174
+ */
175
+ valueStateMessage : {
176
+ type : HTMLElement ,
177
+ } ,
145
178
} ,
146
179
events : /** @lends sap.ui.webcomponents.main.FileUploader.prototype */ {
147
180
/**
@@ -209,6 +242,14 @@ class FileUploader extends UI5Element {
209
242
return FileUploaderTemplate ;
210
243
}
211
244
245
+ static get staticAreaTemplate ( ) {
246
+ return FileUploaderPopoverTemplate ;
247
+ }
248
+
249
+ static get staticAreaStyles ( ) {
250
+ return [ ResponsivePopoverCommonCss , ValueStateMessageCss ] ;
251
+ }
252
+
212
253
constructor ( ) {
213
254
super ( ) ;
214
255
if ( this . _canUseNativeFormSupport ) {
@@ -230,6 +271,14 @@ class FileUploader extends UI5Element {
230
271
} ) ;
231
272
}
232
273
274
+ _onfocusin ( ) {
275
+ this . focused = true ;
276
+ }
277
+
278
+ _onfocusout ( ) {
279
+ this . focused = false ;
280
+ }
281
+
233
282
/**
234
283
* FileList of all selected files.
235
284
* @readonly
@@ -252,6 +301,8 @@ class FileUploader extends UI5Element {
252
301
if ( ! this . value ) {
253
302
this . _input . value = "" ;
254
303
}
304
+
305
+ this . toggleValueStatePopover ( this . shouldOpenValueStateMessagePopover ) ;
255
306
}
256
307
257
308
_enableFormSupport ( ) {
@@ -297,6 +348,35 @@ class FileUploader extends UI5Element {
297
348
this . _internals . setFormValue ( formData ) ;
298
349
}
299
350
351
+ toggleValueStatePopover ( open ) {
352
+ if ( open ) {
353
+ this . openValueStatePopover ( ) ;
354
+ } else {
355
+ this . closeValueStatePopover ( ) ;
356
+ }
357
+ }
358
+
359
+ async openValueStatePopover ( ) {
360
+ const popover = await this . _getPopover ( ) ;
361
+
362
+ if ( popover ) {
363
+ popover . openBy ( this ) ;
364
+ }
365
+ }
366
+
367
+ async closeValueStatePopover ( ) {
368
+ const popover = await this . _getPopover ( ) ;
369
+
370
+ if ( popover ) {
371
+ popover . close ( ) ;
372
+ }
373
+ }
374
+
375
+ async _getPopover ( ) {
376
+ const staticAreaItem = await this . getStaticAreaItemDomRef ( ) ;
377
+ return staticAreaItem . querySelector ( ".ui5-valuestatemessage-popover" ) ;
378
+ }
379
+
300
380
/**
301
381
* in case when ui5-file-uploader is not placed in the DOM, return empty FileList, like native input would do
302
382
* @private
@@ -338,8 +418,67 @@ class FileUploader extends UI5Element {
338
418
return "file" ;
339
419
}
340
420
421
+ get valueStateTextMappings ( ) {
422
+ const i18nBundle = this . i18nBundle ;
423
+
424
+ return {
425
+ "Success" : i18nBundle . getText ( VALUE_STATE_SUCCESS ) ,
426
+ "Information" : i18nBundle . getText ( VALUE_STATE_INFORMATION ) ,
427
+ "Error" : i18nBundle . getText ( VALUE_STATE_ERROR ) ,
428
+ "Warning" : i18nBundle . getText ( VALUE_STATE_WARNING ) ,
429
+ } ;
430
+ }
431
+
432
+ get valueStateText ( ) {
433
+ return this . valueStateTextMappings [ this . valueState ] ;
434
+ }
435
+
436
+ get hasValueState ( ) {
437
+ return this . valueState !== ValueState . None ;
438
+ }
439
+
440
+ get hasValueStateText ( ) {
441
+ return this . hasValueState && this . valueState !== ValueState . Success ;
442
+ }
443
+
444
+ get valueStateMessageText ( ) {
445
+ return this . getSlottedNodes ( "valueStateMessage" ) . map ( el => el . cloneNode ( true ) ) ;
446
+ }
447
+
448
+ get shouldDisplayDefaultValueStateMessage ( ) {
449
+ return ! this . valueStateMessage . length && this . hasValueStateText ;
450
+ }
451
+
452
+ get shouldOpenValueStateMessagePopover ( ) {
453
+ return this . focused && this . hasValueStateText && ! this . hideInput ;
454
+ }
455
+
456
+ get classes ( ) {
457
+ return {
458
+ popoverValueState : {
459
+ "ui5-valuestatemessage-root" : true ,
460
+ "ui5-valuestatemessage--success" : this . valueState === ValueState . Success ,
461
+ "ui5-valuestatemessage--error" : this . valueState === ValueState . Error ,
462
+ "ui5-valuestatemessage--warning" : this . valueState === ValueState . Warning ,
463
+ "ui5-valuestatemessage--information" : this . valueState === ValueState . Information ,
464
+ } ,
465
+ } ;
466
+ }
467
+
468
+ get styles ( ) {
469
+ return {
470
+ popoverHeader : {
471
+ "width" : `${ this . ui5Input ? this . ui5Input . offsetWidth : 0 } px` ,
472
+ } ,
473
+ } ;
474
+ }
475
+
476
+ get ui5Input ( ) {
477
+ return this . shadowRoot . querySelector ( ".ui5-file-uploader-input" ) ;
478
+ }
479
+
341
480
static get dependencies ( ) {
342
- return [ Input ] ;
481
+ return [ Input , Popover ] ;
343
482
}
344
483
345
484
static async onDefine ( ) {
0 commit comments