@finema/core 1.4.85 → 1.4.87

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.
Files changed (48) hide show
  1. package/README.md +63 -63
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +1 -1
  4. package/dist/runtime/components/Alert.vue +48 -48
  5. package/dist/runtime/components/Avatar.vue +27 -27
  6. package/dist/runtime/components/Badge.vue +53 -53
  7. package/dist/runtime/components/Breadcrumb.vue +44 -44
  8. package/dist/runtime/components/Button/Group.vue +37 -37
  9. package/dist/runtime/components/Button/index.vue +76 -76
  10. package/dist/runtime/components/Card.vue +38 -38
  11. package/dist/runtime/components/Core.vue +13 -13
  12. package/dist/runtime/components/Dialog/index.vue +108 -108
  13. package/dist/runtime/components/Dropdown/index.vue +70 -70
  14. package/dist/runtime/components/FlexDeck/Base.vue +77 -77
  15. package/dist/runtime/components/FlexDeck/index.vue +59 -59
  16. package/dist/runtime/components/Form/FieldWrapper.vue +23 -23
  17. package/dist/runtime/components/Form/Fields.vue +160 -160
  18. package/dist/runtime/components/Form/InputCheckbox/index.vue +21 -21
  19. package/dist/runtime/components/Form/InputDateTime/index.vue +60 -60
  20. package/dist/runtime/components/Form/InputNumber/index.vue +27 -27
  21. package/dist/runtime/components/Form/InputRadio/index.vue +27 -27
  22. package/dist/runtime/components/Form/InputSelect/index.vue +36 -36
  23. package/dist/runtime/components/Form/InputStatic/index.vue +16 -16
  24. package/dist/runtime/components/Form/InputText/index.vue +67 -67
  25. package/dist/runtime/components/Form/InputTextarea/index.vue +25 -25
  26. package/dist/runtime/components/Form/InputToggle/index.vue +14 -14
  27. package/dist/runtime/components/Form/InputUploadDropzone/index.vue +158 -158
  28. package/dist/runtime/components/Form/InputUploadDropzoneAuto/index.vue +243 -243
  29. package/dist/runtime/components/Form/InputUploadFileClassic/index.vue +101 -101
  30. package/dist/runtime/components/Form/InputUploadFileClassicAuto/index.vue +174 -174
  31. package/dist/runtime/components/Form/index.vue +6 -6
  32. package/dist/runtime/components/Icon.vue +23 -23
  33. package/dist/runtime/components/Image.vue +36 -36
  34. package/dist/runtime/components/Loader.vue +27 -14
  35. package/dist/runtime/components/Modal/index.vue +146 -146
  36. package/dist/runtime/components/SimplePagination.vue +96 -96
  37. package/dist/runtime/components/Slideover/index.vue +110 -110
  38. package/dist/runtime/components/Table/Base.vue +139 -139
  39. package/dist/runtime/components/Table/ColumnDate.vue +16 -16
  40. package/dist/runtime/components/Table/ColumnDateTime.vue +18 -18
  41. package/dist/runtime/components/Table/ColumnImage.vue +15 -15
  42. package/dist/runtime/components/Table/ColumnNumber.vue +14 -14
  43. package/dist/runtime/components/Table/ColumnText.vue +25 -25
  44. package/dist/runtime/components/Table/Simple.vue +64 -64
  45. package/dist/runtime/components/Table/index.vue +60 -60
  46. package/dist/runtime/components/Tabs/index.vue +64 -64
  47. package/dist/runtime/ui.css +32 -32
  48. package/package.json +84 -84
@@ -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>