vueless 0.0.781 → 0.0.782
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -36,10 +36,10 @@ const emit = defineEmits([
|
|
|
36
36
|
"update:modelValue",
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Triggers
|
|
39
|
+
* Triggers error changes.
|
|
40
40
|
* @property {string} value
|
|
41
41
|
*/
|
|
42
|
-
"
|
|
42
|
+
"error",
|
|
43
43
|
]);
|
|
44
44
|
|
|
45
45
|
const { tm } = useLocale();
|
|
@@ -47,6 +47,8 @@ const { tm } = useLocale();
|
|
|
47
47
|
const dropZoneRef = ref<HTMLDivElement | null>(null);
|
|
48
48
|
const fileInputRef = ref<HTMLInputElement | null>(null);
|
|
49
49
|
|
|
50
|
+
const localError = ref("");
|
|
51
|
+
|
|
50
52
|
const elementId = props.id || useId();
|
|
51
53
|
|
|
52
54
|
const i18nGlobal = tm(COMPONENT_NAME);
|
|
@@ -61,10 +63,7 @@ const currentFiles = computed<File | File[] | null>({
|
|
|
61
63
|
},
|
|
62
64
|
});
|
|
63
65
|
|
|
64
|
-
const currentError = computed(
|
|
65
|
-
get: () => props.error,
|
|
66
|
-
set: (newValue) => emit("update:error", newValue),
|
|
67
|
-
});
|
|
66
|
+
const currentError = computed(() => localError.value || props.error);
|
|
68
67
|
|
|
69
68
|
const extensionNames = computed(() => {
|
|
70
69
|
return props.allowedFileTypes.map((type) => type.replace(".", ""));
|
|
@@ -105,6 +104,7 @@ onBeforeUnmount(() => {
|
|
|
105
104
|
});
|
|
106
105
|
|
|
107
106
|
watch(() => props.multiple, normalizeFilesForMultipleMode);
|
|
107
|
+
watch(currentError, () => emit("error", currentError.value));
|
|
108
108
|
|
|
109
109
|
function normalizeFilesForMultipleMode() {
|
|
110
110
|
if (!props.multiple) return;
|
|
@@ -131,13 +131,19 @@ function validate(file: File) {
|
|
|
131
131
|
|
|
132
132
|
const isValidSize = Number(targetFileSize) <= props.maxFileSize;
|
|
133
133
|
|
|
134
|
-
if (!
|
|
135
|
-
|
|
134
|
+
if (!isValidType) {
|
|
135
|
+
localError.value = currentLocale.value.formatError;
|
|
136
|
+
|
|
137
|
+
return;
|
|
136
138
|
}
|
|
137
139
|
|
|
138
|
-
if (!
|
|
139
|
-
|
|
140
|
+
if (!isValidSize && props.maxFileSize) {
|
|
141
|
+
localError.value = currentLocale.value.sizeError;
|
|
142
|
+
|
|
143
|
+
return;
|
|
140
144
|
}
|
|
145
|
+
|
|
146
|
+
localError.value = "";
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
function onChangeFile(event: Event) {
|
|
@@ -242,10 +248,18 @@ function onClickRemoveItem(id: string | number) {
|
|
|
242
248
|
* Applies: `class`, `config`, redefined default `props` and dev `vl-...` attributes.
|
|
243
249
|
*/
|
|
244
250
|
const mutatedProps = computed(() => ({
|
|
245
|
-
error: Boolean(
|
|
251
|
+
error: Boolean(currentError.value),
|
|
246
252
|
label: Boolean(props.label),
|
|
247
253
|
}));
|
|
248
254
|
|
|
255
|
+
defineExpose({
|
|
256
|
+
/**
|
|
257
|
+
* An error.
|
|
258
|
+
* @property {boolean}
|
|
259
|
+
*/
|
|
260
|
+
error: currentError,
|
|
261
|
+
});
|
|
262
|
+
|
|
249
263
|
const {
|
|
250
264
|
getDataTest,
|
|
251
265
|
config,
|
|
@@ -260,6 +274,8 @@ const {
|
|
|
260
274
|
inputAttrs,
|
|
261
275
|
fileListAttrs,
|
|
262
276
|
buttonsAttrs,
|
|
277
|
+
chooseFileButtonErrorAttrs,
|
|
278
|
+
clearButtonErrorAttrs,
|
|
263
279
|
} = useUI<Config>(defaultConfig, mutatedProps);
|
|
264
280
|
</script>
|
|
265
281
|
|
|
@@ -268,7 +284,7 @@ const {
|
|
|
268
284
|
:for="elementId"
|
|
269
285
|
:size="size"
|
|
270
286
|
:label="label"
|
|
271
|
-
:error="
|
|
287
|
+
:error="currentError"
|
|
272
288
|
:align="labelAlign"
|
|
273
289
|
:disabled="disabled"
|
|
274
290
|
:description="description"
|
|
@@ -316,11 +332,10 @@ const {
|
|
|
316
332
|
:for="elementId"
|
|
317
333
|
tag="label"
|
|
318
334
|
variant="thirdary"
|
|
319
|
-
:color="error ? 'red' : 'brand'"
|
|
320
335
|
:right-icon="config.defaults.chooseFileIcon"
|
|
321
336
|
:label="currentLocale.uploadFile"
|
|
322
337
|
:disabled="disabled"
|
|
323
|
-
v-bind="chooseFileButtonAttrs"
|
|
338
|
+
v-bind="currentError ? chooseFileButtonErrorAttrs : chooseFileButtonAttrs"
|
|
324
339
|
:data-test="getDataTest('upload')"
|
|
325
340
|
/>
|
|
326
341
|
|
|
@@ -343,9 +358,8 @@ const {
|
|
|
343
358
|
filled
|
|
344
359
|
variant="thirdary"
|
|
345
360
|
:disabled="disabled"
|
|
346
|
-
:color="error ? 'red' : 'brand'"
|
|
347
361
|
:left-icon="config.defaults.clearIcon"
|
|
348
|
-
v-bind="clearButtonAttrs"
|
|
362
|
+
v-bind="currentError ? clearButtonErrorAttrs : clearButtonAttrs"
|
|
349
363
|
:data-test="getDataTest('clear')"
|
|
350
364
|
@click="onClickResetFiles"
|
|
351
365
|
/>
|
|
@@ -65,6 +65,12 @@ export default /*tw*/ {
|
|
|
65
65
|
},
|
|
66
66
|
},
|
|
67
67
|
},
|
|
68
|
+
chooseFileButtonError: {
|
|
69
|
+
base: "{>chooseFileButton}",
|
|
70
|
+
defaults: {
|
|
71
|
+
color: "red",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
68
74
|
clearButton: {
|
|
69
75
|
base: "{UButton}",
|
|
70
76
|
defaults: {
|
|
@@ -75,6 +81,12 @@ export default /*tw*/ {
|
|
|
75
81
|
},
|
|
76
82
|
},
|
|
77
83
|
},
|
|
84
|
+
clearButtonError: {
|
|
85
|
+
base: "{>clearButton}",
|
|
86
|
+
defaults: {
|
|
87
|
+
color: "red",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
78
90
|
input: "sr-only",
|
|
79
91
|
i18n: {
|
|
80
92
|
sizeError: "File size is too big.",
|