@@ -32,7 +32,7 @@ export class HXFileTileElement extends HXElement {
3232 'icon' ,
3333 'name' ,
3434 ] ;
35- } //$observedAttributes
35+ }
3636
3737 $onAttributeChange ( attr , oldVal , newVal ) {
3838 switch ( attr ) {
@@ -53,42 +53,48 @@ export class HXFileTileElement extends HXElement {
5353 this . _elExt . innerText = this . _extension || '' ;
5454 break ;
5555 }
56- } //$onAttributeChange
56+ }
5757
58- // GETTERS
58+ /**
59+ * Icon to appear within the empty file icon.
60+ * @type {String }
61+ */
5962 get icon ( ) {
6063 return this . getAttribute ( 'icon' ) ;
6164 }
62-
63- get name ( ) {
64- return this . getAttribute ( 'name' ) ;
65- }
66-
67- get href ( ) {
68- return this . getAttribute ( 'href' ) ;
69- }
70-
71- get loading ( ) {
72- return this . hasAttribute ( 'loading' ) ;
73- }
74-
75- get valid ( ) {
76- return ! this . hasAttribute ( 'invalid' ) ;
77- }
78-
79- // SETTERS
8065 set icon ( newVal ) {
8166 this . setAttribute ( 'icon' , newVal ) ;
8267 }
8368
69+ /**
70+ * File name
71+ * @type {String }
72+ */
73+ get name ( ) {
74+ return this . getAttribute ( 'name' ) ;
75+ }
8476 set name ( newVal ) {
8577 this . setAttribute ( 'name' , newVal ) ;
8678 }
8779
80+ /**
81+ * URL to download the file
82+ * @type {String }
83+ */
84+ get href ( ) {
85+ return this . getAttribute ( 'href' ) ;
86+ }
8887 set href ( newVal ) {
8988 this . setAttribute ( 'href' , newVal ) ;
9089 }
9190
91+ /**
92+ * @default false
93+ * @type {Boolean }
94+ */
95+ get loading ( ) {
96+ return this . hasAttribute ( 'loading' ) ;
97+ }
9298 set loading ( newVal ) {
9399 if ( newVal ) {
94100 this . setAttribute ( 'loading' , '' ) ;
@@ -97,6 +103,13 @@ export class HXFileTileElement extends HXElement {
97103 }
98104 }
99105
106+ /**
107+ * @default true
108+ * @type {Boolean }
109+ */
110+ get valid ( ) {
111+ return ! this . hasAttribute ( 'invalid' ) ;
112+ }
100113 set valid ( newVal ) {
101114 if ( newVal ) {
102115 this . removeAttribute ( 'invalid' ) ;
@@ -105,6 +118,31 @@ export class HXFileTileElement extends HXElement {
105118 }
106119 }
107120
121+ /**
122+ * Simulates clicking "X" (i.e., the dismiss button)
123+ */
124+ dismiss ( ) {
125+ if ( this . loading || ! this . valid ) {
126+ if ( this . $emit ( 'cancel' ) ) {
127+ this . remove ( ) ;
128+ }
129+ } else {
130+ if ( this . $emit ( 'delete' ) ) {
131+ // only if event was not canceled by consumer
132+ this . remove ( ) ;
133+ }
134+ }
135+ }
136+
137+ /**
138+ * https://regex101.com/r/K8XCbn/2
139+ * @private
140+ */
141+ get _extension ( ) {
142+ let re = / (?: \. ( [ ^ . ] + ) ) ? $ / ;
143+ return re . exec ( this . name ) [ 1 ] ;
144+ }
145+
108146 /** @private */
109147 get _btnDismiss ( ) {
110148 return this . shadowRoot . getElementById ( 'hxDismiss' ) ;
@@ -125,26 +163,9 @@ export class HXFileTileElement extends HXElement {
125163 return this . shadowRoot . getElementById ( 'hxLink' ) ;
126164 }
127165
128- /** @private */
129- // https://regex101.com/r/K8XCbn/2
130- get _extension ( ) {
131- let re = / (?: \. ( [ ^ . ] + ) ) ? $ / ;
132- return re . exec ( this . name ) [ 1 ] ;
133- }
134-
135166 /** @private */
136167 _onDismiss ( evt ) {
137168 evt . preventDefault ( ) ;
138-
139- if ( this . loading || ! this . valid ) {
140- if ( this . $emit ( 'cancel' ) ) {
141- this . remove ( ) ;
142- }
143- } else {
144- if ( this . $emit ( 'delete' ) ) {
145- // only if event was not canceled by consumer
146- this . remove ( ) ;
147- }
148- }
169+ this . dismiss ( ) ;
149170 }
150171}
0 commit comments