@bouko/react 2.7.2 → 2.7.3
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.
|
@@ -10,6 +10,7 @@ export { default as IconButton } from "./button/icon";
|
|
|
10
10
|
export { default as Badge } from "./text/badge";
|
|
11
11
|
export { default as Dropdown } from "./dropdown/normal";
|
|
12
12
|
export { default as FileUploader } from "./upload/file";
|
|
13
|
+
export { ImageUploader } from "./upload/image";
|
|
13
14
|
export * from "./animate";
|
|
14
15
|
export * from "./list";
|
|
15
16
|
export * from "./carousel";
|
package/dist/components/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { default as IconButton } from "./button/icon";
|
|
|
10
10
|
export { default as Badge } from "./text/badge";
|
|
11
11
|
export { default as Dropdown } from "./dropdown/normal";
|
|
12
12
|
export { default as FileUploader } from "./upload/file";
|
|
13
|
+
export { ImageUploader } from "./upload/image";
|
|
13
14
|
export * from "./animate";
|
|
14
15
|
export * from "./list";
|
|
15
16
|
export * from "./carousel";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
style?: string;
|
|
3
|
+
placeholder?: string;
|
|
4
|
+
value?: File;
|
|
5
|
+
update?: (x: File) => void;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function ImageUploader({ style, placeholder, value, update, disabled }: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default ImageUploader;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useRef, useEffect } from "react";
|
|
4
|
+
import { cn } from "@bouko/style";
|
|
5
|
+
import Camera from "../../assets/icons/camera.svg";
|
|
6
|
+
export function ImageUploader({ style, placeholder, value, update, disabled = false }) {
|
|
7
|
+
const [preview, setPreview] = useState();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (value) {
|
|
10
|
+
console.log(value);
|
|
11
|
+
setPreview(URL.createObjectURL(value));
|
|
12
|
+
}
|
|
13
|
+
}, [value]);
|
|
14
|
+
const ref = useRef(null);
|
|
15
|
+
const uploadFile = () => ref.current?.click();
|
|
16
|
+
if (!update)
|
|
17
|
+
disabled = true;
|
|
18
|
+
const handleFileChange = (e) => {
|
|
19
|
+
const file = e.target.files?.[0];
|
|
20
|
+
if (!file)
|
|
21
|
+
return;
|
|
22
|
+
update?.(file);
|
|
23
|
+
};
|
|
24
|
+
return (_jsxs("div", { className: cn(styles.container, style), onClick: uploadFile, children: [_jsx("input", { type: "file", className: "hidden", onChange: handleFileChange, ref: ref }), _jsx("img", { className: "absolute top-0 left-0 w-full h-full", src: preview || placeholder, alt: "Image Uploader" }), _jsx("div", { className: "flex justify-center items-center w-full h-full z-10 opacity-0 hover:opacity-50 bg-background-light/80 duration-200 cursor-pointer", children: _jsx(Camera, { className: "text-xl text-primary-light" }) })] }));
|
|
25
|
+
}
|
|
26
|
+
const styles = {
|
|
27
|
+
container: "relative shrink-0 border border-border rounded-md overflow-hidden",
|
|
28
|
+
};
|
|
29
|
+
export default ImageUploader;
|