66import '@vaadin/progress-bar/src/vaadin-progress-bar.js' ;
77import './vaadin-upload-icons.js' ;
88import { html , PolymerElement } from '@polymer/polymer/polymer-element.js' ;
9+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js' ;
910import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js' ;
11+ import { SlotController } from '@vaadin/component-base/src/slot-controller.js' ;
1012import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js' ;
1113
1214/**
@@ -30,7 +32,6 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
3032 * `start-button` | Start file upload button
3133 * `retry-button` | Retry file upload button
3234 * `remove-button` | Remove file button
33- * `progress` | Progress bar
3435 *
3536 * The following state attributes are available for styling:
3637 *
@@ -46,10 +47,11 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
4647 * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
4748 *
4849 * @extends HTMLElement
50+ * @mixes ControllerMixin
4951 * @mixes FocusMixin
5052 * @mixes ThemableMixin
5153 */
52- class UploadFile extends FocusMixin ( ThemableMixin ( PolymerElement ) ) {
54+ class UploadFile extends FocusMixin ( ThemableMixin ( ControllerMixin ( PolymerElement ) ) ) {
5355 static get template ( ) {
5456 return html `
5557 < style >
@@ -72,8 +74,8 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
7274 box-shadow : none;
7375 }
7476
75- : host ( [complete ]) [ part = 'progress' ],
76- : host ( [error ]) [ part = 'progress' ] {
77+ : host ( [complete ]) :: slotted ( [ slot = 'progress' ]) ,
78+ : host ( [error ]) :: slotted ( [ slot = 'progress' ]) {
7779 display : none !important ;
7880 }
7981 </ style >
@@ -119,12 +121,7 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
119121 </ div >
120122 </ div >
121123
122- < vaadin-progress-bar
123- part ="progress "
124- id ="progress "
125- value$ ="[[_formatProgressValue(file.progress)]] "
126- indeterminate$ ="[[file.indeterminate]] "
127- > </ vaadin-progress-bar >
124+ < slot name ="progress "> </ slot >
128125 ` ;
129126 }
130127
@@ -147,6 +144,11 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
147144 value : 0 ,
148145 reflectToAttribute : true ,
149146 } ,
147+
148+ /** @private */
149+ _progress : {
150+ type : Object ,
151+ } ,
150152 } ;
151153 }
152154
@@ -157,13 +159,25 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
157159 '_toggleHostAttribute(file.indeterminate, "indeterminate")' ,
158160 '_toggleHostAttribute(file.uploading, "uploading")' ,
159161 '_toggleHostAttribute(file.complete, "complete")' ,
162+ '__updateProgress(_progress, file.progress, file.indeterminate)' ,
160163 ] ;
161164 }
162165
163166 /** @protected */
164167 ready ( ) {
165168 super . ready ( ) ;
166169
170+ this . addController (
171+ new SlotController (
172+ this ,
173+ 'progress' ,
174+ ( ) => document . createElement ( 'vaadin-progress-bar' ) ,
175+ ( _ , progress ) => {
176+ this . _progress = progress ;
177+ } ,
178+ ) ,
179+ ) ;
180+
167181 // Handle moving focus to the button on Tab.
168182 this . shadowRoot . addEventListener ( 'focusin' , ( e ) => {
169183 const target = e . composedPath ( ) [ 0 ] ;
@@ -211,8 +225,11 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
211225 }
212226
213227 /** @private */
214- _formatProgressValue ( progress ) {
215- return progress / 100 ;
228+ __updateProgress ( progress , value , indeterminate ) {
229+ if ( progress ) {
230+ progress . value = isNaN ( value ) ? 0 : value / 100 ;
231+ progress . indeterminate = indeterminate ;
232+ }
216233 }
217234
218235 /** @private */
0 commit comments