@bouku/core 0.1.0 → 0.1.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,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640" width="1em" height="1em">
|
|
2
|
+
<path
|
|
3
|
+
d="M352 173.3L352 384C352 401.7 337.7 416 320 416C302.3 416 288 401.7 288 384L288 173.3L246.6 214.7C234.1 227.2 213.8 227.2 201.3 214.7C188.8 202.2 188.8 181.9 201.3 169.4L297.3 73.4C309.8 60.9 330.1 60.9 342.6 73.4L438.6 169.4C451.1 181.9 451.1 202.2 438.6 214.7C426.1 227.2 405.8 227.2 393.3 214.7L352 173.3zM320 464C364.2 464 400 428.2 400 384L480 384C515.3 384 544 412.7 544 448L544 480C544 515.3 515.3 544 480 544L160 544C124.7 544 96 515.3 96 480L96 448C96 412.7 124.7 384 160 384L240 384C240 428.2 275.8 464 320 464zM464 488C477.3 488 488 477.3 488 464C488 450.7 477.3 440 464 440C450.7 440 440 450.7 440 464C440 477.3 450.7 488 464 488z"
|
|
4
|
+
fill="currentColor"
|
|
5
|
+
/>
|
|
6
|
+
</svg>
|
|
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CopyButton = exports.Button = void 0;
|
|
6
|
+
exports.FileUploader = exports.CopyButton = exports.Button = void 0;
|
|
7
7
|
var normal_1 = require("./normal");
|
|
8
8
|
Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return __importDefault(normal_1).default; } });
|
|
9
9
|
var copy_1 = require("./copy");
|
|
10
10
|
Object.defineProperty(exports, "CopyButton", { enumerable: true, get: function () { return __importDefault(copy_1).default; } });
|
|
11
|
+
var upload_1 = require("./upload");
|
|
12
|
+
Object.defineProperty(exports, "FileUploader", { enumerable: true, get: function () { return __importDefault(upload_1).default; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type FileType = "csv";
|
|
2
|
+
type Props<T> = {
|
|
3
|
+
type?: FileType | FileType[];
|
|
4
|
+
url: string;
|
|
5
|
+
next?: (data: T) => void;
|
|
6
|
+
oops?: (err: string) => void;
|
|
7
|
+
};
|
|
8
|
+
export default function FileUploader<T>({ type, url, next, oops }: Props<T>): import("react").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.default = FileUploader;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const upload_svg_1 = __importDefault(require("../../assets/icons/upload.svg"));
|
|
11
|
+
const core_1 = require("@bouku/core");
|
|
12
|
+
const snatch_http_1 = require("snatch-http");
|
|
13
|
+
function FileUploader({ type, url, next, oops }) {
|
|
14
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
15
|
+
const clickButton = () => inputRef.current?.click();
|
|
16
|
+
const [isLoading, setLoading] = (0, react_1.useState)(false);
|
|
17
|
+
const typesArray = type ? (Array.isArray(type) ? type : [type]) : undefined;
|
|
18
|
+
const acceptAttribute = typesArray?.map((t) => `.${t}`).join(", ");
|
|
19
|
+
const handleUpload = async (event) => {
|
|
20
|
+
const file = event.target.files?.[0];
|
|
21
|
+
if (!file)
|
|
22
|
+
return;
|
|
23
|
+
setLoading(true);
|
|
24
|
+
const formData = new FormData();
|
|
25
|
+
formData.append("data", file);
|
|
26
|
+
const handleSuccess = (data) => {
|
|
27
|
+
next?.(data);
|
|
28
|
+
setLoading(false);
|
|
29
|
+
};
|
|
30
|
+
await (0, snatch_http_1.postApi)({
|
|
31
|
+
url: url,
|
|
32
|
+
data: formData,
|
|
33
|
+
next: handleSuccess,
|
|
34
|
+
oops: oops,
|
|
35
|
+
safe: true
|
|
36
|
+
});
|
|
37
|
+
setLoading(false);
|
|
38
|
+
if (event.target)
|
|
39
|
+
event.target.value = "";
|
|
40
|
+
};
|
|
41
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(core_1.Button, { variant: "accent", action: clickButton, disabled: isLoading, children: [(0, jsx_runtime_1.jsx)(upload_svg_1.default, {}), "Import CSV"] }), (0, jsx_runtime_1.jsx)("input", { ref: inputRef, type: "file", className: "hidden", accept: acceptAttribute, onChange: handleUpload })] }));
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bouku/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"framer-motion": "^12.23.6",
|
|
30
30
|
"react-rnd": "^10.5.2",
|
|
31
31
|
"react-time-ago": "^7.4.4",
|
|
32
|
+
"snatch-http": "^0.0.1",
|
|
32
33
|
"tailwind-variants": "^1.0.0",
|
|
33
34
|
"ts-helper-kit": "^0.0.6"
|
|
34
35
|
},
|