5555</template >
5656
5757<script setup lang="ts">
58- import { onMounted , onUpdated , ref } from " vue" ;
58+ import { onMounted , onUpdated , ref , watch } from " vue" ;
5959
6060import { MucButton } from " ../Button" ;
6161import { MucIcon } from " ../Icon" ;
@@ -71,6 +71,7 @@ const {
7171 maxFileSizeWarning,
7272 maxTotalFileSize = 0 ,
7373 maxTotalFileSizeWarning,
74+ showWarning = false ,
7475} = defineProps <{
7576 /**
7677 * Text on the upload button
@@ -108,13 +109,21 @@ const {
108109 * Warning for invalid file size sum
109110 */
110111 maxTotalFileSizeWarning? : string ;
112+ /**
113+ * Clears warnings when changes from 'true' to 'false'.
114+ */
115+ showWarning? : boolean ;
111116}>();
112117
113118const emit = defineEmits ([
114119 /**
115120 * Dropped files as {@link File[] } array
116121 */
117122 " files" ,
123+ /**
124+ * Event that signals when warnings are displayed.
125+ */
126+ " warning" ,
118127]);
119128
120129/** Flag signals if file size is valid */
@@ -212,6 +221,7 @@ const _emitFiles = (files: File[]) => {
212221 validTotalFileSizes .value = _isTotalFilesSumValid (files );
213222
214223 if (! validFileSizes .value || ! validTotalFileSizes .value ) {
224+ emit (" warning" );
215225 return ;
216226 }
217227
@@ -240,6 +250,27 @@ const _isTotalFilesSumValid = (files: File[]) => {
240250 );
241251 return true ;
242252};
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+ };
243274 </script >
244275
245276<style scoped>
0 commit comments