@bouko/react 2.7.3 → 2.7.4

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.
@@ -1,9 +1,12 @@
1
- type Props = {
1
+ import { Dispatch, SetStateAction } from "react";
2
+ type Props<T> = {
3
+ id?: string;
2
4
  style?: string;
3
5
  placeholder?: string;
4
6
  value?: File;
5
7
  update?: (x: File) => void;
8
+ updateForm?: Dispatch<SetStateAction<T>>;
6
9
  disabled?: boolean;
7
10
  };
8
- export declare function ImageUploader({ style, placeholder, value, update, disabled }: Props): import("react/jsx-runtime").JSX.Element;
11
+ export declare function ImageUploader<T>({ id, style, placeholder, value, update, updateForm, disabled }: Props<T>): import("react/jsx-runtime").JSX.Element;
9
12
  export default ImageUploader;
@@ -3,12 +3,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useState, useRef, useEffect } from "react";
4
4
  import { cn } from "@bouko/style";
5
5
  import Camera from "../../assets/icons/camera.svg";
6
- export function ImageUploader({ style, placeholder, value, update, disabled = false }) {
6
+ export function ImageUploader({ id, style, placeholder, value, update, updateForm, disabled = false }) {
7
7
  const [preview, setPreview] = useState();
8
8
  useEffect(() => {
9
9
  if (value) {
10
- console.log(value);
11
- setPreview(URL.createObjectURL(value));
10
+ const imageUrl = URL.createObjectURL(value);
11
+ setPreview(imageUrl);
12
12
  }
13
13
  }, [value]);
14
14
  const ref = useRef(null);
@@ -19,7 +19,10 @@ export function ImageUploader({ style, placeholder, value, update, disabled = fa
19
19
  const file = e.target.files?.[0];
20
20
  if (!file)
21
21
  return;
22
- update?.(file);
22
+ if (id && updateForm)
23
+ updateForm(x => ({ ...x, [id]: file }));
24
+ else
25
+ update?.(file);
23
26
  };
24
27
  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
28
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "2.7.3",
4
+ "version": "2.7.4",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",