@tak-ps/vue-tabler 4.26.1 → 4.28.0
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/CHANGELOG.md +4 -0
- package/components/TablerUploadLogo.vue +81 -0
- package/lib.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class='mb-3'>
|
|
3
|
+
<TablerInput
|
|
4
|
+
:id='props.inputId || "logoUpload"'
|
|
5
|
+
:label='props.label || "Upload PNG/SVG Logo"'
|
|
6
|
+
type='file'
|
|
7
|
+
accept='image/png, image/svg+xml'
|
|
8
|
+
:disabled='props.disabled'
|
|
9
|
+
:error='error'
|
|
10
|
+
@change='onFileChange'
|
|
11
|
+
/>
|
|
12
|
+
</div>
|
|
13
|
+
<div
|
|
14
|
+
v-if='base64Data'
|
|
15
|
+
class='mt-3 row d-flex align-items-center justify-content-center'
|
|
16
|
+
>
|
|
17
|
+
<img
|
|
18
|
+
:src='base64Data'
|
|
19
|
+
alt='Logo Preview'
|
|
20
|
+
class='img-thumbnail'
|
|
21
|
+
style='max-width: 200px;'
|
|
22
|
+
>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<script setup lang='ts'>
|
|
27
|
+
import { ref, watch } from 'vue';
|
|
28
|
+
import TablerInput from './input/Input.vue';
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits(['update:modelValue', 'file-name']);
|
|
31
|
+
|
|
32
|
+
const props = defineProps<{
|
|
33
|
+
modelValue?: string | null;
|
|
34
|
+
label?: string;
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
inputId?: string;
|
|
37
|
+
}>();
|
|
38
|
+
|
|
39
|
+
const base64Data = ref<string | undefined | null>(props.modelValue);
|
|
40
|
+
const error = ref('');
|
|
41
|
+
|
|
42
|
+
watch(() => props.modelValue, () => {
|
|
43
|
+
base64Data.value = props.modelValue;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
watch(base64Data, () => {
|
|
47
|
+
emit('update:modelValue', base64Data.value);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function onFileChange(event: Event) {
|
|
51
|
+
const target = event.target as HTMLInputElement;
|
|
52
|
+
|
|
53
|
+
error.value = '';
|
|
54
|
+
|
|
55
|
+
if (!target.files || target.files.length === 0) {
|
|
56
|
+
throw new Error('Could not read file from input');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const file = target.files[0];
|
|
60
|
+
if (!file) return;
|
|
61
|
+
|
|
62
|
+
emit('file-name', file.name);
|
|
63
|
+
|
|
64
|
+
if (!['image/png', 'image/svg+xml'].includes(file.type)) {
|
|
65
|
+
error.value = 'Please upload a PNG or SVG file.';
|
|
66
|
+
base64Data.value = '';
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const reader = new FileReader();
|
|
71
|
+
reader.onload = (e) => {
|
|
72
|
+
base64Data.value = (e.target && e.target.result) ? String(e.target.result) : undefined;
|
|
73
|
+
};
|
|
74
|
+
reader.onerror = () => {
|
|
75
|
+
error.value = 'Failed to read file.';
|
|
76
|
+
base64Data.value = '';
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
reader.readAsDataURL(file);
|
|
80
|
+
}
|
|
81
|
+
</script>
|
package/lib.ts
CHANGED
|
@@ -34,3 +34,4 @@ export { default as TablerDelete } from './components/Delete.vue';
|
|
|
34
34
|
export { default as TablerPillGroup } from './components/PillGroup.vue';
|
|
35
35
|
export { default as TablerSchema } from './components/Schema.vue';
|
|
36
36
|
export { default as TablerSchemaBuilder } from './components/SchemaBuilder.vue';
|
|
37
|
+
export { default as TablerUploadLogo } from './components/TablerUploadLogo.vue';
|