@omniumretail/component-library 1.0.41 → 1.0.43

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,5 +1,4 @@
1
1
  import { Meta, Story } from "@storybook/react";
2
- import { TagProps } from 'antd';
3
2
  declare const _default: Meta<import("@storybook/react").Args>;
4
3
  export default _default;
5
- export declare const Primary: Story<TagProps>;
4
+ export declare const Primary: Story<any>;
@@ -0,0 +1,2 @@
1
+ export declare const getResizedImage: (imageFile: any, maxWidth: any, maxHeight: any) => Promise<unknown>;
2
+ export declare const getCroppedImg: (image: any, crop: any) => Promise<unknown>;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const ImageUpload: () => JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { Meta, Story } from "@storybook/react";
2
+ declare const _default: Meta<import("@storybook/react").Args>;
3
+ export default _default;
4
+ export declare const Primary: Story<any>;
@@ -0,0 +1,7 @@
1
+ import type { UploadFile, UploadProps } from 'antd/es/upload/interface';
2
+ interface UploadPropsExtended extends UploadProps {
3
+ onImageChange?: (file: UploadFile | null) => void;
4
+ initialFileList?: UploadFile[];
5
+ }
6
+ export declare const Upload: (props: UploadPropsExtended) => JSX.Element;
7
+ export {};
@@ -19,3 +19,4 @@ export * from './Category';
19
19
  export * from './DatePickerTag';
20
20
  export * from './AnalyticsBar';
21
21
  export * from './CategoryResponse';
22
+ export * from './Upload';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omniumretail/component-library",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "private": false,
5
5
  "main": "dist/bundle.js",
6
6
  "typings": "./dist/types/index",
@@ -18,11 +18,13 @@
18
18
  "@types/react-beautiful-dnd": "^13.1.3",
19
19
  "@types/react-dom": "^18.0.9",
20
20
  "antd": "^5.1.2",
21
+ "antd-img-crop": "^4.10.2",
21
22
  "babel-jest": "^27.4.2",
22
23
  "babel-loader": "^8.2.3",
23
24
  "babel-plugin-named-asset-import": "^0.3.8",
24
25
  "babel-preset-react-app": "^10.0.1",
25
26
  "bfj": "^7.0.2",
27
+ "browser-image-compression": "^2.0.2",
26
28
  "browserslist": "^4.18.1",
27
29
  "camelcase": "^6.2.1",
28
30
  "case-sensitive-paths-webpack-plugin": "^2.4.0",
@@ -59,6 +61,7 @@
59
61
  "react-beautiful-dnd": "^13.1.1",
60
62
  "react-dev-utils": "^12.0.1",
61
63
  "react-dom": "^18.2.0",
64
+ "react-easy-crop": "^4.7.4",
62
65
  "react-i18next": "^12.1.4",
63
66
  "react-refresh": "^0.11.0",
64
67
  "resolve": "^1.20.0",
@@ -12,6 +12,7 @@ const Template: Story<ModalWithTableProps> = (args) => {
12
12
  const [isFetching, setIsFetching] = useState<boolean>(false);
13
13
  const [tagsData, setTagsData] = useState<any>({});
14
14
  const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
15
+ const [selectedSupervisors, setSelectedSupervisors] = useState<any>(['232']);
15
16
 
16
17
  const onClickMe = () => {
17
18
  setIsModalOpen(true);
@@ -53,13 +54,13 @@ const Template: Story<ModalWithTableProps> = (args) => {
53
54
  },
54
55
  ],
55
56
  pagination: {
56
- total: 6,
57
+ total: 4,
57
58
  pageSize: 2
58
59
  },
59
60
  rowKeyValue: 'mecanographicNumber',
60
61
  rowSelection: {
61
- type: 'radio',
62
- selectedRowKeys: ['232']
62
+ type: 'checkbox',
63
+ selectedRowKeys: selectedSupervisors?.length > 0 ? selectedSupervisors : []
63
64
  },
64
65
  }
65
66
 
@@ -73,6 +74,10 @@ const Template: Story<ModalWithTableProps> = (args) => {
73
74
  }, 1000);
74
75
  }
75
76
 
77
+ if(modalData?.rowSelectionInfo?.length !== undefined) {
78
+ setSelectedSupervisors(modalData.rowSelectionInfo);
79
+ }
80
+
76
81
  setIsModalOpen(modalData?.open!);
77
82
  }, [modalData]);
78
83
 
@@ -27,12 +27,14 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
27
27
  isLoading,
28
28
  } = props;
29
29
 
30
+ const pageBase = {currentPage: 1};
30
31
  const [open, setOpen] = useState((isOpen));
31
32
  const [confirmLoading, setConfirmLoading] = useState(false);
32
- const [pageInfo, setPageInfo] = useState<any>({});
33
- const [rowSelectionInfo, setRowSelectionInfo] = useState<any>({});
33
+ const [pageInfo, setPageInfo] = useState<any>(pageBase);
34
+ const [rowSelectionInfo, setRowSelectionInfo] = useState<any>();
34
35
  const [tagsInfo, setTagsInfo] = useState<any>([]);
35
36
  const [ModalCanceled, setModalCanceled] = useState<boolean>(false);
37
+ const [selectedData, setSelectedData] = useState<any>([]);
36
38
 
37
39
  useEffect(()=> {
38
40
  setOpen(isOpen);
@@ -49,27 +51,36 @@ export const ModalWithTable = (props: ModalWithTableProps) => {
49
51
  };
50
52
 
51
53
  useEffect(() => {
52
- modalData({
53
- "pageInfo": pageInfo,
54
- "rowSelectionInfo": rowSelectionInfo,
55
- "tagsInfo": tagsInfo,
56
- "open": open
57
- });
58
- }, [tagsInfo, pageInfo, rowSelectionInfo, open]);
54
+ if(!open) {
55
+ setPageInfo(pageBase);
56
+ }
59
57
 
60
- useEffect(() => {
61
- setTimeout(() => {
62
- ModalCanceled
63
- && modalData({
58
+ ModalCanceled
59
+ ? modalData({
64
60
  "pageInfo": {},
65
- "rowSelectionInfo": {},
61
+ "rowSelectionInfo": [],
66
62
  "tagsInfo": [],
67
- "open": open
68
- });
63
+ "open": open,
64
+ "selectedData": []
65
+ })
66
+ : modalData({
67
+ "pageInfo": pageInfo,
68
+ "rowSelectionInfo": rowSelectionInfo,
69
+ "tagsInfo": tagsInfo,
70
+ "open": open,
71
+ "selectedData": selectedData
72
+ });
73
+ }, [open]);
74
+
75
+ useEffect(() => {
76
+ const selectedRowKeys = rowSelectionInfo || tableData.rowSelection.selectedRowKeys;
77
+
78
+ const filteredArray = tableData?.dataSource?.filter((element) => {
79
+ return selectedRowKeys.includes(element[tableData.rowKeyValue as any]);
80
+ });
69
81
 
70
- setModalCanceled(false);
71
- }, 100);
72
- },[ModalCanceled]);
82
+ setSelectedData(filteredArray);
83
+ }, [rowSelectionInfo])
73
84
 
74
85
  useEffect(()=> {
75
86
  if(tagsInfo.length > 0) {
@@ -0,0 +1,45 @@
1
+ import { Meta, Story } from "@storybook/react";
2
+ import { Form, UploadFile } from "antd";
3
+ import { Button } from "components/Button";
4
+ import { Upload } from '.';
5
+
6
+ export default {
7
+ title: 'Upload',
8
+ component: Upload,
9
+ } as Meta;
10
+
11
+ const Template: Story<any> = (args) => {
12
+ const [form] = Form.useForm();
13
+
14
+ const handleSubmit = (values: any) => {
15
+ console.log('Form values:', values);
16
+ };
17
+
18
+ const handleImageChange = (file: UploadFile | null) => {
19
+ form.setFieldsValue({ image: file });
20
+ };
21
+
22
+ const initialValue = {
23
+ uid: '-1',
24
+ name: 'image.png',
25
+ status: 'done',
26
+ url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
27
+ }
28
+ return (
29
+ <Form form={form} onFinish={handleSubmit}>
30
+ <Form.Item name="image" valuePropName="file" initialValue={initialValue}>
31
+ <Upload {...args} onImageChange={handleImageChange} initialFileList={[initialValue]}></Upload>
32
+ </Form.Item>
33
+ <Form.Item>
34
+ <Button type="primary" htmlType="submit">
35
+ Submit
36
+ </Button>
37
+ </Form.Item>
38
+ </Form>
39
+ )
40
+ }
41
+
42
+
43
+ export const Primary = Template.bind({});
44
+ Primary.args = {
45
+ };
@@ -0,0 +1,93 @@
1
+ import { Upload as UploadAntd } from 'antd';
2
+ import ImgCrop from 'antd-img-crop';
3
+ import type { RcFile, UploadFile, UploadProps } from 'antd/es/upload/interface';
4
+ import React, { useState } from 'react';
5
+ import imageCompression from 'browser-image-compression';
6
+
7
+ interface UploadPropsExtended extends UploadProps {
8
+ onImageChange?: (file: UploadFile | null) => void;
9
+ initialFileList?: UploadFile[];
10
+ }
11
+
12
+ export const Upload = (props: UploadPropsExtended) => {
13
+ const {
14
+ onImageChange,
15
+ initialFileList
16
+ } = props;
17
+ const [fileList, setFileList] = useState<UploadFile[]>(initialFileList || []);
18
+ console.log(fileList);
19
+
20
+ const compressImage = async (file: RcFile) => {
21
+ const options = {
22
+ maxSizeMB: 1,
23
+ maxWidthOrHeight: 1920,
24
+ useWebWorker: true,
25
+ };
26
+
27
+ try {
28
+ const compressedFile = await imageCompression(file, options);
29
+ return compressedFile;
30
+ } catch (error) {
31
+ console.error('Image compression failed:', error);
32
+ return file;
33
+ }
34
+ };
35
+
36
+ const beforeUpload: UploadProps['beforeUpload'] = async (file: RcFile) => {
37
+ const compressedFile = await compressImage(file);
38
+
39
+ const newFile: UploadFile = {
40
+ uid: file.uid,
41
+ name: file.name,
42
+ type: file.type,
43
+ size: compressedFile.size,
44
+ originFileObj: compressedFile as any,
45
+ status: 'done',
46
+ };
47
+
48
+ setFileList((prevFileList) => [...prevFileList, newFile]);
49
+ if (onImageChange) {
50
+ onImageChange(newFile);
51
+ }
52
+ return false;
53
+ };
54
+
55
+ const onChange: UploadProps['onChange'] = ({ file, fileList: newFileList }) => {
56
+ if (file.status === 'removed') {
57
+ setFileList(newFileList);
58
+ if (onImageChange) {
59
+ onImageChange(newFileList[0] || null);
60
+ }
61
+ }
62
+ };
63
+
64
+ const onPreview = async (file: UploadFile) => {
65
+ let src = file.url as string;
66
+ if (!src) {
67
+ src = await new Promise((resolve) => {
68
+ const reader = new FileReader();
69
+ reader.readAsDataURL(file.originFileObj as RcFile);
70
+ reader.onload = () => resolve(reader.result as string);
71
+ });
72
+ }
73
+ const image = new Image();
74
+ image.src = src;
75
+ const imgWindow = window.open(src);
76
+ imgWindow?.document.write(image.outerHTML);
77
+ };
78
+
79
+ return (
80
+ <ImgCrop rotationSlider>
81
+ <UploadAntd
82
+ action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
83
+ listType="picture-card"
84
+ fileList={fileList}
85
+ beforeUpload={beforeUpload}
86
+ onChange={onChange}
87
+ onPreview={onPreview}
88
+ >
89
+ {fileList.length < 1 && '+ Upload'}
90
+ </UploadAntd>
91
+ </ImgCrop>
92
+ );
93
+ };
@@ -19,3 +19,4 @@ export * from './Category';
19
19
  export * from './DatePickerTag';
20
20
  export * from './AnalyticsBar';
21
21
  export * from './CategoryResponse';
22
+ export * from './Upload';
@@ -1,6 +0,0 @@
1
- import { TagProps } from 'antd';
2
- export interface RangePickerTagProps extends TagProps {
3
- customTags?: any;
4
- tagsInfo?: any;
5
- }
6
- export declare const RangePickerTag: (props: RangePickerTagProps) => JSX.Element;