55
55
</template >
56
56
57
57
<script setup lang="ts">
58
- import { onMounted , onUpdated , ref } from " vue" ;
58
+ import { onMounted , onUpdated , ref , watch } from " vue" ;
59
59
60
60
import { MucButton } from " ../Button" ;
61
61
import { MucIcon } from " ../Icon" ;
@@ -71,6 +71,7 @@ const {
71
71
maxFileSizeWarning,
72
72
maxTotalFileSize = 0 ,
73
73
maxTotalFileSizeWarning,
74
+ showWarning = false ,
74
75
} = defineProps <{
75
76
/**
76
77
* Text on the upload button
@@ -108,13 +109,21 @@ const {
108
109
* Warning for invalid file size sum
109
110
*/
110
111
maxTotalFileSizeWarning? : string ;
112
+ /**
113
+ * Clears warnings when changes from 'true' to 'false'.
114
+ */
115
+ showWarning? : boolean ;
111
116
}>();
112
117
113
118
const emit = defineEmits ([
114
119
/**
115
120
* Dropped files as {@link File[] } array
116
121
*/
117
122
" files" ,
123
+ /**
124
+ * Event that signals when warnings are displayed.
125
+ */
126
+ " warning" ,
118
127
]);
119
128
120
129
/** Flag signals if file size is valid */
@@ -212,6 +221,7 @@ const _emitFiles = (files: File[]) => {
212
221
validTotalFileSizes .value = _isTotalFilesSumValid (files );
213
222
214
223
if (! validFileSizes .value || ! validTotalFileSizes .value ) {
224
+ emit (" warning" );
215
225
return ;
216
226
}
217
227
@@ -240,6 +250,27 @@ const _isTotalFilesSumValid = (files: File[]) => {
240
250
);
241
251
return true ;
242
252
};
253
+
254
+ /**
255
+ * Watches for changes in {@link Props#showWarning } and clears all warnings if it switches to 'false'.
256
+ */
257
+ watch (
258
+ () => showWarning ,
259
+ (isShowWarning : boolean ) => {
260
+ if (! isShowWarning ) {
261
+ _clearWarnings ();
262
+ }
263
+ }
264
+ );
265
+
266
+ /**
267
+ * Clears all warnings.
268
+ */
269
+ const _clearWarnings = () => {
270
+ validFileSizes .value = true ;
271
+ validTotalFileSizes .value = true ;
272
+ validFilesAmount .value = true ;
273
+ };
243
274
</script >
244
275
245
276
<style scoped>
0 commit comments