@mekari/pixel3-upload 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,257 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-QZ7VFGWC.mjs";
4
+
5
+ // src/modules/upload.hooks.ts
6
+ import { computed, watch, ref, toRefs } from "vue";
7
+ import { getUniqueId } from "@mekari/pixel3-utils";
8
+ import { uploadSlotRecipe, uploadListSlotRecipe, sharedSlotRecipe } from "@mekari/pixel3-styled-system/recipes";
9
+ function useUpload(props, emit) {
10
+ const {
11
+ id,
12
+ fileList,
13
+ placeholder,
14
+ accept,
15
+ name,
16
+ loadingText,
17
+ isLoading,
18
+ isDisabled,
19
+ isInvalid,
20
+ isRequired,
21
+ isResetOnChange,
22
+ isMultiple,
23
+ isFullWidth
24
+ } = toRefs(props);
25
+ const files = ref(fileList == null ? void 0 : fileList.value);
26
+ const fileInput = ref();
27
+ const getId = id.value || getUniqueId("", "upload").value;
28
+ const fileName = computed(() => {
29
+ if (isLoading.value) {
30
+ return loadingText.value;
31
+ } else {
32
+ if (totalFiles.value === 0) {
33
+ return placeholder.value;
34
+ } else if (files.value && totalFiles.value === 1) {
35
+ return files.value[0].name;
36
+ } else {
37
+ return `${totalFiles.value} files`;
38
+ }
39
+ }
40
+ });
41
+ const totalFiles = computed(() => {
42
+ var _a;
43
+ return ((_a = files.value) == null ? void 0 : _a.length) || 0;
44
+ });
45
+ const isShowTooltip = computed(() => {
46
+ var _a;
47
+ return ((_a = files.value) == null ? void 0 : _a.length) === 1;
48
+ });
49
+ const rootAttrs = computed(() => {
50
+ return {
51
+ "data-pixel-component": "MpUpload",
52
+ "data-invalid": isInvalid.value || void 0,
53
+ "data-disabled": isDisabled.value || void 0,
54
+ id: getId,
55
+ tabindex: isDisabled.value ? -1 : 0,
56
+ class: uploadSlotRecipe().root,
57
+ style: {
58
+ maxWidth: isFullWidth.value ? "100%" : "var(--mp-sizes-65)"
59
+ },
60
+ onClick: handleClick
61
+ };
62
+ });
63
+ const buttonAttrs = computed(() => {
64
+ return {
65
+ variant: "secondary",
66
+ size: "sm",
67
+ isDisabled: isDisabled.value
68
+ };
69
+ });
70
+ const textAttrs = computed(() => {
71
+ return {
72
+ color: !isLoading.value && totalFiles.value >= 1 ? "dark" : "gray.400",
73
+ isTruncated: true
74
+ };
75
+ });
76
+ const resetButtonAttrs = computed(() => {
77
+ return {
78
+ class: uploadSlotRecipe().resetButton,
79
+ "aria-label": "reset button",
80
+ name: "reset",
81
+ size: "sm",
82
+ color: "gray.400",
83
+ onClick: handleClear
84
+ };
85
+ });
86
+ const inputAttrs = computed(() => {
87
+ return {
88
+ ref: fileInput,
89
+ id: `input-${getId}`,
90
+ class: sharedSlotRecipe().hidden,
91
+ type: "file",
92
+ name: name == null ? void 0 : name.value,
93
+ accept: accept == null ? void 0 : accept.value,
94
+ multiple: isMultiple.value,
95
+ disabled: isDisabled.value,
96
+ required: isRequired.value,
97
+ onChange: handleChange
98
+ };
99
+ });
100
+ function clear() {
101
+ files.value = void 0;
102
+ fileInput.value.value = "";
103
+ }
104
+ __name(clear, "clear");
105
+ function handleClear(e) {
106
+ e.stopPropagation();
107
+ clear();
108
+ emit("clear", e);
109
+ }
110
+ __name(handleClear, "handleClear");
111
+ function handleChange(e) {
112
+ const target = e.target;
113
+ if (target && target.files) {
114
+ files.value = target.files;
115
+ }
116
+ emit("change", e);
117
+ }
118
+ __name(handleChange, "handleChange");
119
+ function handleClick(e) {
120
+ if (isDisabled.value) {
121
+ return;
122
+ }
123
+ if (isResetOnChange.value) {
124
+ clear();
125
+ }
126
+ fileInput.value.click();
127
+ emit("click", e);
128
+ }
129
+ __name(handleClick, "handleClick");
130
+ watch(() => fileList == null ? void 0 : fileList.value, (newValue) => {
131
+ if (newValue) {
132
+ files.value = newValue;
133
+ }
134
+ });
135
+ return {
136
+ rootAttrs,
137
+ buttonAttrs,
138
+ textAttrs,
139
+ resetButtonAttrs,
140
+ inputAttrs,
141
+ fileName,
142
+ totalFiles,
143
+ isShowTooltip
144
+ };
145
+ }
146
+ __name(useUpload, "useUpload");
147
+ function useUploadList(props, emit) {
148
+ const {
149
+ id,
150
+ status,
151
+ iconName,
152
+ iconColor,
153
+ iconVariant,
154
+ isShowCancelButton,
155
+ isShowDownloadButton,
156
+ isShowRemoveButton
157
+ } = toRefs(props);
158
+ const getId = id.value || getUniqueId("", "upload-list").value;
159
+ const color = computed(() => {
160
+ let title = "dark";
161
+ let subtitle = "gray.600";
162
+ if (status.value === "success") {
163
+ title = "blue.700";
164
+ }
165
+ if (status.value === "error") {
166
+ title = "red.400";
167
+ subtitle = "red.400";
168
+ }
169
+ return {
170
+ title,
171
+ subtitle
172
+ };
173
+ });
174
+ const hasCancelButton = computed(() => {
175
+ return isShowCancelButton.value && status.value === "loading";
176
+ });
177
+ const hasDownloadButton = computed(() => {
178
+ return isShowDownloadButton.value && status.value === "success";
179
+ });
180
+ const hasRemoveButton = computed(() => {
181
+ return isShowRemoveButton.value && (status.value === "success" || status.value === "error");
182
+ });
183
+ const rootAttrs = computed(() => {
184
+ return {
185
+ "data-pixel-component": "MpUploadList",
186
+ id: getId,
187
+ tabindex: 0,
188
+ class: uploadListSlotRecipe().root
189
+ };
190
+ });
191
+ const iconAttrs = computed(() => {
192
+ return {
193
+ size: "md",
194
+ name: status.value === "error" ? "error" : iconName.value,
195
+ color: status.value === "error" ? "red.700" : iconColor.value,
196
+ variant: status.value === "error" ? "duotone" : iconVariant.value
197
+ };
198
+ });
199
+ const titleWrapperAttrs = computed(() => {
200
+ return {
201
+ class: uploadListSlotRecipe().titleWrapper,
202
+ style: {
203
+ cursor: status.value === "success" ? "pointer" : "default"
204
+ },
205
+ onClick: handleClick
206
+ };
207
+ });
208
+ const buttonCancelAttrs = computed(() => {
209
+ return {
210
+ variant: "ghost",
211
+ size: "sm",
212
+ leftIcon: "close",
213
+ onClick: (e) => emit("cancel", e)
214
+ };
215
+ });
216
+ const buttonDownloadAttrs = computed(() => {
217
+ return {
218
+ variant: "ghost",
219
+ size: "sm",
220
+ leftIcon: "download",
221
+ onClick: (e) => emit("download", e)
222
+ };
223
+ });
224
+ const buttonRemoveAttrs = computed(() => {
225
+ return {
226
+ variant: "ghost",
227
+ size: "sm",
228
+ leftIcon: "minus-circular",
229
+ onClick: (e) => emit("remove", e)
230
+ };
231
+ });
232
+ function handleClick(e) {
233
+ if (status.value !== "success") {
234
+ return;
235
+ }
236
+ emit("click", e);
237
+ }
238
+ __name(handleClick, "handleClick");
239
+ return {
240
+ color,
241
+ rootAttrs,
242
+ iconAttrs,
243
+ titleWrapperAttrs,
244
+ buttonCancelAttrs,
245
+ buttonDownloadAttrs,
246
+ buttonRemoveAttrs,
247
+ hasCancelButton,
248
+ hasDownloadButton,
249
+ hasRemoveButton
250
+ };
251
+ }
252
+ __name(useUploadList, "useUploadList");
253
+
254
+ export {
255
+ useUpload,
256
+ useUploadList
257
+ };
@@ -0,0 +1,113 @@
1
+ // src/modules/upload.props.ts
2
+ var uploadProps = {
3
+ id: {
4
+ type: String,
5
+ default: ""
6
+ },
7
+ fileList: {
8
+ type: Array
9
+ },
10
+ accept: {
11
+ type: String
12
+ },
13
+ name: {
14
+ type: String
15
+ },
16
+ placeholder: {
17
+ type: String,
18
+ default: "No file selected"
19
+ },
20
+ loadingText: {
21
+ type: String,
22
+ default: "Uploading..."
23
+ },
24
+ buttonCaption: {
25
+ type: String,
26
+ default: "Choose file"
27
+ },
28
+ value: {
29
+ type: String
30
+ },
31
+ modelValue: {
32
+ type: String
33
+ },
34
+ isLoading: {
35
+ type: Boolean,
36
+ default: false
37
+ },
38
+ isDisabled: {
39
+ type: Boolean,
40
+ default: false
41
+ },
42
+ isInvalid: {
43
+ type: Boolean,
44
+ default: false
45
+ },
46
+ isRequired: {
47
+ type: Boolean,
48
+ default: false
49
+ },
50
+ isResetOnChange: {
51
+ type: Boolean,
52
+ default: false
53
+ },
54
+ isMultiple: {
55
+ type: Boolean,
56
+ default: false
57
+ },
58
+ isFullWidth: {
59
+ type: Boolean,
60
+ default: false
61
+ }
62
+ };
63
+ var uploadListProps = {
64
+ id: {
65
+ type: String,
66
+ default: ""
67
+ },
68
+ status: {
69
+ type: String,
70
+ default: "success"
71
+ },
72
+ title: {
73
+ type: String,
74
+ default: ""
75
+ },
76
+ subtitle: {
77
+ type: String,
78
+ default: ""
79
+ },
80
+ iconName: {
81
+ type: String,
82
+ default: "image-document"
83
+ },
84
+ iconColor: {
85
+ type: String,
86
+ default: "gray.600"
87
+ },
88
+ iconVariant: {
89
+ type: String,
90
+ default: "outline"
91
+ },
92
+ isShowDownloadButton: {
93
+ type: Boolean,
94
+ default: true
95
+ },
96
+ isShowRemoveButton: {
97
+ type: Boolean,
98
+ default: true
99
+ },
100
+ isShowCancelButton: {
101
+ type: Boolean,
102
+ default: true
103
+ }
104
+ };
105
+ var uploadEmit = ["click", "change", "clear"];
106
+ var uploadListEmit = ["click", "cancel", "remove", "download"];
107
+
108
+ export {
109
+ uploadProps,
110
+ uploadListProps,
111
+ uploadEmit,
112
+ uploadListEmit
113
+ };
@@ -0,0 +1,71 @@
1
+ import {
2
+ useUploadList
3
+ } from "./chunk-IEVDIM2Y.mjs";
4
+ import {
5
+ uploadListEmit,
6
+ uploadListProps
7
+ } from "./chunk-P2IS3QXL.mjs";
8
+ import {
9
+ __name
10
+ } from "./chunk-QZ7VFGWC.mjs";
11
+
12
+ // src/upload-list.tsx
13
+ import { withDirectives as _withDirectives, isVNode as _isVNode, resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
14
+ import { defineComponent } from "vue";
15
+ import { MpButton } from "@mekari/pixel3-button";
16
+ import { MpText } from "@mekari/pixel3-text";
17
+ import { MpIcon } from "@mekari/pixel3-icon";
18
+ import { MpSpinner } from "@mekari/pixel3-spinner";
19
+ import { uploadListSlotRecipe } from "@mekari/pixel3-styled-system/recipes";
20
+ function _isSlot(s) {
21
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !_isVNode(s);
22
+ }
23
+ __name(_isSlot, "_isSlot");
24
+ var MpUploadList = defineComponent({
25
+ name: "MpUploadList",
26
+ props: uploadListProps,
27
+ emits: uploadListEmit,
28
+ setup(props, {
29
+ emit
30
+ }) {
31
+ const {
32
+ color,
33
+ rootAttrs,
34
+ iconAttrs,
35
+ titleWrapperAttrs,
36
+ buttonCancelAttrs,
37
+ buttonDownloadAttrs,
38
+ buttonRemoveAttrs,
39
+ hasCancelButton,
40
+ hasDownloadButton,
41
+ hasRemoveButton
42
+ } = useUploadList(props, emit);
43
+ return () => {
44
+ const {
45
+ status,
46
+ title,
47
+ subtitle
48
+ } = props;
49
+ return _createVNode("div", rootAttrs.value, [status === "loading" ? _createVNode(MpSpinner, {
50
+ "size": "sm"
51
+ }, null) : _createVNode(MpIcon, iconAttrs.value, null), _createVNode("div", titleWrapperAttrs.value, [_withDirectives(_createVNode(MpText, {
52
+ "color": color.value.title,
53
+ "is-truncated": true
54
+ }, _isSlot(title) ? title : {
55
+ default: () => [title]
56
+ }), [[_resolveDirective("tooltip"), title]]), _createVNode(MpText, {
57
+ "color": color.value.subtitle,
58
+ "size": "body-small",
59
+ "is-truncated": true
60
+ }, _isSlot(subtitle) ? subtitle : {
61
+ default: () => [subtitle]
62
+ })]), _createVNode("div", {
63
+ "class": uploadListSlotRecipe().actionWrapper
64
+ }, [hasCancelButton.value && _withDirectives(_createVNode(MpButton, buttonCancelAttrs.value, null), [[_resolveDirective("tooltip"), "cancel"]]), hasDownloadButton.value && _withDirectives(_createVNode(MpButton, buttonDownloadAttrs.value, null), [[_resolveDirective("tooltip"), "download"]]), hasRemoveButton.value && _withDirectives(_createVNode(MpButton, buttonRemoveAttrs.value, null), [[_resolveDirective("tooltip"), "remove"]])])]);
65
+ };
66
+ }
67
+ });
68
+
69
+ export {
70
+ MpUploadList
71
+ };
@@ -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,54 @@
1
+ import {
2
+ useUpload
3
+ } from "./chunk-IEVDIM2Y.mjs";
4
+ import {
5
+ uploadEmit,
6
+ uploadProps
7
+ } from "./chunk-P2IS3QXL.mjs";
8
+ import {
9
+ __name
10
+ } from "./chunk-QZ7VFGWC.mjs";
11
+
12
+ // src/upload.tsx
13
+ import { withDirectives as _withDirectives, resolveDirective as _resolveDirective, createVNode as _createVNode, isVNode as _isVNode } from "vue";
14
+ import { defineComponent } from "vue";
15
+ import { MpButton } from "@mekari/pixel3-button";
16
+ import { MpText } from "@mekari/pixel3-text";
17
+ import { MpIcon } from "@mekari/pixel3-icon";
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 MpUpload = defineComponent({
23
+ name: "MpUpload",
24
+ props: uploadProps,
25
+ emits: uploadEmit,
26
+ setup(props, {
27
+ emit
28
+ }) {
29
+ const {
30
+ rootAttrs,
31
+ buttonAttrs,
32
+ textAttrs,
33
+ resetButtonAttrs,
34
+ inputAttrs,
35
+ fileName,
36
+ totalFiles,
37
+ isShowTooltip
38
+ } = useUpload(props, emit);
39
+ return () => {
40
+ const {
41
+ buttonCaption
42
+ } = props;
43
+ return _createVNode("div", rootAttrs.value, [_createVNode(MpButton, buttonAttrs.value, _isSlot(buttonCaption) ? buttonCaption : {
44
+ default: () => [buttonCaption]
45
+ }), _withDirectives(_createVNode(MpText, textAttrs.value, {
46
+ default: () => [fileName.value]
47
+ }), [[_resolveDirective("tooltip"), isShowTooltip.value ? fileName.value : ""]]), totalFiles.value > 0 && _createVNode(MpIcon, resetButtonAttrs.value, null), _createVNode("input", inputAttrs.value, null)]);
48
+ };
49
+ }
50
+ });
51
+
52
+ export {
53
+ MpUpload
54
+ };
@@ -0,0 +1,5 @@
1
+ export { MpUpload } from './upload.mjs';
2
+ export { MpUploadList } from './upload-list.mjs';
3
+ import 'vue/jsx-runtime';
4
+ import './modules/upload.props.mjs';
5
+ import 'vue';
@@ -0,0 +1,5 @@
1
+ export { MpUpload } from './upload.js';
2
+ export { MpUploadList } from './upload-list.js';
3
+ import 'vue/jsx-runtime';
4
+ import './modules/upload.props.js';
5
+ import 'vue';