@mekari/pixel3-dropzone 0.0.1

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.
@@ -0,0 +1,83 @@
1
+ // src/modules/dropzone.props.ts
2
+ var dropzoneProps = {
3
+ id: {
4
+ type: String,
5
+ default: ""
6
+ },
7
+ variant: {
8
+ type: String,
9
+ default: "default"
10
+ },
11
+ accept: {
12
+ type: String
13
+ },
14
+ name: {
15
+ type: String
16
+ },
17
+ placeholder: {
18
+ type: String,
19
+ default: "Drop your file(s) here or "
20
+ },
21
+ description: {
22
+ type: String,
23
+ default: "Description of dropzone"
24
+ },
25
+ loadingText: {
26
+ type: String,
27
+ default: "Uploading..."
28
+ },
29
+ buttonText: {
30
+ type: String,
31
+ default: "Change file"
32
+ },
33
+ overlayVariant: {
34
+ type: String,
35
+ default: "white"
36
+ },
37
+ isShowPreview: {
38
+ type: Boolean,
39
+ default: true
40
+ },
41
+ isMultiple: {
42
+ type: Boolean,
43
+ default: false
44
+ },
45
+ isLoading: {
46
+ type: Boolean,
47
+ default: false
48
+ },
49
+ isDisabled: {
50
+ type: Boolean,
51
+ default: false
52
+ },
53
+ isInvalid: {
54
+ type: Boolean,
55
+ default: false
56
+ },
57
+ isRequired: {
58
+ type: Boolean,
59
+ default: false
60
+ },
61
+ hasCustomUpload: {
62
+ type: Boolean,
63
+ default: false
64
+ },
65
+ isEnableDragAndDrop: {
66
+ type: Boolean,
67
+ default: true
68
+ },
69
+ isEnableInputFile: {
70
+ type: Boolean,
71
+ default: false
72
+ },
73
+ isShowOverlay: {
74
+ type: Boolean,
75
+ default: false
76
+ }
77
+ };
78
+ var dropzoneEmit = ["click", "dragover", "dragleave", "drop", "change", "clear", "cancel"];
79
+
80
+ export {
81
+ dropzoneProps,
82
+ dropzoneEmit
83
+ };
@@ -0,0 +1,123 @@
1
+ import {
2
+ useDropzone
3
+ } from "./chunk-PB3KHIIV.mjs";
4
+ import {
5
+ dropzoneEmit,
6
+ dropzoneProps
7
+ } from "./chunk-CQO276YD.mjs";
8
+ import {
9
+ __name
10
+ } from "./chunk-QZ7VFGWC.mjs";
11
+
12
+ // src/dropzone.tsx
13
+ import { createTextVNode as _createTextVNode, createVNode as _createVNode, isVNode as _isVNode } from "vue";
14
+ import { defineComponent } from "vue";
15
+ import { MpText } from "@mekari/pixel3-text";
16
+ import { MpIcon } from "@mekari/pixel3-icon";
17
+ import { MpSpinner } from "@mekari/pixel3-spinner";
18
+ function _isSlot(s) {
19
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !_isVNode(s);
20
+ }
21
+ __name(_isSlot, "_isSlot");
22
+ var MpDropzone = defineComponent({
23
+ name: "MpDropzone",
24
+ props: dropzoneProps,
25
+ emits: dropzoneEmit,
26
+ setup(props, {
27
+ emit,
28
+ slots
29
+ }) {
30
+ const {
31
+ rootAttrs,
32
+ wrapperAttrs,
33
+ boxAttrs,
34
+ logoBoxAttrs,
35
+ productBoxAttrs,
36
+ avatarBoxAttrs,
37
+ overlayWrapperAttrs,
38
+ overlayAttrs,
39
+ inputAttrs,
40
+ imageAttrs,
41
+ cancelButtonAttrs,
42
+ browseButtonAttrs,
43
+ previewAttrs,
44
+ overlayPreviewAttrs,
45
+ clearButtonAttrs,
46
+ hasPreview
47
+ } = useDropzone(props, emit);
48
+ return () => {
49
+ const children = slots.default && slots.default();
50
+ const {
51
+ variant,
52
+ placeholder,
53
+ description,
54
+ buttonText,
55
+ loadingText,
56
+ overlayVariant,
57
+ isLoading,
58
+ isInvalid
59
+ } = props;
60
+ return _createVNode("div", rootAttrs.value, [children ? _createVNode("div", overlayWrapperAttrs.value, [_createVNode("div", overlayAttrs.value, [_createVNode(MpText, {
61
+ "weight": "semiBold",
62
+ "color": overlayVariant === "white" ? "dark" : "white"
63
+ }, _isSlot(placeholder) ? placeholder : {
64
+ default: () => [placeholder]
65
+ }), _createVNode(MpText, {
66
+ "color": overlayVariant === "white" ? "dark" : "white"
67
+ }, _isSlot(description) ? description : {
68
+ default: () => [description]
69
+ })]), children]) : _createVNode("div", wrapperAttrs.value, [isLoading && _createVNode("div", boxAttrs.value, [_createVNode(MpSpinner, null, null), variant !== "avatar" && _createVNode(MpText, {
70
+ "color": "gray.600"
71
+ }, _isSlot(loadingText) ? loadingText : {
72
+ default: () => [loadingText]
73
+ }), variant === "default" && _createVNode(MpText, cancelButtonAttrs.value, {
74
+ default: () => [_createTextVNode("Cancel")]
75
+ })]), !isLoading && hasPreview.value && _createVNode("div", previewAttrs.value, [_createVNode(MpIcon, clearButtonAttrs.value, null), _createVNode("div", overlayPreviewAttrs.value, [_createVNode(MpIcon, {
76
+ "name": "folder-open",
77
+ "variant": "fill",
78
+ "color": "white"
79
+ }, null), variant !== "avatar" && _createVNode(MpText, {
80
+ "color": "white"
81
+ }, _isSlot(buttonText) ? buttonText : {
82
+ default: () => [buttonText]
83
+ })]), _createVNode("img", imageAttrs.value, null)]), !isLoading && !hasPreview.value && variant === "default" && _createVNode("div", boxAttrs.value, [_createVNode(MpIcon, {
84
+ "name": "upload",
85
+ "variant": isInvalid ? "outline" : "duotone",
86
+ "color": isInvalid ? "red.400" : "gray.600"
87
+ }, null), _createVNode(MpText, null, {
88
+ default: () => [placeholder, _createVNode(MpText, browseButtonAttrs.value, {
89
+ default: () => [_createTextVNode("Browse")]
90
+ })]
91
+ }), _createVNode(MpText, {
92
+ "color": "gray.600"
93
+ }, _isSlot(description) ? description : {
94
+ default: () => [description]
95
+ })]), !isLoading && !hasPreview.value && variant === "logo" && _createVNode("div", logoBoxAttrs.value, [_createVNode(MpIcon, {
96
+ "name": "img",
97
+ "variant": isInvalid ? "fill" : "outline",
98
+ "color": isInvalid ? "red.400" : "gray.600"
99
+ }, null), _createVNode(MpText, {
100
+ "color": isInvalid ? "red.400" : "gray.600"
101
+ }, _isSlot(placeholder) ? placeholder : {
102
+ default: () => [placeholder]
103
+ })]), !isLoading && !hasPreview.value && variant === "product" && _createVNode("div", productBoxAttrs.value, [_createVNode(MpIcon, {
104
+ "name": "add-circular",
105
+ "variant": isInvalid ? "fill" : "outline",
106
+ "color": isInvalid ? "red.400" : "gray.600"
107
+ }, null), _createVNode(MpText, {
108
+ "color": isInvalid ? "red.400" : "gray.600"
109
+ }, _isSlot(placeholder) ? placeholder : {
110
+ default: () => [placeholder]
111
+ })]), !isLoading && !hasPreview.value && variant === "avatar" && _createVNode("div", avatarBoxAttrs.value, [_createVNode(MpText, {
112
+ "size": "h1",
113
+ "color": isInvalid ? "red.400" : "gray.600"
114
+ }, _isSlot(placeholder) ? placeholder : {
115
+ default: () => [placeholder]
116
+ })])]), _createVNode("input", inputAttrs.value, null)]);
117
+ };
118
+ }
119
+ });
120
+
121
+ export {
122
+ MpDropzone
123
+ };
@@ -0,0 +1,291 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-QZ7VFGWC.mjs";
4
+
5
+ // src/modules/dropzone.hooks.ts
6
+ import { computed, ref, toRefs } from "vue";
7
+ import { getUniqueId } from "@mekari/pixel3-utils";
8
+ import { dropzoneSlotRecipe, sharedSlotRecipe } from "@mekari/pixel3-styled-system/recipes";
9
+ function useDropzone(props, emit) {
10
+ const {
11
+ id,
12
+ variant,
13
+ name,
14
+ accept,
15
+ isMultiple,
16
+ hasCustomUpload,
17
+ overlayVariant,
18
+ isEnableInputFile,
19
+ isEnableDragAndDrop,
20
+ isShowPreview,
21
+ isShowOverlay,
22
+ isLoading,
23
+ isInvalid,
24
+ isDisabled,
25
+ isRequired
26
+ } = toRefs(props);
27
+ const files = ref();
28
+ const fileInput = ref();
29
+ const preview = ref("");
30
+ const showOverlay = ref(isShowOverlay.value);
31
+ const overlay = ref();
32
+ const getId = id.value || getUniqueId("", "dropzone").value;
33
+ const hasPreview = computed(() => {
34
+ return isShowPreview.value && preview.value;
35
+ });
36
+ const rootAttrs = computed(() => {
37
+ return {
38
+ "data-pixel-component": "MpDropzone",
39
+ id: getId,
40
+ class: dropzoneSlotRecipe().root,
41
+ onClick: handleClick,
42
+ onDragover: handleDragover,
43
+ onDragleave: handleDragleave,
44
+ onDrop: handleDrop
45
+ };
46
+ });
47
+ const wrapperAttrs = computed(() => {
48
+ return {
49
+ "data-invalid": isInvalid.value || void 0,
50
+ "data-disabled": isDisabled.value || void 0,
51
+ "data-variant": variant.value,
52
+ tabindex: isDisabled.value ? -1 : 0,
53
+ class: dropzoneSlotRecipe().wrapper,
54
+ style: {
55
+ background: variant.value === "default" ? "var(--mp-colors-white)" : "var(--mp-colors-background)",
56
+ borderRadius: variant.value === "avatar" ? "var(--mp-radii-full)" : "var(--mp-radii-md)"
57
+ }
58
+ };
59
+ });
60
+ const boxAttrs = computed(() => {
61
+ return {
62
+ class: dropzoneSlotRecipe().box
63
+ };
64
+ });
65
+ const logoBoxAttrs = computed(() => {
66
+ return {
67
+ class: dropzoneSlotRecipe().logoBox,
68
+ onClick: handleClickInput
69
+ };
70
+ });
71
+ const productBoxAttrs = computed(() => {
72
+ return {
73
+ class: dropzoneSlotRecipe().productBox,
74
+ onClick: handleClickInput
75
+ };
76
+ });
77
+ const avatarBoxAttrs = computed(() => {
78
+ return {
79
+ class: dropzoneSlotRecipe().avatarBox,
80
+ onClick: handleClickInput
81
+ };
82
+ });
83
+ const overlayWrapperAttrs = computed(() => {
84
+ return {
85
+ class: dropzoneSlotRecipe().overlayWrapper
86
+ };
87
+ });
88
+ const overlayAttrs = computed(() => {
89
+ return {
90
+ ref: overlay,
91
+ class: dropzoneSlotRecipe().overlay,
92
+ style: {
93
+ display: showOverlay.value ? "flex" : "none",
94
+ background: overlayVariant.value === "white" ? "var(--mp-colors-whiteAlpha.300)" : "var(--mp-colors-overlay)"
95
+ }
96
+ };
97
+ });
98
+ const inputAttrs = computed(() => {
99
+ return {
100
+ ref: fileInput,
101
+ id: `input-${getId}`,
102
+ class: sharedSlotRecipe().hidden,
103
+ type: "file",
104
+ name: name == null ? void 0 : name.value,
105
+ accept: accept == null ? void 0 : accept.value,
106
+ multiple: isMultiple.value,
107
+ disabled: isDisabled.value,
108
+ required: isRequired.value,
109
+ onChange: handleChangeInput
110
+ };
111
+ });
112
+ const cancelButtonAttrs = computed(() => {
113
+ return {
114
+ color: "red.400",
115
+ style: {
116
+ cursor: "pointer"
117
+ },
118
+ onClick: handleCancel
119
+ };
120
+ });
121
+ const browseButtonAttrs = computed(() => {
122
+ return {
123
+ as: "span",
124
+ weight: "semiBold",
125
+ color: "blue.400",
126
+ style: {
127
+ cursor: "pointer"
128
+ },
129
+ onClick: handleClickInput
130
+ };
131
+ });
132
+ const previewAttrs = computed(() => {
133
+ return {
134
+ class: dropzoneSlotRecipe().preview
135
+ };
136
+ });
137
+ const overlayPreviewAttrs = computed(() => {
138
+ return {
139
+ "data-overlay-preview": true,
140
+ class: dropzoneSlotRecipe().overlayPreview,
141
+ onClick: handleClickInput
142
+ };
143
+ });
144
+ const imageAttrs = computed(() => {
145
+ return {
146
+ src: preview.value,
147
+ style: {
148
+ borderRadius: "inherit",
149
+ height: "100%",
150
+ objectFit: "cover"
151
+ }
152
+ };
153
+ });
154
+ const clearButtonAttrs = computed(() => {
155
+ return {
156
+ class: dropzoneSlotRecipe().clearButton,
157
+ name: "minus-circular",
158
+ variant: "fill",
159
+ color: "red.400",
160
+ style: {
161
+ top: variant.value === "avatar" ? "-4px" : "-10px",
162
+ right: variant.value === "avatar" ? "-4px" : "-10px"
163
+ },
164
+ onClick: handleClear
165
+ };
166
+ });
167
+ function handleClick(e) {
168
+ if (!isEnableInputFile.value) {
169
+ return;
170
+ }
171
+ handleClickInput();
172
+ emit("click", e);
173
+ }
174
+ __name(handleClick, "handleClick");
175
+ function handleClickInput() {
176
+ if (isDisabled.value) {
177
+ return;
178
+ }
179
+ files.value = null;
180
+ fileInput.value.value = null;
181
+ fileInput.value.click();
182
+ }
183
+ __name(handleClickInput, "handleClickInput");
184
+ function handleDragover(e) {
185
+ e.preventDefault();
186
+ if (!isEnableDragAndDrop.value) {
187
+ return;
188
+ }
189
+ emit("dragover", e);
190
+ if (hasCustomUpload.value) {
191
+ showOverlay.value = true;
192
+ }
193
+ }
194
+ __name(handleDragover, "handleDragover");
195
+ function handleDragleave(e) {
196
+ if (!isEnableDragAndDrop.value) {
197
+ return;
198
+ }
199
+ emit("dragleave", e);
200
+ if (e.target === overlay.value) {
201
+ showOverlay.value = false;
202
+ }
203
+ }
204
+ __name(handleDragleave, "handleDragleave");
205
+ function handleDrop(e) {
206
+ e.preventDefault();
207
+ if (!isEnableDragAndDrop.value) {
208
+ return;
209
+ }
210
+ emit("drop", e);
211
+ const target = e.dataTransfer;
212
+ if (target && target.files) {
213
+ const {
214
+ files: files2
215
+ } = target;
216
+ handleFiles(files2);
217
+ }
218
+ if (hasCustomUpload.value) {
219
+ showOverlay.value = false;
220
+ }
221
+ }
222
+ __name(handleDrop, "handleDrop");
223
+ function handleChangeInput(e) {
224
+ const target = e.target;
225
+ if (target && target.files) {
226
+ const {
227
+ files: files2
228
+ } = target;
229
+ handleFiles(files2);
230
+ }
231
+ }
232
+ __name(handleChangeInput, "handleChangeInput");
233
+ function handleFiles(item) {
234
+ if (isDisabled.value) {
235
+ return;
236
+ }
237
+ if (item && item.length > 0) {
238
+ files.value = item;
239
+ }
240
+ emit("change", files.value);
241
+ if (files.value && files.value.length === 1) {
242
+ handlePreview(files.value[0]);
243
+ }
244
+ }
245
+ __name(handleFiles, "handleFiles");
246
+ function handlePreview(item) {
247
+ if (isLoading.value) {
248
+ return;
249
+ }
250
+ const REGEXP_MIME_TYPE_IMAGES = /^image\/\w+$/;
251
+ if (REGEXP_MIME_TYPE_IMAGES.test(item.type)) {
252
+ preview.value = URL.createObjectURL(item);
253
+ }
254
+ }
255
+ __name(handlePreview, "handlePreview");
256
+ function handleClear(e) {
257
+ e.stopPropagation();
258
+ emit("clear", e);
259
+ files.value = null;
260
+ preview.value = "";
261
+ }
262
+ __name(handleClear, "handleClear");
263
+ function handleCancel(e) {
264
+ e.stopPropagation();
265
+ emit("cancel", e);
266
+ }
267
+ __name(handleCancel, "handleCancel");
268
+ return {
269
+ rootAttrs,
270
+ wrapperAttrs,
271
+ boxAttrs,
272
+ logoBoxAttrs,
273
+ productBoxAttrs,
274
+ avatarBoxAttrs,
275
+ overlayWrapperAttrs,
276
+ overlayAttrs,
277
+ inputAttrs,
278
+ imageAttrs,
279
+ cancelButtonAttrs,
280
+ browseButtonAttrs,
281
+ previewAttrs,
282
+ overlayPreviewAttrs,
283
+ clearButtonAttrs,
284
+ hasPreview
285
+ };
286
+ }
287
+ __name(useDropzone, "useDropzone");
288
+
289
+ export {
290
+ useDropzone
291
+ };
@@ -0,0 +1,6 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ export {
5
+ __name
6
+ };
@@ -0,0 +1,176 @@
1
+ import * as vue_jsx_runtime from 'vue/jsx-runtime';
2
+ import * as vue from 'vue';
3
+
4
+ declare const MpDropzone: vue.DefineComponent<{
5
+ id: {
6
+ type: vue.PropType<string>;
7
+ default: string;
8
+ };
9
+ variant: {
10
+ type: vue.PropType<"default" | "logo" | "product" | "avatar">;
11
+ default: string;
12
+ };
13
+ accept: {
14
+ type: vue.PropType<string>;
15
+ };
16
+ name: {
17
+ type: vue.PropType<string>;
18
+ };
19
+ placeholder: {
20
+ type: vue.PropType<string>;
21
+ default: string;
22
+ };
23
+ description: {
24
+ type: vue.PropType<string>;
25
+ default: string;
26
+ };
27
+ loadingText: {
28
+ type: vue.PropType<string>;
29
+ default: string;
30
+ };
31
+ buttonText: {
32
+ type: vue.PropType<string>;
33
+ default: string;
34
+ };
35
+ overlayVariant: {
36
+ type: vue.PropType<"white" | "black">;
37
+ default: string;
38
+ };
39
+ isShowPreview: {
40
+ type: vue.PropType<boolean>;
41
+ default: boolean;
42
+ };
43
+ isMultiple: {
44
+ type: vue.PropType<boolean>;
45
+ default: boolean;
46
+ };
47
+ isLoading: {
48
+ type: vue.PropType<boolean>;
49
+ default: boolean;
50
+ };
51
+ isDisabled: {
52
+ type: vue.PropType<boolean>;
53
+ default: boolean;
54
+ };
55
+ isInvalid: {
56
+ type: vue.PropType<boolean>;
57
+ default: boolean;
58
+ };
59
+ isRequired: {
60
+ type: vue.PropType<boolean>;
61
+ default: boolean;
62
+ };
63
+ hasCustomUpload: {
64
+ type: vue.PropType<boolean>;
65
+ default: boolean;
66
+ };
67
+ isEnableDragAndDrop: {
68
+ type: vue.PropType<boolean>;
69
+ default: boolean;
70
+ };
71
+ isEnableInputFile: {
72
+ type: vue.PropType<boolean>;
73
+ default: boolean;
74
+ };
75
+ isShowOverlay: {
76
+ type: vue.PropType<boolean>;
77
+ default: boolean;
78
+ };
79
+ }, () => vue_jsx_runtime.JSX.Element, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, string[], string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
80
+ id: {
81
+ type: vue.PropType<string>;
82
+ default: string;
83
+ };
84
+ variant: {
85
+ type: vue.PropType<"default" | "logo" | "product" | "avatar">;
86
+ default: string;
87
+ };
88
+ accept: {
89
+ type: vue.PropType<string>;
90
+ };
91
+ name: {
92
+ type: vue.PropType<string>;
93
+ };
94
+ placeholder: {
95
+ type: vue.PropType<string>;
96
+ default: string;
97
+ };
98
+ description: {
99
+ type: vue.PropType<string>;
100
+ default: string;
101
+ };
102
+ loadingText: {
103
+ type: vue.PropType<string>;
104
+ default: string;
105
+ };
106
+ buttonText: {
107
+ type: vue.PropType<string>;
108
+ default: string;
109
+ };
110
+ overlayVariant: {
111
+ type: vue.PropType<"white" | "black">;
112
+ default: string;
113
+ };
114
+ isShowPreview: {
115
+ type: vue.PropType<boolean>;
116
+ default: boolean;
117
+ };
118
+ isMultiple: {
119
+ type: vue.PropType<boolean>;
120
+ default: boolean;
121
+ };
122
+ isLoading: {
123
+ type: vue.PropType<boolean>;
124
+ default: boolean;
125
+ };
126
+ isDisabled: {
127
+ type: vue.PropType<boolean>;
128
+ default: boolean;
129
+ };
130
+ isInvalid: {
131
+ type: vue.PropType<boolean>;
132
+ default: boolean;
133
+ };
134
+ isRequired: {
135
+ type: vue.PropType<boolean>;
136
+ default: boolean;
137
+ };
138
+ hasCustomUpload: {
139
+ type: vue.PropType<boolean>;
140
+ default: boolean;
141
+ };
142
+ isEnableDragAndDrop: {
143
+ type: vue.PropType<boolean>;
144
+ default: boolean;
145
+ };
146
+ isEnableInputFile: {
147
+ type: vue.PropType<boolean>;
148
+ default: boolean;
149
+ };
150
+ isShowOverlay: {
151
+ type: vue.PropType<boolean>;
152
+ default: boolean;
153
+ };
154
+ }>> & {
155
+ [x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
156
+ }, {
157
+ id: string;
158
+ variant: "default" | "logo" | "product" | "avatar";
159
+ placeholder: string;
160
+ description: string;
161
+ loadingText: string;
162
+ buttonText: string;
163
+ overlayVariant: "white" | "black";
164
+ isShowPreview: boolean;
165
+ isMultiple: boolean;
166
+ isLoading: boolean;
167
+ isDisabled: boolean;
168
+ isInvalid: boolean;
169
+ isRequired: boolean;
170
+ hasCustomUpload: boolean;
171
+ isEnableDragAndDrop: boolean;
172
+ isEnableInputFile: boolean;
173
+ isShowOverlay: boolean;
174
+ }, {}>;
175
+
176
+ export { MpDropzone };