@pnkx-lib/ui 1.9.359 → 1.9.360

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.
@@ -21,6 +21,7 @@ const UploadComponent = ({
21
21
  description = "Ảnh có kích thước 400x400 px và dung lượng ảnh < 1 mb",
22
22
  customRequest,
23
23
  setImageUpload,
24
+ clickIconRemove,
24
25
  ...restProps
25
26
  }) => {
26
27
  const imageUrl = typeof field?.value === "string" ? field.value : field?.value instanceof File ? URL.createObjectURL(field.value) : null;
@@ -65,7 +66,10 @@ const UploadComponent = ({
65
66
  "button",
66
67
  {
67
68
  type: "button",
68
- onClick: handleRemoveImage,
69
+ onClick: () => {
70
+ handleRemoveImage();
71
+ clickIconRemove?.();
72
+ },
69
73
  className: "absolute top-1 right-1 w-6 h-6 flex items-center justify-center bg-white cursor-pointer bg-opacity-80 rounded-full hover:bg-opacity-100 transition",
70
74
  children: /* @__PURE__ */ jsx(RefIcon, { className: "text-black text-[12px]" })
71
75
  }
@@ -1,75 +1,19 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { useState } from 'react';
3
- import { Spin, Upload, message } from 'antd';
4
- import { C as Controller } from '../chunks/index.esm-o4O8pXMN.js';
2
+ import { Spin, Upload } from 'antd';
5
3
  import { R as RefIcon } from '../chunks/InboxOutlined-DNCJCjk3.js';
6
4
 
7
5
  const { Dragger } = Upload;
8
6
  const UploadMultiple = ({
9
- name,
10
- control,
11
7
  title,
12
- content
8
+ content,
9
+ isLoading,
10
+ ...props
13
11
  }) => {
14
- const [isLoading, setIsLoading] = useState(false);
15
- const createUploadProps = (value, onChange) => ({
16
- multiple: true,
17
- listType: "picture",
18
- showUploadList: true,
19
- fileList: value,
20
- customRequest: async ({ file, onSuccess, onError }) => {
21
- const formData = new FormData();
22
- formData.append("file", file);
23
- formData.append("upload_preset", "ml_default");
24
- setIsLoading(true);
25
- try {
26
- const res = await fetch(
27
- "https://api.cloudinary.com/v1_1/dhtrzmzd3/image/upload",
28
- {
29
- method: "POST",
30
- body: formData
31
- }
32
- );
33
- const data = await res.json();
34
- const newFile = {
35
- uid: data.asset_id || Date.now().toString(),
36
- name: data.original_filename,
37
- url: data.secure_url
38
- };
39
- onChange([...value || [], newFile]);
40
- onSuccess?.(data, new XMLHttpRequest());
41
- message.success("Tải ảnh lên thành công.");
42
- } catch (err) {
43
- onError?.(err);
44
- message.error("Tải ảnh lên thất bại.");
45
- } finally {
46
- setIsLoading(false);
47
- }
48
- },
49
- onPreview: (file) => {
50
- window.open(file.url, "_blank");
51
- },
52
- onRemove: (file) => {
53
- const newList = (value || []).filter((item) => item.uid !== file.uid);
54
- onChange(newList);
55
- }
56
- });
57
- return /* @__PURE__ */ jsx(
58
- Controller,
59
- {
60
- name,
61
- control,
62
- render: ({ field }) => {
63
- const { value, onChange } = field;
64
- const props = createUploadProps(value || [], onChange);
65
- return /* @__PURE__ */ jsx(Spin, { spinning: isLoading, tip: "Đang tải", children: /* @__PURE__ */ jsxs(Dragger, { ...props, children: [
66
- /* @__PURE__ */ jsx("p", { className: "ant-upload-drag-icon", children: /* @__PURE__ */ jsx(RefIcon, {}) }),
67
- /* @__PURE__ */ jsx("p", { className: "ant-upload-text", children: title }),
68
- /* @__PURE__ */ jsx("p", { className: "ant-upload-hint", children: content })
69
- ] }) });
70
- }
71
- }
72
- );
12
+ return /* @__PURE__ */ jsx(Spin, { spinning: isLoading, tip: "Đang tải", children: /* @__PURE__ */ jsxs(Dragger, { ...props, children: [
13
+ /* @__PURE__ */ jsx("p", { className: "ant-upload-drag-icon", children: /* @__PURE__ */ jsx(RefIcon, {}) }),
14
+ /* @__PURE__ */ jsx("p", { className: "ant-upload-text", children: title }),
15
+ /* @__PURE__ */ jsx("p", { className: "ant-upload-hint", children: content })
16
+ ] }) });
73
17
  };
74
18
 
75
19
  export { UploadMultiple };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pnkx-lib/ui",
3
3
  "private": false,
4
- "version": "1.9.359",
4
+ "version": "1.9.360",
5
5
  "type": "module",
6
6
  "main": "./es/index.js",
7
7
  "module": "./es/index.js",
@@ -12,6 +12,7 @@ interface UploadImageProps extends UploadProps {
12
12
  setImageUpload?: (value: string) => void;
13
13
  content?: string;
14
14
  description?: string;
15
+ clickIconRemove?: () => void;
15
16
  }
16
17
  export declare const UploadComponent: React.FC<UploadImageProps & {
17
18
  field: any;
@@ -4,5 +4,6 @@ export interface UploadMultipleProps {
4
4
  control: Control | any;
5
5
  title?: string;
6
6
  content?: string;
7
+ isLoading?: boolean;
7
8
  }
8
- export declare const UploadMultiple: ({ name, control, title, content, }: UploadMultipleProps) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const UploadMultiple: ({ title, content, isLoading, ...props }: UploadMultipleProps) => import("react/jsx-runtime").JSX.Element;