@bagelink/vue 0.0.206 → 0.0.214
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/dist/components/ModalBglForm.vue.d.ts +44 -0
- package/dist/components/ModalBglForm.vue.d.ts.map +1 -0
- package/dist/components/NavBar.vue.d.ts.map +1 -1
- package/dist/components/form/BglForm.vue.d.ts.map +1 -1
- package/dist/components/form/index.d.ts +1 -0
- package/dist/components/form/index.d.ts.map +1 -1
- package/dist/components/form/inputs/CheckInput.vue.d.ts +11 -4
- package/dist/components/form/inputs/CheckInput.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/FileUpload.vue.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/index.cjs +252 -139
- package/dist/index.mjs +253 -140
- package/dist/plugins/modal.d.ts +3 -1
- package/dist/plugins/modal.d.ts.map +1 -1
- package/dist/style.css +153 -172
- package/dist/types/BagelForm.d.ts +2 -0
- package/dist/types/BagelForm.d.ts.map +1 -1
- package/dist/types/BtnOptions.d.ts +1 -0
- package/dist/types/BtnOptions.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/ModalBglForm.vue +120 -0
- package/src/components/NavBar.vue +47 -45
- package/src/components/form/BglForm.vue +14 -12
- package/src/components/form/index.ts +1 -0
- package/src/components/form/inputs/CheckInput.vue +84 -110
- package/src/components/form/inputs/FileUpload.vue +52 -45
- package/src/components/form/inputs/ToggleInput.vue +127 -0
- package/src/components/formkit/Toggle.vue +22 -22
- package/src/components/index.ts +1 -0
- package/src/plugins/modal.ts +16 -8
- package/src/styles/theme.css +0 -8
- package/src/types/BagelForm.ts +2 -0
- package/src/types/BtnOptions.ts +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="bg-dark"
|
|
4
|
+
:class="{ 'is-side': side, 'is-active': isActive }"
|
|
5
|
+
@click="() => (dismissable ? closeModal() : '')"
|
|
6
|
+
@keydown.esc="closeModal"
|
|
7
|
+
>
|
|
8
|
+
<div
|
|
9
|
+
class="card modal"
|
|
10
|
+
@click.stop
|
|
11
|
+
>
|
|
12
|
+
<header class="tool-bar">
|
|
13
|
+
<slot name="toolbar" />
|
|
14
|
+
<Btn
|
|
15
|
+
:style="{ float: side ? 'left' : 'right' }"
|
|
16
|
+
flat
|
|
17
|
+
icon="close"
|
|
18
|
+
@click="closeModal"
|
|
19
|
+
/>
|
|
20
|
+
<h3 class="modal-title">
|
|
21
|
+
{{ title }}
|
|
22
|
+
</h3>
|
|
23
|
+
</header>
|
|
24
|
+
<BagelForm
|
|
25
|
+
:onDelete="onDelete ? runDelete : undefined"
|
|
26
|
+
:modelValue="modelValue"
|
|
27
|
+
@update:modelValue="handleEmit"
|
|
28
|
+
@submit="runSubmit"
|
|
29
|
+
:schema="computedFormSchema"
|
|
30
|
+
/>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script lang="ts" setup>
|
|
36
|
+
import { onMounted, onUnmounted } from 'vue';
|
|
37
|
+
import {
|
|
38
|
+
Btn, BtnOptions, useEscape, BagelForm, type BglFormSchemaT,
|
|
39
|
+
} from '@bagelink/vue';
|
|
40
|
+
import '../styles/modal.css';
|
|
41
|
+
|
|
42
|
+
const props = defineProps<{
|
|
43
|
+
side?: boolean;
|
|
44
|
+
title?: string;
|
|
45
|
+
dismissable?: boolean;
|
|
46
|
+
actions?: BtnOptions[];
|
|
47
|
+
schema: BglFormSchemaT | (() => BglFormSchemaT);
|
|
48
|
+
modelValue?: Record<string, any>;
|
|
49
|
+
// eslint-disable-next-line no-unused-vars
|
|
50
|
+
onSubmit?: ((formData: any) => Promise<void>);
|
|
51
|
+
// eslint-disable-next-line no-unused-vars
|
|
52
|
+
onDelete?: ((id: string) => void);
|
|
53
|
+
}>();
|
|
54
|
+
|
|
55
|
+
const computedFormSchema = $computed(() => {
|
|
56
|
+
if (typeof props.schema === 'function') {
|
|
57
|
+
return props.schema();
|
|
58
|
+
}
|
|
59
|
+
return props.schema;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
let isActive = $ref<boolean>(false);
|
|
63
|
+
|
|
64
|
+
const emit = defineEmits(['update:isModalVisible', 'update:modelValue']);
|
|
65
|
+
const handleEmit = (value: any) => {
|
|
66
|
+
emit('update:modelValue', value);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const closeModal = () => {
|
|
70
|
+
isActive = false;
|
|
71
|
+
setTimeout(() => {
|
|
72
|
+
emit('update:isModalVisible', false);
|
|
73
|
+
}, 200);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const runSubmit = async (formData: any) => {
|
|
77
|
+
try {
|
|
78
|
+
await props.onSubmit?.(formData);
|
|
79
|
+
closeModal();
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.error(err);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const runDelete = () => {
|
|
86
|
+
props.onDelete?.(props.modelValue?.id);
|
|
87
|
+
closeModal();
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const escapeKeyClose = (e: KeyboardEvent) => props?.dismissable && useEscape(e, () => closeModal());
|
|
91
|
+
|
|
92
|
+
onMounted(() => {
|
|
93
|
+
setTimeout(() => {
|
|
94
|
+
isActive = true;
|
|
95
|
+
}, 1);
|
|
96
|
+
|
|
97
|
+
document.addEventListener(
|
|
98
|
+
'keydown',
|
|
99
|
+
escapeKeyClose,
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
onUnmounted(() => {
|
|
103
|
+
document.removeEventListener(
|
|
104
|
+
'keydown',
|
|
105
|
+
escapeKeyClose,
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<style scoped>
|
|
111
|
+
.modal-title {
|
|
112
|
+
margin-top: 0.5rem;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@media screen and (max-width: 910px) {
|
|
116
|
+
.modal-title {
|
|
117
|
+
margin-top: 1rem;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
</style>
|
|
@@ -1,51 +1,53 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
2
|
+
<div :class="{ open: isOpen, closed: !isOpen }">
|
|
3
|
+
<slot name="top" />
|
|
4
|
+
<div
|
|
5
|
+
class="nav-expend"
|
|
6
|
+
@click="isOpen = !isOpen"
|
|
7
|
+
@keypress.enter="isOpen = !isOpen"
|
|
8
|
+
role="button"
|
|
9
|
+
aria-label="Toggle Navigation"
|
|
10
|
+
tabindex="0"
|
|
11
|
+
>
|
|
12
|
+
<div class="icon-font top-arrow">
|
|
13
|
+
chevron_right
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<div class="full-nav">
|
|
18
|
+
<div class="nav-scroll">
|
|
19
|
+
<div class="nav-links-wrapper">
|
|
20
|
+
<RouterLink
|
|
21
|
+
v-for="link in links?.()"
|
|
22
|
+
class="nav-button"
|
|
23
|
+
:to="link.to"
|
|
24
|
+
:key="link.label"
|
|
25
|
+
>
|
|
26
|
+
<div class="icon-font">
|
|
27
|
+
{{ link.materialIcon }}
|
|
28
|
+
</div>
|
|
29
|
+
<div class="tooltip">
|
|
30
|
+
{{ link.localized ? link.localized : link.label }}
|
|
31
|
+
</div>
|
|
32
|
+
</RouterLink>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<div class="bot-buttons-wrapper">
|
|
37
|
+
<slot name="floor" />
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
39
41
|
</template>
|
|
40
42
|
|
|
41
43
|
<script lang="ts" setup>
|
|
42
44
|
// import LangText from "../translation/LangText.vue"s
|
|
43
|
-
import type { MaterialIcons } from
|
|
45
|
+
import type { MaterialIcons } from '@bagelink/vue';
|
|
44
46
|
|
|
45
47
|
const isOpen = $ref(true);
|
|
46
48
|
|
|
47
49
|
withDefaults(
|
|
48
|
-
|
|
50
|
+
defineProps<{
|
|
49
51
|
links?: () => {
|
|
50
52
|
label: string;
|
|
51
53
|
to: string;
|
|
@@ -56,15 +58,15 @@ withDefaults(
|
|
|
56
58
|
homeLabel?: string;
|
|
57
59
|
homeTo?: string;
|
|
58
60
|
}>(),
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
{
|
|
62
|
+
homeIcon: 'home',
|
|
63
|
+
homeLabel: 'Home',
|
|
64
|
+
homeTo: '/',
|
|
65
|
+
},
|
|
64
66
|
);
|
|
65
67
|
</script>
|
|
66
68
|
|
|
67
|
-
<style>
|
|
69
|
+
<style scoped>
|
|
68
70
|
[dir="rtl"] .top-arrow {
|
|
69
71
|
transform: rotate(180deg);
|
|
70
72
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<form @submit.prevent="runSubmit">
|
|
3
3
|
<BglField
|
|
4
4
|
v-for="(field, i) in schema" :key="field.id || `${i }p`" :field="field" :modelValue="data"
|
|
5
|
-
@update:modelValue="($event
|
|
5
|
+
@update:modelValue="($event)=>updateModelValue($event, field?.id || '')"
|
|
6
6
|
/>
|
|
7
7
|
<Btn
|
|
8
8
|
class="del-top" v-if="modelValue?.id && onDelete" @click="runDelete" value="Delete" flat icon="delete"
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
</template>
|
|
17
17
|
|
|
18
18
|
<script lang="ts" setup>
|
|
19
|
-
import { watch } from 'vue';
|
|
20
19
|
import { Btn, useModal, BglField } from '@bagelink/vue';
|
|
21
20
|
import { type BglFormSchemaT } from '@bagelink/vue';
|
|
21
|
+
import { watch } from 'vue';
|
|
22
22
|
|
|
23
23
|
const { showModal } = useModal();
|
|
24
24
|
|
|
@@ -29,11 +29,19 @@ const props = defineProps<{
|
|
|
29
29
|
onSubmit?: ((data: any) => void);
|
|
30
30
|
}>();
|
|
31
31
|
|
|
32
|
+
let data = $ref<Record<string, any>>({});
|
|
33
|
+
|
|
34
|
+
watch(() => props.modelValue, (val) => {
|
|
35
|
+
data = val;
|
|
36
|
+
}, { immediate: true, deep: true });
|
|
37
|
+
|
|
38
|
+
const updateModelValue = (val: any, fieldID: string) => {
|
|
39
|
+
if (!fieldID) return;
|
|
40
|
+
data[fieldID] = val;
|
|
41
|
+
emits('update:modelValue', data);
|
|
42
|
+
};
|
|
43
|
+
|
|
32
44
|
const emits = defineEmits(['update:modelValue', 'submit']);
|
|
33
|
-
const handleEmit = (val: any) => emits('update:modelValue', val);
|
|
34
|
-
let data = $ref({
|
|
35
|
-
...props.modelValue,
|
|
36
|
-
});
|
|
37
45
|
const runSubmit = () => {
|
|
38
46
|
emits('submit', data);
|
|
39
47
|
clearForm();
|
|
@@ -43,12 +51,6 @@ const clearForm = () => data = {};
|
|
|
43
51
|
|
|
44
52
|
const i18nT = (val: string) => val;
|
|
45
53
|
|
|
46
|
-
watch(
|
|
47
|
-
() => data,
|
|
48
|
-
() => handleEmit,
|
|
49
|
-
{ immediate: true },
|
|
50
|
-
);
|
|
51
|
-
|
|
52
54
|
const runDelete = () => {
|
|
53
55
|
showModal(
|
|
54
56
|
{
|
|
@@ -2,5 +2,6 @@ export { default as ItemRef } from './ItemRef.vue';
|
|
|
2
2
|
export { default as MaterialIcon } from './MaterialIcon.vue';
|
|
3
3
|
export { default as PlainInputField } from './PlainInputField.vue';
|
|
4
4
|
export { default as BglForm } from './BglForm.vue';
|
|
5
|
+
export { default as BagelForm } from './BglForm.vue';
|
|
5
6
|
export { default as BglField } from './BglField.vue';
|
|
6
7
|
export * from './inputs';
|
|
@@ -1,143 +1,117 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
<div
|
|
3
|
+
class="bagel-input bgl-checkbox"
|
|
4
|
+
:title="title"
|
|
5
|
+
:class="{ small: small, 'no-edit': !editMode }"
|
|
6
|
+
>
|
|
7
|
+
<input
|
|
8
|
+
:id="id"
|
|
9
|
+
type="checkbox"
|
|
10
|
+
v-model="inputVal"
|
|
11
|
+
:class="{ 'no-edit': !editMode }"
|
|
12
|
+
>
|
|
13
|
+
<svg
|
|
14
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
15
|
+
height="24" viewBox="0 -960 960 960"
|
|
16
|
+
width="24"
|
|
17
|
+
>
|
|
18
|
+
<path d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z"/></svg>
|
|
19
|
+
<label :for="id">
|
|
20
|
+
{{ label }}
|
|
21
|
+
</label>
|
|
22
|
+
</div>
|
|
20
23
|
</template>
|
|
21
24
|
|
|
22
25
|
<script setup lang="ts">
|
|
23
|
-
import { watch
|
|
24
|
-
import { BagelField } from "@bagelink/vue";
|
|
26
|
+
import { watch } from 'vue';
|
|
25
27
|
|
|
26
|
-
const emits = defineEmits([
|
|
28
|
+
const emits = defineEmits(['update:modelValue']);
|
|
27
29
|
const props = withDefaults(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
defineProps<{
|
|
31
|
+
label: string;
|
|
32
|
+
id?: string;
|
|
33
|
+
title?: string;
|
|
34
|
+
modelValue: boolean;
|
|
31
35
|
editMode?: boolean;
|
|
32
36
|
small?: boolean;
|
|
33
37
|
}>(),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
{
|
|
39
|
+
editMode: true,
|
|
40
|
+
id: Math.random().toString(36).substring(7),
|
|
41
|
+
},
|
|
37
42
|
);
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
let inputVal = $ref(false);
|
|
40
45
|
watch(inputVal, (newVal) => {
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
if (newVal === undefined) return;
|
|
47
|
+
emits('update:modelValue', newVal);
|
|
43
48
|
});
|
|
49
|
+
|
|
44
50
|
watch(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
() => props.modelValue,
|
|
52
|
+
(newVal) => {
|
|
53
|
+
if (inputVal !== newVal) inputVal = newVal;
|
|
54
|
+
},
|
|
55
|
+
{ immediate: true },
|
|
49
56
|
);
|
|
50
|
-
onMounted(() => (inputVal.value = !!props.modelValue));
|
|
51
57
|
</script>
|
|
58
|
+
<style>
|
|
59
|
+
:root {
|
|
60
|
+
--bgl-white: #fff;
|
|
61
|
+
--input-height: 40px;
|
|
62
|
+
--input-border-radius: 7px;
|
|
63
|
+
--bgl-transition: all 200ms ease;
|
|
64
|
+
--bgl-primary: #19b8ea;
|
|
52
65
|
|
|
66
|
+
}
|
|
67
|
+
</style>
|
|
53
68
|
<style scoped>
|
|
54
|
-
.
|
|
55
|
-
|
|
69
|
+
.bgl-checkbox{
|
|
70
|
+
position: relative;
|
|
56
71
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
display: inline-block;
|
|
60
|
-
color: var(--input-bg);
|
|
61
|
-
font-size: var(--input-font-size);
|
|
62
|
-
margin-inline-end: 10px;
|
|
72
|
+
.bgl-checkbox input[type=checkbox]{
|
|
73
|
+
display: none;
|
|
63
74
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
display: inline-block;
|
|
68
|
-
border-radius: var(--input-border-radius);
|
|
69
|
-
font-size: var(--input-font-size);
|
|
70
|
-
background: var(--input-bg);
|
|
71
|
-
color: var(--bgl-black);
|
|
72
|
-
text-align: center;
|
|
73
|
-
margin: 8px 5px;
|
|
75
|
+
.bgl-checkbox label{
|
|
76
|
+
padding-inline-start: calc(var(--input-height) / 2 + 0.25rem);
|
|
77
|
+
transition: var(--bgl-transition);
|
|
74
78
|
cursor: pointer;
|
|
75
79
|
user-select: none;
|
|
76
80
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
background: transparent;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.radio-wrap input {
|
|
83
|
-
display: none;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.radio-wrap input:checked:checked + label {
|
|
87
|
-
background: var(--bgl-primary);
|
|
88
|
-
color: var(--bgl-white);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
.checkbox {
|
|
92
|
-
position: relative;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.switch {
|
|
96
|
-
position: relative;
|
|
97
|
-
display: inline-block;
|
|
98
|
-
height: calc(var(--input-height) / 2);
|
|
99
|
-
width: var(--input-height);
|
|
100
|
-
border-radius: var(--input-height);
|
|
81
|
+
.bgl-checkbox:hover{
|
|
82
|
+
filter: brightness(90%);
|
|
101
83
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
opacity: 0;
|
|
105
|
-
width: 0;
|
|
106
|
-
height: 0;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.slider {
|
|
110
|
-
position: absolute;
|
|
111
|
-
cursor: pointer;
|
|
112
|
-
top: 0;
|
|
113
|
-
left: 0;
|
|
114
|
-
right: 0;
|
|
115
|
-
bottom: 0;
|
|
116
|
-
background: var(--input-bg);
|
|
117
|
-
-webkit-transition: 0.4s;
|
|
118
|
-
transition: 0.4s;
|
|
119
|
-
border-radius: calc(var(--input-height) / 2);
|
|
120
|
-
box-shadow: inset 0 0 10px #00000020;
|
|
84
|
+
.bgl-checkbox:active{
|
|
85
|
+
filter: var(--bgl-active-filter);
|
|
121
86
|
}
|
|
122
|
-
|
|
123
|
-
.slider:before {
|
|
124
|
-
position: absolute;
|
|
87
|
+
.bgl-checkbox label::before{
|
|
125
88
|
content: "";
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
left: 2px;
|
|
129
|
-
bottom: 2px;
|
|
130
|
-
border-radius: 50%;
|
|
89
|
+
width: calc(var(--input-height) / 2.5);
|
|
90
|
+
height: calc(var(--input-height) / 2.5);
|
|
131
91
|
background: var(--bgl-white);
|
|
132
|
-
|
|
133
|
-
|
|
92
|
+
display: inline-block;
|
|
93
|
+
position: absolute;
|
|
94
|
+
margin-top: 0.25rem;
|
|
95
|
+
inset-inline-start: 0;
|
|
96
|
+
border-radius: calc(var(--input-border-radius) / 2) ;
|
|
97
|
+
border: var(--bgl-primary) 1px solid;
|
|
134
98
|
}
|
|
135
99
|
|
|
136
|
-
input:checked
|
|
100
|
+
input:checked ~ label::before{
|
|
137
101
|
background: var(--bgl-primary);
|
|
138
102
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
103
|
+
.bgl-checkbox svg{
|
|
104
|
+
width: calc(var(--input-height) / 2.5);
|
|
105
|
+
height: calc(var(--input-height) / 2.5);
|
|
106
|
+
position: absolute;
|
|
107
|
+
inset-inline-start: 0.05rem;
|
|
108
|
+
margin-top: 0.3rem;
|
|
109
|
+
z-index: 2;
|
|
110
|
+
fill: var(--bgl-white);
|
|
111
|
+
opacity: 0;
|
|
112
|
+
pointer-events: none;
|
|
113
|
+
}
|
|
114
|
+
input:checked ~ svg{
|
|
115
|
+
opacity: 1;
|
|
142
116
|
}
|
|
143
117
|
</style>
|
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
<label>
|
|
4
4
|
{{ label }}
|
|
5
5
|
</label>
|
|
6
|
-
<div @click="browse" @dragover="
|
|
6
|
+
<div @click="browse" @dragover="dragover" @drop="drop" @dragleave="dragleave" class="fileUploadWrap"
|
|
7
|
+
:class="{ fileDropZone: !files.length, dragover: isDragOver }">
|
|
7
8
|
<div v-if="files.length && !multiple">
|
|
8
9
|
<div class="imagePreviewWrap">
|
|
9
|
-
<img class="preview" :src="fileToUrl(files[0])" alt=""
|
|
10
|
+
<img class="preview" :src="fileToUrl(files[0])" alt="">
|
|
10
11
|
</div>
|
|
11
12
|
<div class="previewName">
|
|
12
13
|
<p class="no-margin">
|
|
13
|
-
{{files[0].name}}
|
|
14
|
+
{{ files[0].name }}
|
|
14
15
|
</p>
|
|
15
|
-
<Btn thin @click.stop="removeFile(files[0])" flat icon="delete" color="red"/>
|
|
16
|
+
<Btn thin @click.stop="removeFile(files[0])" flat icon="delete" color="red" />
|
|
16
17
|
</div>
|
|
17
18
|
</div>
|
|
18
19
|
</div>
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
<script setup lang="ts">
|
|
23
24
|
import { Btn } from '@bagelink/vue';
|
|
24
25
|
|
|
25
|
-
const props = defineProps<{label:string, multiple?: boolean}>();
|
|
26
|
+
const props = defineProps<{ label: string, multiple?: boolean }>();
|
|
26
27
|
const files = $ref<File[]>([]);
|
|
27
28
|
const fileQueue = $ref<File[]>([]);
|
|
28
29
|
let isDragOver = $ref(false);
|
|
@@ -33,14 +34,13 @@ const preventDefault = (e: Event) => {
|
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
const fileToUrl = (file: File) => URL.createObjectURL(file);
|
|
36
|
-
const removeFile = (file:File) => {
|
|
37
|
+
const removeFile = (file: File) => {
|
|
37
38
|
const index = files.indexOf(file);
|
|
38
39
|
files.splice(index, 1);
|
|
39
40
|
};
|
|
40
41
|
const flushQueue = () => {
|
|
41
|
-
fileQueue.forEach((file:File, i) => {
|
|
42
|
+
fileQueue.forEach((file: File, i) => {
|
|
42
43
|
if (props.multiple) { if (!files.includes(file)) files.push(file); } else files.splice(0, 1, file);
|
|
43
|
-
console.log(files);
|
|
44
44
|
fileQueue.splice(i, 1);
|
|
45
45
|
});
|
|
46
46
|
};
|
|
@@ -63,7 +63,7 @@ const dragleave = (e: DragEvent) => {
|
|
|
63
63
|
else isDragOver = false;
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
const
|
|
66
|
+
const dragover = (e: DragEvent) => {
|
|
67
67
|
preventDefault(e);
|
|
68
68
|
if (e.dataTransfer) isDragOver = true;
|
|
69
69
|
else isDragOver = false;
|
|
@@ -79,52 +79,59 @@ const drop = (e: DragEvent) => {
|
|
|
79
79
|
|
|
80
80
|
<style scoped>
|
|
81
81
|
.bagel-input .fileUploadWrap {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
outline: 1px solid var(--border-color);
|
|
83
|
+
border-radius: var(--input-border-radius);
|
|
84
|
+
text-align: center;
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
transition: var(--bgl-transition);
|
|
87
|
+
position: relative;
|
|
88
|
+
height: 132px;
|
|
89
|
+
font-size: var(--input-font-size);
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
|
|
92
|
+
.previewName {
|
|
93
|
+
padding: 0.5rem;
|
|
94
|
+
text-align: start;
|
|
95
|
+
color: var(--input-color);
|
|
96
|
+
display: grid;
|
|
97
|
+
grid-template-columns: 1fr 22px;
|
|
98
|
+
align-items: center;
|
|
98
99
|
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
|
|
102
|
+
.previewName p {
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
text-overflow: ellipsis;
|
|
105
|
+
white-space: nowrap;
|
|
104
106
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
|
|
108
|
+
.imagePreviewWrap {
|
|
109
|
+
background: var(--input-bg);
|
|
110
|
+
border-radius: var(--input-border-radius);
|
|
111
|
+
height: 90px;
|
|
112
|
+
padding: 5px;
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
img.preview {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
height: 80px;
|
|
117
|
+
border-radius: var(--input-border-radius);
|
|
118
|
+
object-fit: contain;
|
|
116
119
|
}
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
|
|
121
|
+
.fileUploadWrap.dragover,
|
|
122
|
+
.fileUploadWrap:hover {
|
|
123
|
+
box-shadow: inset 0 0 10px #00000012;
|
|
119
124
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
|
|
126
|
+
.bagel-input .fileUploadWrap.fileDropZone {
|
|
127
|
+
background: var(--input-bg);
|
|
128
|
+
display: flex;
|
|
129
|
+
align-items: center;
|
|
130
|
+
justify-content: center;
|
|
131
|
+
color: var(--bgl-gray);
|
|
126
132
|
}
|
|
133
|
+
|
|
127
134
|
.bagel-input .fileUploadWrap.fileDropZone:after {
|
|
128
|
-
|
|
135
|
+
content: "Drop files here or click to upload";
|
|
129
136
|
}
|
|
130
137
|
</style>
|