@finema/core 1.4.82 → 1.4.83
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/README.md +63 -63
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -1
- package/dist/runtime/components/Alert.vue +48 -48
- package/dist/runtime/components/Avatar.vue +27 -27
- package/dist/runtime/components/Badge.vue +53 -53
- package/dist/runtime/components/Breadcrumb.vue +44 -44
- package/dist/runtime/components/Button/Group.vue +37 -37
- package/dist/runtime/components/Button/index.vue +76 -76
- package/dist/runtime/components/Card.vue +38 -38
- package/dist/runtime/components/Core.vue +13 -13
- package/dist/runtime/components/Dialog/index.vue +108 -108
- package/dist/runtime/components/Dropdown/index.vue +70 -70
- package/dist/runtime/components/Form/FieldWrapper.vue +23 -23
- package/dist/runtime/components/Form/Fields.vue +160 -160
- package/dist/runtime/components/Form/InputCheckbox/index.vue +21 -21
- package/dist/runtime/components/Form/InputDateTime/index.vue +60 -60
- package/dist/runtime/components/Form/InputNumber/index.vue +27 -27
- package/dist/runtime/components/Form/InputRadio/index.vue +27 -27
- package/dist/runtime/components/Form/InputSelect/index.vue +36 -36
- package/dist/runtime/components/Form/InputStatic/index.vue +16 -16
- package/dist/runtime/components/Form/InputText/index.vue +67 -67
- package/dist/runtime/components/Form/InputTextarea/index.vue +25 -25
- package/dist/runtime/components/Form/InputToggle/index.vue +14 -14
- package/dist/runtime/components/Form/InputUploadDropzone/index.vue +158 -158
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/index.vue +242 -242
- package/dist/runtime/components/Form/InputUploadFileClassic/index.vue +101 -101
- package/dist/runtime/components/Form/InputUploadFileClassicAuto/index.vue +165 -165
- package/dist/runtime/components/Form/index.vue +6 -6
- package/dist/runtime/components/Icon.vue +23 -23
- package/dist/runtime/components/Image.vue +36 -36
- package/dist/runtime/components/Loader.vue +14 -14
- package/dist/runtime/components/Modal/index.vue +146 -146
- package/dist/runtime/components/SimplePagination.vue +96 -96
- package/dist/runtime/components/Slideover/index.vue +110 -110
- package/dist/runtime/components/Table/Base.vue +139 -139
- package/dist/runtime/components/Table/ColumnDate.vue +16 -16
- package/dist/runtime/components/Table/ColumnDateTime.vue +18 -18
- package/dist/runtime/components/Table/ColumnImage.vue +15 -15
- package/dist/runtime/components/Table/ColumnNumber.vue +14 -14
- package/dist/runtime/components/Table/ColumnText.vue +25 -25
- package/dist/runtime/components/Table/Simple.vue +64 -64
- package/dist/runtime/components/Table/index.vue +60 -60
- package/dist/runtime/components/Tabs/index.vue +64 -64
- package/dist/runtime/ui.css +32 -32
- package/package.json +1 -1
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
-
<USelectMenu
|
|
4
|
-
v-model="value"
|
|
5
|
-
searchable
|
|
6
|
-
:options="options"
|
|
7
|
-
:placeholder="placeholder || label"
|
|
8
|
-
:disabled="wrapperProps.isDisabled"
|
|
9
|
-
:loading="loading"
|
|
10
|
-
:searchable-placeholder="searchablePlaceholder"
|
|
11
|
-
value-attribute="value"
|
|
12
|
-
option-attribute="label"
|
|
13
|
-
:icon="icon"
|
|
14
|
-
:color="color"
|
|
15
|
-
:size="size"
|
|
16
|
-
:ui="ui"
|
|
17
|
-
:ui-menu="uiMenu"
|
|
18
|
-
>
|
|
19
|
-
<template #label>
|
|
20
|
-
<span v-if="value" class="truncate">
|
|
21
|
-
{{ options.find((item) => item.value === value)?.label || value }}
|
|
22
|
-
</span>
|
|
23
|
-
</template>
|
|
24
|
-
</USelectMenu>
|
|
25
|
-
</FieldWrapper>
|
|
26
|
-
</template>
|
|
27
|
-
|
|
28
|
-
<script lang="ts" setup>
|
|
29
|
-
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
30
|
-
import { useFieldHOC } from '#core/composables/useForm'
|
|
31
|
-
import { type ISelectFieldProps } from '#core/components/Form/InputSelect/types'
|
|
32
|
-
|
|
33
|
-
const props = withDefaults(defineProps<ISelectFieldProps>(), {})
|
|
34
|
-
|
|
35
|
-
const { value, wrapperProps } = useFieldHOC<any>(props)
|
|
36
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
+
<USelectMenu
|
|
4
|
+
v-model="value"
|
|
5
|
+
searchable
|
|
6
|
+
:options="options"
|
|
7
|
+
:placeholder="placeholder || label"
|
|
8
|
+
:disabled="wrapperProps.isDisabled"
|
|
9
|
+
:loading="loading"
|
|
10
|
+
:searchable-placeholder="searchablePlaceholder"
|
|
11
|
+
value-attribute="value"
|
|
12
|
+
option-attribute="label"
|
|
13
|
+
:icon="icon"
|
|
14
|
+
:color="color"
|
|
15
|
+
:size="size"
|
|
16
|
+
:ui="ui"
|
|
17
|
+
:ui-menu="uiMenu"
|
|
18
|
+
>
|
|
19
|
+
<template #label>
|
|
20
|
+
<span v-if="value" class="truncate">
|
|
21
|
+
{{ options.find((item) => item.value === value)?.label || value }}
|
|
22
|
+
</span>
|
|
23
|
+
</template>
|
|
24
|
+
</USelectMenu>
|
|
25
|
+
</FieldWrapper>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<script lang="ts" setup>
|
|
29
|
+
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
30
|
+
import { useFieldHOC } from '#core/composables/useForm'
|
|
31
|
+
import { type ISelectFieldProps } from '#core/components/Form/InputSelect/types'
|
|
32
|
+
|
|
33
|
+
const props = withDefaults(defineProps<ISelectFieldProps>(), {})
|
|
34
|
+
|
|
35
|
+
const { value, wrapperProps } = useFieldHOC<any>(props)
|
|
36
|
+
</script>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<FieldWrapper v-bind="wrapperProps" :is-required="false">
|
|
3
|
-
<p class="form-control-static">
|
|
4
|
-
{{ !value || value.length === 0 ? '-' : value }}
|
|
5
|
-
</p>
|
|
6
|
-
</FieldWrapper>
|
|
7
|
-
</template>
|
|
8
|
-
<script lang="ts" setup>
|
|
9
|
-
import { type IStaticFieldProps } from '#core/components/Form/InputStatic/types'
|
|
10
|
-
import { useFieldHOC } from '#core/composables/useForm'
|
|
11
|
-
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
12
|
-
|
|
13
|
-
const props = withDefaults(defineProps<IStaticFieldProps>(), {})
|
|
14
|
-
|
|
15
|
-
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
16
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<FieldWrapper v-bind="wrapperProps" :is-required="false">
|
|
3
|
+
<p class="form-control-static">
|
|
4
|
+
{{ !value || value.length === 0 ? '-' : value }}
|
|
5
|
+
</p>
|
|
6
|
+
</FieldWrapper>
|
|
7
|
+
</template>
|
|
8
|
+
<script lang="ts" setup>
|
|
9
|
+
import { type IStaticFieldProps } from '#core/components/Form/InputStatic/types'
|
|
10
|
+
import { useFieldHOC } from '#core/composables/useForm'
|
|
11
|
+
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(defineProps<IStaticFieldProps>(), {})
|
|
14
|
+
|
|
15
|
+
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
16
|
+
</script>
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
-
<UInput
|
|
4
|
-
v-if="type === 'password'"
|
|
5
|
-
v-model="value"
|
|
6
|
-
v-maska:[maskOptions]
|
|
7
|
-
:data-maska="mask"
|
|
8
|
-
:data-maska-tokens="maskTokens"
|
|
9
|
-
:data-maska-tokens-replace="maskTokensReplace"
|
|
10
|
-
:data-maska-reversed="maskReversed"
|
|
11
|
-
:data-maska-eager="maskEager"
|
|
12
|
-
:disabled="wrapperProps.isDisabled"
|
|
13
|
-
:leading-icon="leadingIcon"
|
|
14
|
-
:trailing-icon="trailingIcon"
|
|
15
|
-
:name="name"
|
|
16
|
-
:placeholder="wrapperProps.placeholder"
|
|
17
|
-
:type="isShowPassword ? 'text' : 'password'"
|
|
18
|
-
:autofocus="!!autoFocus"
|
|
19
|
-
:icon="icon"
|
|
20
|
-
:readonly="isReadonly"
|
|
21
|
-
:ui="_deepMerge({}, ui, { icon: { trailing: { pointer: '' } } })"
|
|
22
|
-
>
|
|
23
|
-
<template #trailing>
|
|
24
|
-
<UButton
|
|
25
|
-
color="gray"
|
|
26
|
-
variant="link"
|
|
27
|
-
:icon="isShowPassword ? 'i-heroicons-eye-slash' : 'i-heroicons-eye'"
|
|
28
|
-
:padded="false"
|
|
29
|
-
@click="isShowPassword = !isShowPassword"
|
|
30
|
-
/>
|
|
31
|
-
</template>
|
|
32
|
-
</UInput>
|
|
33
|
-
<UInput
|
|
34
|
-
v-else
|
|
35
|
-
v-model="value"
|
|
36
|
-
v-maska:[maskOptions]
|
|
37
|
-
:data-maska="mask"
|
|
38
|
-
:data-maska-tokens="maskTokens"
|
|
39
|
-
:data-maska-tokens-replace="maskTokensReplace"
|
|
40
|
-
:data-maska-reversed="maskReversed"
|
|
41
|
-
:data-maska-eager="maskEager"
|
|
42
|
-
:disabled="wrapperProps.isDisabled"
|
|
43
|
-
:leading-icon="leadingIcon"
|
|
44
|
-
:trailing-icon="trailingIcon"
|
|
45
|
-
:name="name"
|
|
46
|
-
:placeholder="wrapperProps.placeholder"
|
|
47
|
-
:type="type || 'text'"
|
|
48
|
-
:autofocus="!!autoFocus"
|
|
49
|
-
:icon="icon"
|
|
50
|
-
:readonly="isReadonly"
|
|
51
|
-
:ui="ui"
|
|
52
|
-
/>
|
|
53
|
-
</FieldWrapper>
|
|
54
|
-
</template>
|
|
55
|
-
<script lang="ts" setup>
|
|
56
|
-
import { _deepMerge, ref } from '#imports'
|
|
57
|
-
import { type ITextFieldProps } from '#core/components/Form/InputText/types'
|
|
58
|
-
import { useFieldHOC } from '#core/composables/useForm'
|
|
59
|
-
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
60
|
-
import { vMaska } from 'maska'
|
|
61
|
-
|
|
62
|
-
const props = withDefaults(defineProps<ITextFieldProps>(), {})
|
|
63
|
-
|
|
64
|
-
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
65
|
-
|
|
66
|
-
const isShowPassword = ref(false)
|
|
67
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
+
<UInput
|
|
4
|
+
v-if="type === 'password'"
|
|
5
|
+
v-model="value"
|
|
6
|
+
v-maska:[maskOptions]
|
|
7
|
+
:data-maska="mask"
|
|
8
|
+
:data-maska-tokens="maskTokens"
|
|
9
|
+
:data-maska-tokens-replace="maskTokensReplace"
|
|
10
|
+
:data-maska-reversed="maskReversed"
|
|
11
|
+
:data-maska-eager="maskEager"
|
|
12
|
+
:disabled="wrapperProps.isDisabled"
|
|
13
|
+
:leading-icon="leadingIcon"
|
|
14
|
+
:trailing-icon="trailingIcon"
|
|
15
|
+
:name="name"
|
|
16
|
+
:placeholder="wrapperProps.placeholder"
|
|
17
|
+
:type="isShowPassword ? 'text' : 'password'"
|
|
18
|
+
:autofocus="!!autoFocus"
|
|
19
|
+
:icon="icon"
|
|
20
|
+
:readonly="isReadonly"
|
|
21
|
+
:ui="_deepMerge({}, ui, { icon: { trailing: { pointer: '' } } })"
|
|
22
|
+
>
|
|
23
|
+
<template #trailing>
|
|
24
|
+
<UButton
|
|
25
|
+
color="gray"
|
|
26
|
+
variant="link"
|
|
27
|
+
:icon="isShowPassword ? 'i-heroicons-eye-slash' : 'i-heroicons-eye'"
|
|
28
|
+
:padded="false"
|
|
29
|
+
@click="isShowPassword = !isShowPassword"
|
|
30
|
+
/>
|
|
31
|
+
</template>
|
|
32
|
+
</UInput>
|
|
33
|
+
<UInput
|
|
34
|
+
v-else
|
|
35
|
+
v-model="value"
|
|
36
|
+
v-maska:[maskOptions]
|
|
37
|
+
:data-maska="mask"
|
|
38
|
+
:data-maska-tokens="maskTokens"
|
|
39
|
+
:data-maska-tokens-replace="maskTokensReplace"
|
|
40
|
+
:data-maska-reversed="maskReversed"
|
|
41
|
+
:data-maska-eager="maskEager"
|
|
42
|
+
:disabled="wrapperProps.isDisabled"
|
|
43
|
+
:leading-icon="leadingIcon"
|
|
44
|
+
:trailing-icon="trailingIcon"
|
|
45
|
+
:name="name"
|
|
46
|
+
:placeholder="wrapperProps.placeholder"
|
|
47
|
+
:type="type || 'text'"
|
|
48
|
+
:autofocus="!!autoFocus"
|
|
49
|
+
:icon="icon"
|
|
50
|
+
:readonly="isReadonly"
|
|
51
|
+
:ui="ui"
|
|
52
|
+
/>
|
|
53
|
+
</FieldWrapper>
|
|
54
|
+
</template>
|
|
55
|
+
<script lang="ts" setup>
|
|
56
|
+
import { _deepMerge, ref } from '#imports'
|
|
57
|
+
import { type ITextFieldProps } from '#core/components/Form/InputText/types'
|
|
58
|
+
import { useFieldHOC } from '#core/composables/useForm'
|
|
59
|
+
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
60
|
+
import { vMaska } from 'maska'
|
|
61
|
+
|
|
62
|
+
const props = withDefaults(defineProps<ITextFieldProps>(), {})
|
|
63
|
+
|
|
64
|
+
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
65
|
+
|
|
66
|
+
const isShowPassword = ref(false)
|
|
67
|
+
</script>
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
-
<UTextarea
|
|
4
|
-
v-model="value"
|
|
5
|
-
:disabled="wrapperProps.isDisabled"
|
|
6
|
-
:name="name"
|
|
7
|
-
:resize="resize"
|
|
8
|
-
:placeholder="wrapperProps.placeholder"
|
|
9
|
-
:autofocus="!!autoFocus"
|
|
10
|
-
:autoresize="autoresize"
|
|
11
|
-
:rows="rows"
|
|
12
|
-
:readonly="isReadonly"
|
|
13
|
-
:ui="ui"
|
|
14
|
-
/>
|
|
15
|
-
</FieldWrapper>
|
|
16
|
-
</template>
|
|
17
|
-
<script lang="ts" setup>
|
|
18
|
-
import { useFieldHOC } from '#core/composables/useForm'
|
|
19
|
-
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
20
|
-
import { type ITextareaFieldProps } from '#core/components/Form/InputTextarea/types'
|
|
21
|
-
|
|
22
|
-
const props = withDefaults(defineProps<ITextareaFieldProps>(), {})
|
|
23
|
-
|
|
24
|
-
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
25
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
+
<UTextarea
|
|
4
|
+
v-model="value"
|
|
5
|
+
:disabled="wrapperProps.isDisabled"
|
|
6
|
+
:name="name"
|
|
7
|
+
:resize="resize"
|
|
8
|
+
:placeholder="wrapperProps.placeholder"
|
|
9
|
+
:autofocus="!!autoFocus"
|
|
10
|
+
:autoresize="autoresize"
|
|
11
|
+
:rows="rows"
|
|
12
|
+
:readonly="isReadonly"
|
|
13
|
+
:ui="ui"
|
|
14
|
+
/>
|
|
15
|
+
</FieldWrapper>
|
|
16
|
+
</template>
|
|
17
|
+
<script lang="ts" setup>
|
|
18
|
+
import { useFieldHOC } from '#core/composables/useForm'
|
|
19
|
+
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
20
|
+
import { type ITextareaFieldProps } from '#core/components/Form/InputTextarea/types'
|
|
21
|
+
|
|
22
|
+
const props = withDefaults(defineProps<ITextareaFieldProps>(), {})
|
|
23
|
+
|
|
24
|
+
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
25
|
+
</script>
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
-
<UToggle v-model="value" :disabled="wrapperProps.isDisabled" :name="name" :ui="ui" />
|
|
4
|
-
</FieldWrapper>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script lang="ts" setup>
|
|
8
|
-
import { useFieldHOC } from '#core/composables/useForm'
|
|
9
|
-
import { type IToggleFieldProps } from '#core/components/Form/InputToggle/types'
|
|
10
|
-
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
11
|
-
|
|
12
|
-
const props = withDefaults(defineProps<IToggleFieldProps>(), {})
|
|
13
|
-
const { value, wrapperProps } = useFieldHOC<boolean>(props)
|
|
14
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
+
<UToggle v-model="value" :disabled="wrapperProps.isDisabled" :name="name" :ui="ui" />
|
|
4
|
+
</FieldWrapper>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts" setup>
|
|
8
|
+
import { useFieldHOC } from '#core/composables/useForm'
|
|
9
|
+
import { type IToggleFieldProps } from '#core/components/Form/InputToggle/types'
|
|
10
|
+
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<IToggleFieldProps>(), {})
|
|
13
|
+
const { value, wrapperProps } = useFieldHOC<boolean>(props)
|
|
14
|
+
</script>
|
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
-
<div
|
|
4
|
-
ref="dropzoneRef"
|
|
5
|
-
:class="[
|
|
6
|
-
ui.base,
|
|
7
|
-
{
|
|
8
|
-
[ui.disabled]: isDisabled,
|
|
9
|
-
[ui.background.default]: !isOverDropZone && !isDisabled,
|
|
10
|
-
[ui.background.dragover]: isOverDropZone && !isDisabled,
|
|
11
|
-
},
|
|
12
|
-
]"
|
|
13
|
-
>
|
|
14
|
-
<Icon
|
|
15
|
-
v-if="selectedFile"
|
|
16
|
-
:name="ui.default.closeIcon"
|
|
17
|
-
:class="[ui.button.delete]"
|
|
18
|
-
@click="handleDeleteFile"
|
|
19
|
-
/>
|
|
20
|
-
<input
|
|
21
|
-
ref="fileInputRef"
|
|
22
|
-
type="file"
|
|
23
|
-
class="hidden"
|
|
24
|
-
:name="name"
|
|
25
|
-
:accept="acceptFile"
|
|
26
|
-
:disabled="isDisabled"
|
|
27
|
-
@change="handleChange"
|
|
28
|
-
/>
|
|
29
|
-
<div :class="[ui.wrapper]">
|
|
30
|
-
<div v-if="selectedFile" :class="[ui.preview.wrapper]">
|
|
31
|
-
<div v-if="isImage(selectedFile)" :class="[ui.preview.image.wrapper]">
|
|
32
|
-
<img :src="generateURL(selectedFile)" :class="[ui.preview.image.img]" alt="file" />
|
|
33
|
-
</div>
|
|
34
|
-
<Icon v-else :name="ui.default.filePreviewIcon" :class="[ui.preview.icon]" />
|
|
35
|
-
<div :class="[ui.preview.filename]">
|
|
36
|
-
<p class="truncate">{{ selectedFile.name }}</p>
|
|
37
|
-
</div>
|
|
38
|
-
<Badge size="xs" variant="outline" class="mt-1">
|
|
39
|
-
{{ isSelectedFileUseMb ? `${selectedFileSizeMb} Mb` : `${selectedFileSizeKb} Kb` }}
|
|
40
|
-
</Badge>
|
|
41
|
-
</div>
|
|
42
|
-
<div v-if="!selectedFile" :class="[ui.placeholderWrapper]">
|
|
43
|
-
<Icon :name="ui.default.uploadIcon" :class="[ui.labelIcon]" />
|
|
44
|
-
<div :class="[ui.labelWrapper]">
|
|
45
|
-
<p class="text-primary cursor-pointer" @click="handleOpenFile">
|
|
46
|
-
{{ selectFileLabel ?? 'คลิกเพื่อเลือกไฟล์' }}
|
|
47
|
-
</p>
|
|
48
|
-
<p>{{ selectFileSubLabel ?? 'หรือ ลากและวางที่นี่' }}</p>
|
|
49
|
-
</div>
|
|
50
|
-
<p v-if="placeholder" :class="[ui.placeholder]">{{ placeholder }}</p>
|
|
51
|
-
</div>
|
|
52
|
-
</div>
|
|
53
|
-
</div>
|
|
54
|
-
</FieldWrapper>
|
|
55
|
-
</template>
|
|
56
|
-
|
|
57
|
-
<script lang="ts" setup>
|
|
58
|
-
import { useDropZone } from '@vueuse/core'
|
|
59
|
-
import { type IUploadDropzoneProps } from './types'
|
|
60
|
-
import { isImage, generateURL, checkMaxSize, checkFileType } from '#core/helpers/componentHelper'
|
|
61
|
-
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
62
|
-
import { useFieldHOC } from '#core/composables/useForm'
|
|
63
|
-
import { computed, ref, toRef, useUI, useUiConfig } from '#imports'
|
|
64
|
-
import { uploadFileDropzone } from '#core/ui.config'
|
|
65
|
-
import i18next from 'i18next'
|
|
66
|
-
|
|
67
|
-
const config = useUiConfig<typeof uploadFileDropzone>(uploadFileDropzone, 'uploadFileDropzone')
|
|
68
|
-
|
|
69
|
-
const props = withDefaults(defineProps<IUploadDropzoneProps>(), {})
|
|
70
|
-
const emit = defineEmits(['change', 'delete'])
|
|
71
|
-
|
|
72
|
-
const { wrapperProps, handleChange: onChange, setErrors, value } = useFieldHOC<File>(props)
|
|
73
|
-
|
|
74
|
-
const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
|
|
75
|
-
|
|
76
|
-
const fileInputRef = ref<HTMLInputElement>()
|
|
77
|
-
const dropzoneRef = ref<HTMLDivElement>()
|
|
78
|
-
|
|
79
|
-
const acceptFile = computed(() =>
|
|
80
|
-
typeof props.accept === 'string' ? props.accept : props.accept?.join(',')
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
const acceptFileSizeKb = computed(() => props.maxSize)
|
|
84
|
-
const acceptFileSizeMb = computed(() => ((acceptFileSizeKb.value ?? 0) / 1024).toFixed(2))
|
|
85
|
-
const isAcceptFileUseMb = computed(() => acceptFileSizeKb.value && acceptFileSizeKb.value > 1024)
|
|
86
|
-
|
|
87
|
-
const selectedFileSizeKb = computed(() => ((value?.value.size || 0) / 1000).toFixed(2))
|
|
88
|
-
const selectedFileSizeMb = computed(() => ((value?.value.size || 0) / 1000 / 1000).toFixed(2))
|
|
89
|
-
const isSelectedFileUseMb = computed(() => (value?.value.size || 0) / 1000 > 1024)
|
|
90
|
-
const selectedFile = computed(() => value?.value)
|
|
91
|
-
|
|
92
|
-
const onDrop = (files: File[] | null) => {
|
|
93
|
-
if (props.isDisabled || files?.length === 0 || !files) return
|
|
94
|
-
|
|
95
|
-
const file = files[0]
|
|
96
|
-
const result = handleCheckFileCondition(file)
|
|
97
|
-
|
|
98
|
-
if (result) {
|
|
99
|
-
onChange(file)
|
|
100
|
-
emit('change', file)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
|
|
105
|
-
onDrop,
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
const handleChange = (e: Event) => {
|
|
109
|
-
if (props.isDisabled) return
|
|
110
|
-
|
|
111
|
-
const file = (e.target as HTMLInputElement).files?.[0]
|
|
112
|
-
const result = handleCheckFileCondition(file)
|
|
113
|
-
|
|
114
|
-
if (result && file) {
|
|
115
|
-
onChange(file)
|
|
116
|
-
value.value = file
|
|
117
|
-
emit('change', file)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const handleOpenFile = () => {
|
|
122
|
-
fileInputRef.value?.click()
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const handleDeleteFile = () => {
|
|
126
|
-
fileInputRef.value?.value && (fileInputRef.value.value = '')
|
|
127
|
-
onChange(undefined)
|
|
128
|
-
emit('delete')
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const handleCheckFileCondition = (file: File | undefined): boolean => {
|
|
132
|
-
if (!file) return false
|
|
133
|
-
|
|
134
|
-
const fileType = checkFileType(file, acceptFile.value ?? '')
|
|
135
|
-
|
|
136
|
-
if (!fileType) {
|
|
137
|
-
setErrors(i18next.t('custom:invalid_file_type'))
|
|
138
|
-
|
|
139
|
-
return false
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const maxSize = checkMaxSize(file, acceptFileSizeKb.value ?? 0)
|
|
143
|
-
|
|
144
|
-
if (!maxSize) {
|
|
145
|
-
if (isAcceptFileUseMb.value) {
|
|
146
|
-
setErrors(i18next.t('custom:invalid_file_size_mb', { size: acceptFileSizeMb.value }))
|
|
147
|
-
} else {
|
|
148
|
-
setErrors(i18next.t('custom:invalid_file_size_kb', { size: acceptFileSizeKb.value }))
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return false
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
setErrors('')
|
|
155
|
-
|
|
156
|
-
return true
|
|
157
|
-
}
|
|
158
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
+
<div
|
|
4
|
+
ref="dropzoneRef"
|
|
5
|
+
:class="[
|
|
6
|
+
ui.base,
|
|
7
|
+
{
|
|
8
|
+
[ui.disabled]: isDisabled,
|
|
9
|
+
[ui.background.default]: !isOverDropZone && !isDisabled,
|
|
10
|
+
[ui.background.dragover]: isOverDropZone && !isDisabled,
|
|
11
|
+
},
|
|
12
|
+
]"
|
|
13
|
+
>
|
|
14
|
+
<Icon
|
|
15
|
+
v-if="selectedFile"
|
|
16
|
+
:name="ui.default.closeIcon"
|
|
17
|
+
:class="[ui.button.delete]"
|
|
18
|
+
@click="handleDeleteFile"
|
|
19
|
+
/>
|
|
20
|
+
<input
|
|
21
|
+
ref="fileInputRef"
|
|
22
|
+
type="file"
|
|
23
|
+
class="hidden"
|
|
24
|
+
:name="name"
|
|
25
|
+
:accept="acceptFile"
|
|
26
|
+
:disabled="isDisabled"
|
|
27
|
+
@change="handleChange"
|
|
28
|
+
/>
|
|
29
|
+
<div :class="[ui.wrapper]">
|
|
30
|
+
<div v-if="selectedFile" :class="[ui.preview.wrapper]">
|
|
31
|
+
<div v-if="isImage(selectedFile)" :class="[ui.preview.image.wrapper]">
|
|
32
|
+
<img :src="generateURL(selectedFile)" :class="[ui.preview.image.img]" alt="file" />
|
|
33
|
+
</div>
|
|
34
|
+
<Icon v-else :name="ui.default.filePreviewIcon" :class="[ui.preview.icon]" />
|
|
35
|
+
<div :class="[ui.preview.filename]">
|
|
36
|
+
<p class="truncate">{{ selectedFile.name }}</p>
|
|
37
|
+
</div>
|
|
38
|
+
<Badge size="xs" variant="outline" class="mt-1">
|
|
39
|
+
{{ isSelectedFileUseMb ? `${selectedFileSizeMb} Mb` : `${selectedFileSizeKb} Kb` }}
|
|
40
|
+
</Badge>
|
|
41
|
+
</div>
|
|
42
|
+
<div v-if="!selectedFile" :class="[ui.placeholderWrapper]">
|
|
43
|
+
<Icon :name="ui.default.uploadIcon" :class="[ui.labelIcon]" />
|
|
44
|
+
<div :class="[ui.labelWrapper]">
|
|
45
|
+
<p class="text-primary cursor-pointer" @click="handleOpenFile">
|
|
46
|
+
{{ selectFileLabel ?? 'คลิกเพื่อเลือกไฟล์' }}
|
|
47
|
+
</p>
|
|
48
|
+
<p>{{ selectFileSubLabel ?? 'หรือ ลากและวางที่นี่' }}</p>
|
|
49
|
+
</div>
|
|
50
|
+
<p v-if="placeholder" :class="[ui.placeholder]">{{ placeholder }}</p>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</FieldWrapper>
|
|
55
|
+
</template>
|
|
56
|
+
|
|
57
|
+
<script lang="ts" setup>
|
|
58
|
+
import { useDropZone } from '@vueuse/core'
|
|
59
|
+
import { type IUploadDropzoneProps } from './types'
|
|
60
|
+
import { isImage, generateURL, checkMaxSize, checkFileType } from '#core/helpers/componentHelper'
|
|
61
|
+
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
62
|
+
import { useFieldHOC } from '#core/composables/useForm'
|
|
63
|
+
import { computed, ref, toRef, useUI, useUiConfig } from '#imports'
|
|
64
|
+
import { uploadFileDropzone } from '#core/ui.config'
|
|
65
|
+
import i18next from 'i18next'
|
|
66
|
+
|
|
67
|
+
const config = useUiConfig<typeof uploadFileDropzone>(uploadFileDropzone, 'uploadFileDropzone')
|
|
68
|
+
|
|
69
|
+
const props = withDefaults(defineProps<IUploadDropzoneProps>(), {})
|
|
70
|
+
const emit = defineEmits(['change', 'delete'])
|
|
71
|
+
|
|
72
|
+
const { wrapperProps, handleChange: onChange, setErrors, value } = useFieldHOC<File>(props)
|
|
73
|
+
|
|
74
|
+
const { ui } = useUI('uploadFileDropzone', toRef(props, 'ui'), config)
|
|
75
|
+
|
|
76
|
+
const fileInputRef = ref<HTMLInputElement>()
|
|
77
|
+
const dropzoneRef = ref<HTMLDivElement>()
|
|
78
|
+
|
|
79
|
+
const acceptFile = computed(() =>
|
|
80
|
+
typeof props.accept === 'string' ? props.accept : props.accept?.join(',')
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
const acceptFileSizeKb = computed(() => props.maxSize)
|
|
84
|
+
const acceptFileSizeMb = computed(() => ((acceptFileSizeKb.value ?? 0) / 1024).toFixed(2))
|
|
85
|
+
const isAcceptFileUseMb = computed(() => acceptFileSizeKb.value && acceptFileSizeKb.value > 1024)
|
|
86
|
+
|
|
87
|
+
const selectedFileSizeKb = computed(() => ((value?.value.size || 0) / 1000).toFixed(2))
|
|
88
|
+
const selectedFileSizeMb = computed(() => ((value?.value.size || 0) / 1000 / 1000).toFixed(2))
|
|
89
|
+
const isSelectedFileUseMb = computed(() => (value?.value.size || 0) / 1000 > 1024)
|
|
90
|
+
const selectedFile = computed(() => value?.value)
|
|
91
|
+
|
|
92
|
+
const onDrop = (files: File[] | null) => {
|
|
93
|
+
if (props.isDisabled || files?.length === 0 || !files) return
|
|
94
|
+
|
|
95
|
+
const file = files[0]
|
|
96
|
+
const result = handleCheckFileCondition(file)
|
|
97
|
+
|
|
98
|
+
if (result) {
|
|
99
|
+
onChange(file)
|
|
100
|
+
emit('change', file)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const { isOverDropZone } = useDropZone(dropzoneRef as unknown as HTMLElement, {
|
|
105
|
+
onDrop,
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const handleChange = (e: Event) => {
|
|
109
|
+
if (props.isDisabled) return
|
|
110
|
+
|
|
111
|
+
const file = (e.target as HTMLInputElement).files?.[0]
|
|
112
|
+
const result = handleCheckFileCondition(file)
|
|
113
|
+
|
|
114
|
+
if (result && file) {
|
|
115
|
+
onChange(file)
|
|
116
|
+
value.value = file
|
|
117
|
+
emit('change', file)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const handleOpenFile = () => {
|
|
122
|
+
fileInputRef.value?.click()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const handleDeleteFile = () => {
|
|
126
|
+
fileInputRef.value?.value && (fileInputRef.value.value = '')
|
|
127
|
+
onChange(undefined)
|
|
128
|
+
emit('delete')
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const handleCheckFileCondition = (file: File | undefined): boolean => {
|
|
132
|
+
if (!file) return false
|
|
133
|
+
|
|
134
|
+
const fileType = checkFileType(file, acceptFile.value ?? '')
|
|
135
|
+
|
|
136
|
+
if (!fileType) {
|
|
137
|
+
setErrors(i18next.t('custom:invalid_file_type'))
|
|
138
|
+
|
|
139
|
+
return false
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const maxSize = checkMaxSize(file, acceptFileSizeKb.value ?? 0)
|
|
143
|
+
|
|
144
|
+
if (!maxSize) {
|
|
145
|
+
if (isAcceptFileUseMb.value) {
|
|
146
|
+
setErrors(i18next.t('custom:invalid_file_size_mb', { size: acceptFileSizeMb.value }))
|
|
147
|
+
} else {
|
|
148
|
+
setErrors(i18next.t('custom:invalid_file_size_kb', { size: acceptFileSizeKb.value }))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return false
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
setErrors('')
|
|
155
|
+
|
|
156
|
+
return true
|
|
157
|
+
}
|
|
158
|
+
</script>
|