@witchcraft/ui 0.2.1-beta.3 → 0.2.2
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/module.json +1 -1
- package/dist/module.mjs +20 -4
- package/dist/runtime/build/WitchcraftUiResolver.d.ts +2 -2
- package/dist/runtime/build/generateTheme.js +2 -2
- package/dist/runtime/components/Aria/Aria.d.vue.ts +5 -0
- package/dist/runtime/components/Aria/Aria.vue +4 -2
- package/dist/runtime/components/Aria/Aria.vue.d.ts +1 -1
- package/dist/runtime/components/Icon/Icon.d.vue.ts +21 -0
- package/dist/runtime/components/Icon/Icon.vue +3 -3
- package/dist/runtime/components/Icon/Icon.vue.d.ts +1 -1
- package/dist/runtime/components/LibButton/LibButton.d.vue.ts +36 -0
- package/dist/runtime/components/LibButton/LibButton.vue +9 -4
- package/dist/runtime/components/LibButton/LibButton.vue.d.ts +1 -1
- package/dist/runtime/components/LibCheckbox/LibCheckbox.d.vue.ts +42 -0
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +3 -4
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +1 -1
- package/dist/runtime/components/LibColorInput/LibColorInput.d.vue.ts +63 -0
- package/dist/runtime/components/LibColorInput/LibColorInput.vue +15 -8
- package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +1 -1
- package/dist/runtime/components/LibColorPicker/LibColorPicker.d.vue.ts +61 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +10 -6
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibColorPicker/utils/truncate.js +1 -1
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.d.vue.ts +22 -0
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +5 -2
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +1 -1
- package/dist/runtime/components/LibDatePicker/LibDatePicker.d.vue.ts +40 -0
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.d.vue.ts +34 -0
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +8 -6
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.d.vue.ts +34 -0
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +7 -5
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.d.vue.ts +22 -0
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +1 -1
- package/dist/runtime/components/LibDebug/LibDebug.d.vue.ts +32 -0
- package/dist/runtime/components/LibDebug/LibDebug.vue +9 -4
- package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +1 -1
- package/dist/runtime/components/LibDevOnly/LibDevOnly.d.vue.ts +25 -0
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +2 -1
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +4 -1
- package/dist/runtime/components/LibFileInput/LibFileInput.d.vue.ts +43 -0
- package/dist/runtime/components/LibFileInput/LibFileInput.vue +29 -13
- package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +2 -2
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.d.vue.ts +165 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +42 -12
- package/dist/runtime/components/LibLabel/LibLabel.d.vue.ts +26 -0
- package/dist/runtime/components/LibLabel/LibLabel.vue +2 -2
- package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +3 -3
- package/dist/runtime/components/LibMultiValues/LibMultiValues.d.vue.ts +29 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +1 -2
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +2 -2
- package/dist/runtime/components/LibNotifications/LibNotification.d.vue.ts +17 -0
- package/dist/runtime/components/LibNotifications/LibNotification.vue +19 -8
- package/dist/runtime/components/LibNotifications/LibNotifications.d.vue.ts +13 -0
- package/dist/runtime/components/LibNotifications/LibNotifications.vue +10 -6
- package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +2 -2
- package/dist/runtime/components/LibPagination/LibPagination.d.vue.ts +104 -0
- package/dist/runtime/components/LibPagination/LibPagination.vue +25 -12
- package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +2 -2
- package/dist/runtime/components/LibPalette/LibPalette.d.vue.ts +14 -0
- package/dist/runtime/components/LibPalette/LibPalette.vue +6 -5
- package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +5 -5
- package/dist/runtime/components/LibPopup/LibPopup.d.vue.ts +46 -0
- package/dist/runtime/components/LibPopup/LibPopup.vue +6 -4
- package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +3 -3
- package/dist/runtime/components/LibProgressBar/LibProgressBar.d.vue.ts +41 -0
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +5 -3
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +9 -9
- package/dist/runtime/components/LibRecorder/LibRecorder.d.vue.ts +77 -0
- package/dist/runtime/components/LibRecorder/LibRecorder.vue +1 -1
- package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +2 -2
- package/dist/runtime/components/LibRoot/LibRoot.d.vue.ts +41 -0
- package/dist/runtime/components/LibRoot/LibRoot.vue +11 -6
- package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +1 -1
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.d.vue.ts +35 -0
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +1 -1
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +1 -1
- package/dist/runtime/components/LibSuggestions/LibSuggestions.d.vue.ts +94 -0
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +6 -4
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +1 -1
- package/dist/runtime/components/LibTable/LibTable.d.vue.ts +45 -0
- package/dist/runtime/components/LibTable/LibTable.vue +23 -8
- package/dist/runtime/components/LibTable/LibTable.vue.d.ts +1 -1
- package/dist/runtime/components/Template/NAME.d.vue.ts +17 -0
- package/dist/runtime/components/Template/NAME.vue +2 -3
- package/dist/runtime/components/Template/NAME.vue.d.ts +1 -1
- package/dist/runtime/components/TestControls/TestControls.d.vue.ts +5 -0
- package/dist/runtime/components/TestControls/TestControls.vue +4 -2
- package/dist/runtime/components/TestControls/TestControls.vue.d.ts +1 -1
- package/dist/runtime/composables/useDragWithThreshold.d.ts +1 -1
- package/dist/runtime/composables/useInjectedI18n.d.ts +1 -1
- package/dist/runtime/composables/useScrollNearContainerEdges.d.ts +1 -1
- package/dist/runtime/composables/useSetupI18n.d.ts +1 -1
- package/dist/runtime/composables/useSuggestions.d.ts +2 -2
- package/dist/runtime/helpers/NotificationHandler.d.ts +1 -1
- package/dist/runtime/helpers/base64ToImg.js +2 -2
- package/dist/runtime/tailwind/themeConvertionOpts.d.ts +1 -1
- package/dist/runtime/types/index.d.ts +1 -1
- package/dist/runtime/utils/notifyIfError.d.ts +1 -1
- package/package.json +9 -10
- package/src/module.ts +41 -33
- package/src/runtime/build/WitchcraftUiResolver.ts +3 -3
- package/src/runtime/build/generateTheme.ts +3 -2
- package/src/runtime/build/unpluginIconViteOptions.ts +1 -1
- package/src/runtime/components/Aria/Aria.vue +5 -6
- package/src/runtime/components/Focus.stories.ts +11 -12
- package/src/runtime/components/Icon/Icon.vue +5 -9
- package/src/runtime/components/LibButton/LibButton.stories.ts +21 -22
- package/src/runtime/components/LibButton/LibButton.vue +23 -21
- package/src/runtime/components/LibCheckbox/LibCheckbox.stories.ts +6 -10
- package/src/runtime/components/LibCheckbox/LibCheckbox.vue +17 -19
- package/src/runtime/components/LibColorInput/LibColorInput.stories.ts +8 -13
- package/src/runtime/components/LibColorInput/LibColorInput.vue +49 -45
- package/src/runtime/components/LibColorPicker/LibColorPicker.stories.ts +14 -18
- package/src/runtime/components/LibColorPicker/LibColorPicker.vue +50 -52
- package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +1 -2
- package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +1 -2
- package/src/runtime/components/LibColorPicker/utils/truncate.ts +1 -2
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.ts +5 -8
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +11 -9
- package/src/runtime/components/LibDatePicker/LibDatePicker.stories.ts +14 -15
- package/src/runtime/components/LibDatePicker/LibDatePicker.vue +1 -2
- package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +13 -13
- package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +9 -8
- package/src/runtime/components/LibDatePicker/LibTimeZonePicker.vue +2 -1
- package/src/runtime/components/LibDatePicker/helpers.ts +0 -2
- package/src/runtime/components/LibDebug/LibDebug.stories.ts +11 -15
- package/src/runtime/components/LibDebug/LibDebug.vue +14 -11
- package/src/runtime/components/LibDevOnly/LibDevOnly.vue +8 -4
- package/src/runtime/components/LibFileInput/LibFileInput.stories.ts +12 -15
- package/src/runtime/components/LibFileInput/LibFileInput.vue +65 -47
- package/src/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.ts +77 -84
- package/src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +73 -48
- package/src/runtime/components/LibLabel/LibLabel.stories.ts +4 -8
- package/src/runtime/components/LibLabel/LibLabel.vue +8 -8
- package/src/runtime/components/LibMultiValues/LibMultiValues.stories.ts +10 -15
- package/src/runtime/components/LibMultiValues/LibMultiValues.vue +14 -18
- package/src/runtime/components/LibNotifications/LibNotification.stories.ts +30 -34
- package/src/runtime/components/LibNotifications/LibNotification.vue +27 -17
- package/src/runtime/components/LibNotifications/LibNotifications.stories.ts +11 -15
- package/src/runtime/components/LibNotifications/LibNotifications.vue +21 -16
- package/src/runtime/components/LibPagination/LibPagination.stories.ts +5 -9
- package/src/runtime/components/LibPagination/LibPagination.vue +46 -32
- package/src/runtime/components/LibPalette/LibPalette.stories.ts +3 -7
- package/src/runtime/components/LibPalette/LibPalette.vue +13 -12
- package/src/runtime/components/LibPopup/LibPopup.stories.ts +19 -23
- package/src/runtime/components/LibPopup/LibPopup.vue +31 -35
- package/src/runtime/components/LibProgressBar/LibProgressBar.stories.ts +13 -17
- package/src/runtime/components/LibProgressBar/LibProgressBar.vue +36 -33
- package/src/runtime/components/LibRecorder/LibRecorder.stories.ts +11 -12
- package/src/runtime/components/LibRecorder/LibRecorder.vue +34 -34
- package/src/runtime/components/LibRoot/LibRoot.vue +16 -12
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.stories.ts +20 -24
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +17 -21
- package/src/runtime/components/LibSuggestions/LibSuggestions.stories.ts +16 -19
- package/src/runtime/components/LibSuggestions/LibSuggestions.vue +28 -30
- package/src/runtime/components/LibTable/LibTable.stories.ts +30 -33
- package/src/runtime/components/LibTable/LibTable.vue +38 -24
- package/src/runtime/components/Reset.stories.ts +3 -6
- package/src/runtime/components/Scrolling.stories.ts +5 -8
- package/src/runtime/components/Template/NAME.vue +11 -11
- package/src/runtime/components/Template/TemplateStory.ts +9 -10
- package/src/runtime/components/TestControls/TestControls.vue +5 -5
- package/src/runtime/components/shared/props.ts +4 -6
- package/src/runtime/components/shared/storyHelpers/playInput.ts +2 -3
- package/src/runtime/components/shared/storyHelpers/playSuggestions.ts +5 -9
- package/src/runtime/composables/useAccesibilityOutline.ts +1 -1
- package/src/runtime/composables/useAriaLabel.ts +1 -1
- package/src/runtime/composables/useDarkMode.ts +15 -19
- package/src/runtime/composables/useDragWithThreshold.ts +6 -8
- package/src/runtime/composables/useGlobalResizeObserver.ts +0 -1
- package/src/runtime/composables/useInjectedDarkMode.ts +2 -2
- package/src/runtime/composables/useInjectedI18n.ts +1 -1
- package/src/runtime/composables/useInjectedLocale.ts +3 -4
- package/src/runtime/composables/useScrollNearContainerEdges.stories.ts +4 -4
- package/src/runtime/composables/useScrollNearContainerEdges.ts +12 -13
- package/src/runtime/composables/useSetupI18n.ts +4 -7
- package/src/runtime/composables/useSetupLocale.ts +3 -5
- package/src/runtime/composables/useSuggestions.ts +25 -30
- package/src/runtime/directives/vDetectFlex.ts +5 -8
- package/src/runtime/directives/vExtractRootEl.ts +1 -1
- package/src/runtime/directives/vResizableCols.ts +3 -7
- package/src/runtime/directives/vResizeObserver.ts +1 -2
- package/src/runtime/globalResizeObserver.ts +0 -1
- package/src/runtime/helpers/NotificationHandler.ts +8 -12
- package/src/runtime/helpers/base64ToImg.ts +2 -3
- package/src/runtime/helpers/createNoonUtcDate.ts +0 -1
- package/src/runtime/helpers/defaultTranslationFunction.ts +0 -1
- package/src/runtime/helpers/getTimeZoneList.ts +0 -1
- package/src/runtime/helpers/readFile.ts +2 -2
- package/src/runtime/helpers/resizeObserverWrapper.ts +0 -1
- package/src/runtime/helpers/storybook.ts +2 -3
- package/src/runtime/main.lib.ts +0 -2
- package/src/runtime/nuxt/plugins/vue-plugin.ts +4 -5
- package/src/runtime/tailwind/themeConvertionOpts.ts +3 -4
- package/src/runtime/theme.ts +0 -1
- package/src/runtime/types/index.ts +3 -4
- package/src/runtime/utils/notifyIfError.ts +2 -2
- package/src/runtime/utils/twMerge.ts +2 -2
- package/src/runtime/vue/VueComponentsPlugin.ts +1 -2
- package/src/runtime/vue/registerComponents.ts +0 -1
|
@@ -4,22 +4,19 @@ import { ref } from "vue"
|
|
|
4
4
|
|
|
5
5
|
import LibFileInput from "./LibFileInput.vue"
|
|
6
6
|
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
8
7
|
import * as components from "../index.js"
|
|
9
8
|
|
|
10
|
-
|
|
11
9
|
const meta: Meta<typeof LibFileInput> = {
|
|
12
10
|
component: LibFileInput,
|
|
13
11
|
title: "Components/FileInput",
|
|
14
12
|
args: {
|
|
15
13
|
|
|
16
|
-
}
|
|
14
|
+
}
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export default meta
|
|
20
18
|
type Story = StoryObj<typeof LibFileInput>
|
|
21
19
|
|
|
22
|
-
|
|
23
20
|
export const SingleFile: Story = {
|
|
24
21
|
render: args => ({
|
|
25
22
|
components,
|
|
@@ -32,16 +29,16 @@ export const SingleFile: Story = {
|
|
|
32
29
|
},
|
|
33
30
|
template: `
|
|
34
31
|
<lib-file-input v-bind="{...args}" @errors="errorHandler"></lib-file-input>
|
|
35
|
-
|
|
36
|
-
})
|
|
32
|
+
`
|
|
33
|
+
})
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
export const MultipleFile: Story = {
|
|
40
37
|
...SingleFile,
|
|
41
38
|
args: {
|
|
42
39
|
...SingleFile.args,
|
|
43
|
-
multiple: true
|
|
44
|
-
}
|
|
40
|
+
multiple: true
|
|
41
|
+
}
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
export const AnyFormat: Story = {
|
|
@@ -49,16 +46,16 @@ export const AnyFormat: Story = {
|
|
|
49
46
|
args: {
|
|
50
47
|
...SingleFile.args,
|
|
51
48
|
multiple: true,
|
|
52
|
-
formats: []
|
|
53
|
-
}
|
|
49
|
+
formats: []
|
|
50
|
+
}
|
|
54
51
|
}
|
|
55
52
|
|
|
56
53
|
export const Compact: Story = {
|
|
57
54
|
...SingleFile,
|
|
58
55
|
args: {
|
|
59
56
|
...SingleFile.args,
|
|
60
|
-
compact: true
|
|
61
|
-
}
|
|
57
|
+
compact: true
|
|
58
|
+
}
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
export const ErrorHandling: Story = {
|
|
@@ -68,12 +65,12 @@ export const ErrorHandling: Story = {
|
|
|
68
65
|
const errors = ref([])
|
|
69
66
|
const errorHandler = (e: any) => errors.value = e
|
|
70
67
|
return {
|
|
71
|
-
args, errors, errorHandler
|
|
68
|
+
args, errors, errorHandler
|
|
72
69
|
}
|
|
73
70
|
},
|
|
74
71
|
template: `
|
|
75
72
|
<lib-debug :title="'Errors'">{{errors}}</lib-debug>
|
|
76
73
|
<lib-file-input v-bind="{...args}" @errors="errorHandler"></lib-file-input>
|
|
77
|
-
|
|
78
|
-
})
|
|
74
|
+
`
|
|
75
|
+
})
|
|
79
76
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<!-- todo aria errors -->
|
|
3
|
-
<div
|
|
3
|
+
<div
|
|
4
|
+
:class="twMerge(`file-input
|
|
4
5
|
justify-center
|
|
5
6
|
border-2
|
|
6
7
|
border-dashed
|
|
@@ -8,25 +9,26 @@
|
|
|
8
9
|
focus-outline-within
|
|
9
10
|
transition-[border-color,box-shadow]
|
|
10
11
|
ease-out`,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
compact && `rounded-sm`,
|
|
13
|
+
!compact && `flex w-full flex-col items-center gap-2 rounded-xl p-2 `,
|
|
14
|
+
errors.length > 0 && errorFlashing && `border-danger-400`,
|
|
15
|
+
($.wrapperAttrs as any).class
|
|
15
16
|
)"
|
|
16
|
-
v-bind="{...$.wrapperAttrs, class:undefined}"
|
|
17
|
+
v-bind="{ ...$.wrapperAttrs, class: undefined }"
|
|
17
18
|
>
|
|
18
|
-
<div
|
|
19
|
+
<div
|
|
20
|
+
:class="twMerge(`
|
|
19
21
|
file-input--wrapper
|
|
20
22
|
relative justify-center`,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
compact && `flex gap-2`,
|
|
24
|
+
!compact && `input-wrapper
|
|
23
25
|
flex flex-col items-center
|
|
24
26
|
`
|
|
25
|
-
|
|
27
|
+
)"
|
|
26
28
|
>
|
|
27
29
|
<label
|
|
28
30
|
:for="id ?? fallbackId"
|
|
29
|
-
:class="twMerge(
|
|
31
|
+
:class="twMerge(`
|
|
30
32
|
file-input--label
|
|
31
33
|
pointer-events-none
|
|
32
34
|
flex
|
|
@@ -35,7 +37,10 @@
|
|
|
35
37
|
whitespace-nowrap
|
|
36
38
|
`)"
|
|
37
39
|
>
|
|
38
|
-
<slot
|
|
40
|
+
<slot
|
|
41
|
+
v-if="compact || multiple || files.length === 0"
|
|
42
|
+
name="icon"
|
|
43
|
+
>
|
|
39
44
|
<icon><i-fa6-solid-arrow-up-from-bracket/></icon>
|
|
40
45
|
</slot>
|
|
41
46
|
<slot name="label">
|
|
@@ -57,7 +62,10 @@
|
|
|
57
62
|
{{ ` (${files.length})` }}
|
|
58
63
|
</span>
|
|
59
64
|
</label>
|
|
60
|
-
<label
|
|
65
|
+
<label
|
|
66
|
+
v-if="!compact && formats?.length > 0"
|
|
67
|
+
class="file-input--formats-label flex flex-col items-center text-sm"
|
|
68
|
+
>
|
|
61
69
|
<slot name="formats">{{ t("file-input.accepted-formats") }}: </slot>
|
|
62
70
|
<div class="file-input--formats-list">
|
|
63
71
|
{{ extensions.join(", ") }}
|
|
@@ -80,13 +88,14 @@
|
|
|
80
88
|
:accept="formats.join(', ')"
|
|
81
89
|
:multiple="multiple"
|
|
82
90
|
ref="el"
|
|
83
|
-
v-bind="{...$.inputAttrs, class:undefined}"
|
|
91
|
+
v-bind="{ ...$.inputAttrs, class: undefined }"
|
|
84
92
|
@input="(inputFile as any)"
|
|
85
93
|
@click="($event.target! as any).value = null"
|
|
86
94
|
>
|
|
87
95
|
<!-- click event allows event to fire even if the user picks the same file -->
|
|
88
96
|
</div>
|
|
89
|
-
<div
|
|
97
|
+
<div
|
|
98
|
+
v-if="!compact && files.length > 0"
|
|
90
99
|
:class="twMerge(`file-input--previews
|
|
91
100
|
flex items-stretch justify-center gap-2 flex-wrap
|
|
92
101
|
`,
|
|
@@ -97,7 +106,8 @@
|
|
|
97
106
|
)"
|
|
98
107
|
>
|
|
99
108
|
<div class="file-input--preview-spacer flex-1"/>
|
|
100
|
-
<div
|
|
109
|
+
<div
|
|
110
|
+
class="file-input--preview-wrapper
|
|
101
111
|
z-1
|
|
102
112
|
relative
|
|
103
113
|
flex
|
|
@@ -124,16 +134,21 @@
|
|
|
124
134
|
</div>
|
|
125
135
|
|
|
126
136
|
<div class="file-input--preview flex flex-initial basis-full justify-center">
|
|
127
|
-
<div
|
|
137
|
+
<div
|
|
138
|
+
v-if="entry.isImg"
|
|
128
139
|
class="file-input--preview-image
|
|
129
140
|
bg-transparency-squares flex
|
|
130
141
|
h-[80px] flex-wrap items-center
|
|
131
142
|
justify-center
|
|
132
143
|
"
|
|
133
144
|
>
|
|
134
|
-
<img
|
|
145
|
+
<img
|
|
146
|
+
class="max-h-full w-auto"
|
|
147
|
+
:src="getSrc(entry.file)"
|
|
148
|
+
>
|
|
135
149
|
</div>
|
|
136
|
-
<div
|
|
150
|
+
<div
|
|
151
|
+
v-if="!entry.isImg"
|
|
137
152
|
class="file-input--preview-no-image
|
|
138
153
|
flex h-[80px]
|
|
139
154
|
flex-1 basis-full flex-wrap items-center justify-center
|
|
@@ -142,7 +157,8 @@
|
|
|
142
157
|
<icon><i-fa6-regular-file class="text-4xl opacity-50"/></icon>
|
|
143
158
|
</div>
|
|
144
159
|
</div>
|
|
145
|
-
<div
|
|
160
|
+
<div
|
|
161
|
+
class="
|
|
146
162
|
file-input--preview-filename
|
|
147
163
|
min-w-0
|
|
148
164
|
flex-1
|
|
@@ -163,8 +179,9 @@
|
|
|
163
179
|
</div>
|
|
164
180
|
</div>
|
|
165
181
|
</template>
|
|
182
|
+
|
|
166
183
|
<script setup lang="ts">
|
|
167
|
-
import { computed, type HTMLAttributes, type InputHTMLAttributes,ref, shallowReactive, watch } from "vue"
|
|
184
|
+
import { computed, type HTMLAttributes, type InputHTMLAttributes, ref, shallowReactive, watch } from "vue"
|
|
168
185
|
|
|
169
186
|
import IFa6RegularFile from "~icons/fa6-regular/file"
|
|
170
187
|
import IFa6SolidArrowUpFromBracket from "~icons/fa6-solid/arrow-up-from-bracket"
|
|
@@ -172,11 +189,11 @@ import IFa6SolidXmark from "~icons/fa6-solid/xmark"
|
|
|
172
189
|
|
|
173
190
|
import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
|
|
174
191
|
import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
|
|
175
|
-
import {
|
|
192
|
+
import type { FileInputError } from "../../types/index.js"
|
|
176
193
|
import { twMerge } from "../../utils/twMerge.js"
|
|
177
194
|
import Icon from "../Icon/Icon.vue"
|
|
178
195
|
import LibButton from "../LibButton/LibButton.vue"
|
|
179
|
-
import { getFallbackId,type LinkableByIdProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
|
|
196
|
+
import { getFallbackId, type LinkableByIdProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
|
|
180
197
|
|
|
181
198
|
const t = useInjectedI18n()
|
|
182
199
|
const el = ref<null | HTMLInputElement>(null)
|
|
@@ -200,11 +217,11 @@ watch(errors, () => {
|
|
|
200
217
|
})
|
|
201
218
|
|
|
202
219
|
defineOptions({
|
|
203
|
-
name: "
|
|
204
|
-
inheritAttrs: false
|
|
220
|
+
name: "LibFileInput",
|
|
221
|
+
inheritAttrs: false
|
|
205
222
|
})
|
|
206
223
|
const $ = useDivideAttrs(["wrapper", "input", "previews"] as const)
|
|
207
|
-
|
|
224
|
+
|
|
208
225
|
const emits = defineEmits<{
|
|
209
226
|
(e: "input", val: File[]): void
|
|
210
227
|
(e: "errors", val: FileInputError[]): void
|
|
@@ -214,7 +231,7 @@ const fallbackId = getFallbackId()
|
|
|
214
231
|
const props = withDefaults(defineProps<Props>(), {
|
|
215
232
|
multiple: false,
|
|
216
233
|
formats: () => ["image/*", ".jpeg", ".jpg", ".png"],
|
|
217
|
-
compact: false
|
|
234
|
+
compact: false
|
|
218
235
|
})
|
|
219
236
|
|
|
220
237
|
const mimeTypes = computed(() => props.formats?.filter(_ => !_.startsWith(".")) ?? [])
|
|
@@ -230,7 +247,7 @@ const removeFile = (entry: Entry) => {
|
|
|
230
247
|
files.splice(index, 1)
|
|
231
248
|
}
|
|
232
249
|
const extensionsList = computed(() => extensions.value.join(", "))
|
|
233
|
-
const inputFile = async (e: InputEvent): Promise<
|
|
250
|
+
const inputFile = async (e: InputEvent): Promise<undefined | boolean> => {
|
|
234
251
|
e.preventDefault()
|
|
235
252
|
if (el.value!.files) {
|
|
236
253
|
const errs = []
|
|
@@ -268,34 +285,35 @@ const inputFile = async (e: InputEvent): Promise<void | boolean> => {
|
|
|
268
285
|
errors.splice(0, errors.length)
|
|
269
286
|
}
|
|
270
287
|
}
|
|
288
|
+
return undefined
|
|
271
289
|
}
|
|
272
|
-
|
|
273
290
|
</script>
|
|
291
|
+
|
|
274
292
|
<script lang="ts">
|
|
275
|
-
export default { name: "
|
|
293
|
+
export default { name: "LibFileInput" }
|
|
276
294
|
|
|
277
|
-
type WrapperTypes
|
|
278
|
-
& WrapperProps<"input", InputHTMLAttributes
|
|
279
|
-
|
|
280
|
-
|
|
295
|
+
type WrapperTypes
|
|
296
|
+
= & WrapperProps<"input", InputHTMLAttributes>
|
|
297
|
+
& WrapperProps<"wrapper", HTMLAttributes>
|
|
298
|
+
& WrapperProps<"previews", HTMLAttributes>
|
|
281
299
|
|
|
282
|
-
type RealProps
|
|
283
|
-
& LinkableByIdProps
|
|
284
|
-
& {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
300
|
+
type RealProps
|
|
301
|
+
= & LinkableByIdProps
|
|
302
|
+
& {
|
|
303
|
+
multiple?: boolean
|
|
304
|
+
/**
|
|
305
|
+
* A list of extensions or mime types to add to the input's accept. Basic validations are done so that files match an extension and mimeType, but note that a file could still be lying, all files should be validated server side.
|
|
306
|
+
*
|
|
307
|
+
* Pass an empty array to allow any filetype.
|
|
308
|
+
*/
|
|
309
|
+
formats?: string[]
|
|
310
|
+
compact?: boolean
|
|
311
|
+
}
|
|
294
312
|
|
|
295
313
|
interface Props
|
|
296
314
|
extends
|
|
297
315
|
/** @vue-ignore */
|
|
298
|
-
Partial<Omit<InputHTMLAttributes,"class" | "multiple" | "formats" | "compact"> & TailwindClassProp>,
|
|
316
|
+
Partial<Omit<InputHTMLAttributes, "class" | "multiple" | "formats" | "compact"> & TailwindClassProp>,
|
|
299
317
|
/** @vue-ignore */
|
|
300
318
|
Partial<WrapperTypes>,
|
|
301
319
|
RealProps { }
|