@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,141 @@
1
+ import * as vue_jsx_runtime from 'vue/jsx-runtime';
2
+ import { File } from './modules/upload.props.mjs';
3
+ import * as vue from 'vue';
4
+
5
+ declare const MpUpload: vue.DefineComponent<{
6
+ id: {
7
+ type: vue.PropType<string>;
8
+ default: string;
9
+ };
10
+ fileList: {
11
+ type: vue.PropType<File[]>;
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
+ loadingText: {
24
+ type: vue.PropType<string>;
25
+ default: string;
26
+ };
27
+ buttonCaption: {
28
+ type: vue.PropType<string>;
29
+ default: string;
30
+ };
31
+ value: {
32
+ type: vue.PropType<string>;
33
+ };
34
+ modelValue: {
35
+ type: vue.PropType<string>;
36
+ };
37
+ isLoading: {
38
+ type: vue.PropType<boolean>;
39
+ default: boolean;
40
+ };
41
+ isDisabled: {
42
+ type: vue.PropType<boolean>;
43
+ default: boolean;
44
+ };
45
+ isInvalid: {
46
+ type: vue.PropType<boolean>;
47
+ default: boolean;
48
+ };
49
+ isRequired: {
50
+ type: vue.PropType<boolean>;
51
+ default: boolean;
52
+ };
53
+ isResetOnChange: {
54
+ type: vue.PropType<boolean>;
55
+ default: boolean;
56
+ };
57
+ isMultiple: {
58
+ type: vue.PropType<boolean>;
59
+ default: boolean;
60
+ };
61
+ isFullWidth: {
62
+ type: vue.PropType<boolean>;
63
+ default: boolean;
64
+ };
65
+ }, () => vue_jsx_runtime.JSX.Element, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, string[], string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
66
+ id: {
67
+ type: vue.PropType<string>;
68
+ default: string;
69
+ };
70
+ fileList: {
71
+ type: vue.PropType<File[]>;
72
+ };
73
+ accept: {
74
+ type: vue.PropType<string>;
75
+ };
76
+ name: {
77
+ type: vue.PropType<string>;
78
+ };
79
+ placeholder: {
80
+ type: vue.PropType<string>;
81
+ default: string;
82
+ };
83
+ loadingText: {
84
+ type: vue.PropType<string>;
85
+ default: string;
86
+ };
87
+ buttonCaption: {
88
+ type: vue.PropType<string>;
89
+ default: string;
90
+ };
91
+ value: {
92
+ type: vue.PropType<string>;
93
+ };
94
+ modelValue: {
95
+ type: vue.PropType<string>;
96
+ };
97
+ isLoading: {
98
+ type: vue.PropType<boolean>;
99
+ default: boolean;
100
+ };
101
+ isDisabled: {
102
+ type: vue.PropType<boolean>;
103
+ default: boolean;
104
+ };
105
+ isInvalid: {
106
+ type: vue.PropType<boolean>;
107
+ default: boolean;
108
+ };
109
+ isRequired: {
110
+ type: vue.PropType<boolean>;
111
+ default: boolean;
112
+ };
113
+ isResetOnChange: {
114
+ type: vue.PropType<boolean>;
115
+ default: boolean;
116
+ };
117
+ isMultiple: {
118
+ type: vue.PropType<boolean>;
119
+ default: boolean;
120
+ };
121
+ isFullWidth: {
122
+ type: vue.PropType<boolean>;
123
+ default: boolean;
124
+ };
125
+ }>> & {
126
+ [x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
127
+ }, {
128
+ isDisabled: boolean;
129
+ isLoading: boolean;
130
+ id: string;
131
+ placeholder: string;
132
+ loadingText: string;
133
+ buttonCaption: string;
134
+ isInvalid: boolean;
135
+ isRequired: boolean;
136
+ isResetOnChange: boolean;
137
+ isMultiple: boolean;
138
+ isFullWidth: boolean;
139
+ }, {}>;
140
+
141
+ export { MpUpload };
@@ -0,0 +1,141 @@
1
+ import * as vue_jsx_runtime from 'vue/jsx-runtime';
2
+ import { File } from './modules/upload.props.js';
3
+ import * as vue from 'vue';
4
+
5
+ declare const MpUpload: vue.DefineComponent<{
6
+ id: {
7
+ type: vue.PropType<string>;
8
+ default: string;
9
+ };
10
+ fileList: {
11
+ type: vue.PropType<File[]>;
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
+ loadingText: {
24
+ type: vue.PropType<string>;
25
+ default: string;
26
+ };
27
+ buttonCaption: {
28
+ type: vue.PropType<string>;
29
+ default: string;
30
+ };
31
+ value: {
32
+ type: vue.PropType<string>;
33
+ };
34
+ modelValue: {
35
+ type: vue.PropType<string>;
36
+ };
37
+ isLoading: {
38
+ type: vue.PropType<boolean>;
39
+ default: boolean;
40
+ };
41
+ isDisabled: {
42
+ type: vue.PropType<boolean>;
43
+ default: boolean;
44
+ };
45
+ isInvalid: {
46
+ type: vue.PropType<boolean>;
47
+ default: boolean;
48
+ };
49
+ isRequired: {
50
+ type: vue.PropType<boolean>;
51
+ default: boolean;
52
+ };
53
+ isResetOnChange: {
54
+ type: vue.PropType<boolean>;
55
+ default: boolean;
56
+ };
57
+ isMultiple: {
58
+ type: vue.PropType<boolean>;
59
+ default: boolean;
60
+ };
61
+ isFullWidth: {
62
+ type: vue.PropType<boolean>;
63
+ default: boolean;
64
+ };
65
+ }, () => vue_jsx_runtime.JSX.Element, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, string[], string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
66
+ id: {
67
+ type: vue.PropType<string>;
68
+ default: string;
69
+ };
70
+ fileList: {
71
+ type: vue.PropType<File[]>;
72
+ };
73
+ accept: {
74
+ type: vue.PropType<string>;
75
+ };
76
+ name: {
77
+ type: vue.PropType<string>;
78
+ };
79
+ placeholder: {
80
+ type: vue.PropType<string>;
81
+ default: string;
82
+ };
83
+ loadingText: {
84
+ type: vue.PropType<string>;
85
+ default: string;
86
+ };
87
+ buttonCaption: {
88
+ type: vue.PropType<string>;
89
+ default: string;
90
+ };
91
+ value: {
92
+ type: vue.PropType<string>;
93
+ };
94
+ modelValue: {
95
+ type: vue.PropType<string>;
96
+ };
97
+ isLoading: {
98
+ type: vue.PropType<boolean>;
99
+ default: boolean;
100
+ };
101
+ isDisabled: {
102
+ type: vue.PropType<boolean>;
103
+ default: boolean;
104
+ };
105
+ isInvalid: {
106
+ type: vue.PropType<boolean>;
107
+ default: boolean;
108
+ };
109
+ isRequired: {
110
+ type: vue.PropType<boolean>;
111
+ default: boolean;
112
+ };
113
+ isResetOnChange: {
114
+ type: vue.PropType<boolean>;
115
+ default: boolean;
116
+ };
117
+ isMultiple: {
118
+ type: vue.PropType<boolean>;
119
+ default: boolean;
120
+ };
121
+ isFullWidth: {
122
+ type: vue.PropType<boolean>;
123
+ default: boolean;
124
+ };
125
+ }>> & {
126
+ [x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
127
+ }, {
128
+ isDisabled: boolean;
129
+ isLoading: boolean;
130
+ id: string;
131
+ placeholder: string;
132
+ loadingText: string;
133
+ buttonCaption: string;
134
+ isInvalid: boolean;
135
+ isRequired: boolean;
136
+ isResetOnChange: boolean;
137
+ isMultiple: boolean;
138
+ isFullWidth: boolean;
139
+ }, {}>;
140
+
141
+ export { MpUpload };
package/dist/upload.js ADDED
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/upload.tsx
22
+ var upload_exports = {};
23
+ __export(upload_exports, {
24
+ MpUpload: () => MpUpload
25
+ });
26
+ module.exports = __toCommonJS(upload_exports);
27
+ var import_vue2 = require("vue");
28
+ var import_vue3 = require("vue");
29
+ var import_pixel3_button = require("@mekari/pixel3-button");
30
+ var import_pixel3_text = require("@mekari/pixel3-text");
31
+ var import_pixel3_icon = require("@mekari/pixel3-icon");
32
+
33
+ // src/modules/upload.props.ts
34
+ var uploadProps = {
35
+ id: {
36
+ type: String,
37
+ default: ""
38
+ },
39
+ fileList: {
40
+ type: Array
41
+ },
42
+ accept: {
43
+ type: String
44
+ },
45
+ name: {
46
+ type: String
47
+ },
48
+ placeholder: {
49
+ type: String,
50
+ default: "No file selected"
51
+ },
52
+ loadingText: {
53
+ type: String,
54
+ default: "Uploading..."
55
+ },
56
+ buttonCaption: {
57
+ type: String,
58
+ default: "Choose file"
59
+ },
60
+ value: {
61
+ type: String
62
+ },
63
+ modelValue: {
64
+ type: String
65
+ },
66
+ isLoading: {
67
+ type: Boolean,
68
+ default: false
69
+ },
70
+ isDisabled: {
71
+ type: Boolean,
72
+ default: false
73
+ },
74
+ isInvalid: {
75
+ type: Boolean,
76
+ default: false
77
+ },
78
+ isRequired: {
79
+ type: Boolean,
80
+ default: false
81
+ },
82
+ isResetOnChange: {
83
+ type: Boolean,
84
+ default: false
85
+ },
86
+ isMultiple: {
87
+ type: Boolean,
88
+ default: false
89
+ },
90
+ isFullWidth: {
91
+ type: Boolean,
92
+ default: false
93
+ }
94
+ };
95
+ var uploadEmit = ["click", "change", "clear"];
96
+
97
+ // src/modules/upload.hooks.ts
98
+ var import_vue = require("vue");
99
+ var import_pixel3_utils = require("@mekari/pixel3-utils");
100
+ var import_recipes = require("@mekari/pixel3-styled-system/recipes");
101
+ function useUpload(props, emit) {
102
+ const {
103
+ id,
104
+ fileList,
105
+ placeholder,
106
+ accept,
107
+ name,
108
+ loadingText,
109
+ isLoading,
110
+ isDisabled,
111
+ isInvalid,
112
+ isRequired,
113
+ isResetOnChange,
114
+ isMultiple,
115
+ isFullWidth
116
+ } = (0, import_vue.toRefs)(props);
117
+ const files = (0, import_vue.ref)(fileList == null ? void 0 : fileList.value);
118
+ const fileInput = (0, import_vue.ref)();
119
+ const getId = id.value || (0, import_pixel3_utils.getUniqueId)("", "upload").value;
120
+ const fileName = (0, import_vue.computed)(() => {
121
+ if (isLoading.value) {
122
+ return loadingText.value;
123
+ } else {
124
+ if (totalFiles.value === 0) {
125
+ return placeholder.value;
126
+ } else if (files.value && totalFiles.value === 1) {
127
+ return files.value[0].name;
128
+ } else {
129
+ return `${totalFiles.value} files`;
130
+ }
131
+ }
132
+ });
133
+ const totalFiles = (0, import_vue.computed)(() => {
134
+ var _a;
135
+ return ((_a = files.value) == null ? void 0 : _a.length) || 0;
136
+ });
137
+ const isShowTooltip = (0, import_vue.computed)(() => {
138
+ var _a;
139
+ return ((_a = files.value) == null ? void 0 : _a.length) === 1;
140
+ });
141
+ const rootAttrs = (0, import_vue.computed)(() => {
142
+ return {
143
+ "data-pixel-component": "MpUpload",
144
+ "data-invalid": isInvalid.value || void 0,
145
+ "data-disabled": isDisabled.value || void 0,
146
+ id: getId,
147
+ tabindex: isDisabled.value ? -1 : 0,
148
+ class: (0, import_recipes.uploadSlotRecipe)().root,
149
+ style: {
150
+ maxWidth: isFullWidth.value ? "100%" : "var(--mp-sizes-65)"
151
+ },
152
+ onClick: handleClick
153
+ };
154
+ });
155
+ const buttonAttrs = (0, import_vue.computed)(() => {
156
+ return {
157
+ variant: "secondary",
158
+ size: "sm",
159
+ isDisabled: isDisabled.value
160
+ };
161
+ });
162
+ const textAttrs = (0, import_vue.computed)(() => {
163
+ return {
164
+ color: !isLoading.value && totalFiles.value >= 1 ? "dark" : "gray.400",
165
+ isTruncated: true
166
+ };
167
+ });
168
+ const resetButtonAttrs = (0, import_vue.computed)(() => {
169
+ return {
170
+ class: (0, import_recipes.uploadSlotRecipe)().resetButton,
171
+ "aria-label": "reset button",
172
+ name: "reset",
173
+ size: "sm",
174
+ color: "gray.400",
175
+ onClick: handleClear
176
+ };
177
+ });
178
+ const inputAttrs = (0, import_vue.computed)(() => {
179
+ return {
180
+ ref: fileInput,
181
+ id: `input-${getId}`,
182
+ class: (0, import_recipes.sharedSlotRecipe)().hidden,
183
+ type: "file",
184
+ name: name == null ? void 0 : name.value,
185
+ accept: accept == null ? void 0 : accept.value,
186
+ multiple: isMultiple.value,
187
+ disabled: isDisabled.value,
188
+ required: isRequired.value,
189
+ onChange: handleChange
190
+ };
191
+ });
192
+ function clear() {
193
+ files.value = void 0;
194
+ fileInput.value.value = "";
195
+ }
196
+ __name(clear, "clear");
197
+ function handleClear(e) {
198
+ e.stopPropagation();
199
+ clear();
200
+ emit("clear", e);
201
+ }
202
+ __name(handleClear, "handleClear");
203
+ function handleChange(e) {
204
+ const target = e.target;
205
+ if (target && target.files) {
206
+ files.value = target.files;
207
+ }
208
+ emit("change", e);
209
+ }
210
+ __name(handleChange, "handleChange");
211
+ function handleClick(e) {
212
+ if (isDisabled.value) {
213
+ return;
214
+ }
215
+ if (isResetOnChange.value) {
216
+ clear();
217
+ }
218
+ fileInput.value.click();
219
+ emit("click", e);
220
+ }
221
+ __name(handleClick, "handleClick");
222
+ (0, import_vue.watch)(() => fileList == null ? void 0 : fileList.value, (newValue) => {
223
+ if (newValue) {
224
+ files.value = newValue;
225
+ }
226
+ });
227
+ return {
228
+ rootAttrs,
229
+ buttonAttrs,
230
+ textAttrs,
231
+ resetButtonAttrs,
232
+ inputAttrs,
233
+ fileName,
234
+ totalFiles,
235
+ isShowTooltip
236
+ };
237
+ }
238
+ __name(useUpload, "useUpload");
239
+
240
+ // src/upload.tsx
241
+ function _isSlot(s) {
242
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, import_vue2.isVNode)(s);
243
+ }
244
+ __name(_isSlot, "_isSlot");
245
+ var MpUpload = (0, import_vue3.defineComponent)({
246
+ name: "MpUpload",
247
+ props: uploadProps,
248
+ emits: uploadEmit,
249
+ setup(props, {
250
+ emit
251
+ }) {
252
+ const {
253
+ rootAttrs,
254
+ buttonAttrs,
255
+ textAttrs,
256
+ resetButtonAttrs,
257
+ inputAttrs,
258
+ fileName,
259
+ totalFiles,
260
+ isShowTooltip
261
+ } = useUpload(props, emit);
262
+ return () => {
263
+ const {
264
+ buttonCaption
265
+ } = props;
266
+ return (0, import_vue2.createVNode)("div", rootAttrs.value, [(0, import_vue2.createVNode)(import_pixel3_button.MpButton, buttonAttrs.value, _isSlot(buttonCaption) ? buttonCaption : {
267
+ default: () => [buttonCaption]
268
+ }), (0, import_vue2.withDirectives)((0, import_vue2.createVNode)(import_pixel3_text.MpText, textAttrs.value, {
269
+ default: () => [fileName.value]
270
+ }), [[(0, import_vue2.resolveDirective)("tooltip"), isShowTooltip.value ? fileName.value : ""]]), totalFiles.value > 0 && (0, import_vue2.createVNode)(import_pixel3_icon.MpIcon, resetButtonAttrs.value, null), (0, import_vue2.createVNode)("input", inputAttrs.value, null)]);
271
+ };
272
+ }
273
+ });
274
+ // Annotate the CommonJS export names for ESM import in node:
275
+ 0 && (module.exports = {
276
+ MpUpload
277
+ });
@@ -0,0 +1,9 @@
1
+ import {
2
+ MpUpload
3
+ } from "./chunk-XCJP2E47.mjs";
4
+ import "./chunk-IEVDIM2Y.mjs";
5
+ import "./chunk-P2IS3QXL.mjs";
6
+ import "./chunk-QZ7VFGWC.mjs";
7
+ export {
8
+ MpUpload
9
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@mekari/pixel3-upload",
3
+ "description": "Upload component for mekari pixel 3",
4
+ "version": "0.0.1",
5
+ "main": "dist/index.js",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "dependencies": {
11
+ "@mekari/pixel3-button": "0.0.2",
12
+ "@mekari/pixel3-icon": "0.0.2",
13
+ "@mekari/pixel3-styled-system": "0.0.1",
14
+ "@mekari/pixel3-spinner": "0.0.2",
15
+ "@mekari/pixel3-text": "0.0.2",
16
+ "@mekari/pixel3-utils": "0.0.2"
17
+ },
18
+ "peerDependencies": {
19
+ "vue": "^3.3.7"
20
+ },
21
+ "devDependencies": {
22
+ "vue": "^3.3.7"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "module": "dist/index.mjs",
28
+ "types": "dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "require": "./dist/index.js",
33
+ "default": "./dist/index.mjs"
34
+ }
35
+ },
36
+ "scripts": {
37
+ "clean": "rimraf dist .turbo",
38
+ "build": "tsup && pnpm build:types",
39
+ "build:fast": "tsup",
40
+ "build:types": "tsup src --dts-only",
41
+ "build:external": "tsup src/index.tsx --external",
42
+ "types:check": "tsc --noEmit",
43
+ "replace-config": "clean-package",
44
+ "restore-config": "clean-package restore"
45
+ }
46
+ }