@ecoding/components.antd 0.2.8 → 0.2.9
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,56 @@
|
|
|
1
|
+
import React, { memo, useMemo } from 'react';
|
|
2
|
+
import { Checkbox } from 'antd';
|
|
3
|
+
const ddStyle = {
|
|
4
|
+
display: "flex",
|
|
5
|
+
alignItems: "center",
|
|
6
|
+
height: 40,
|
|
7
|
+
border: "1px solid #eee",
|
|
8
|
+
padding: "0 10px",
|
|
9
|
+
marginTop: '8px'
|
|
10
|
+
};
|
|
11
|
+
const dtStyle = {
|
|
12
|
+
display: "flex",
|
|
13
|
+
alignItems: "center",
|
|
14
|
+
height: 26,
|
|
15
|
+
padding: "0 11px",
|
|
16
|
+
marginTop: '8px'
|
|
17
|
+
};
|
|
18
|
+
const TableProColumns = memo(({ columns, setColumns, disColumnRef }) => {
|
|
19
|
+
const checkedALl = useMemo(() => {
|
|
20
|
+
let flag = true;
|
|
21
|
+
if (columns.find((c) => c.checked === false)) {
|
|
22
|
+
flag = false;
|
|
23
|
+
}
|
|
24
|
+
return flag;
|
|
25
|
+
}, [columns]);
|
|
26
|
+
const changeAllHandler = (e) => {
|
|
27
|
+
disColumnRef.current = [];
|
|
28
|
+
const checked = e.target.checked;
|
|
29
|
+
const temp = columns.map((c) => {
|
|
30
|
+
c.checked = checked;
|
|
31
|
+
if (checked === false) {
|
|
32
|
+
disColumnRef.current.push(c.key);
|
|
33
|
+
}
|
|
34
|
+
return c;
|
|
35
|
+
});
|
|
36
|
+
setColumns(temp);
|
|
37
|
+
};
|
|
38
|
+
const changeHandler = (e, item) => {
|
|
39
|
+
const checked = e.target.checked;
|
|
40
|
+
const index = columns.findIndex((c) => c.key === item.key);
|
|
41
|
+
columns[index].checked = checked;
|
|
42
|
+
const newColumns = columns.concat([]);
|
|
43
|
+
if (checked === false && !disColumnRef.current.includes(item.key)) {
|
|
44
|
+
disColumnRef.current.push(item.key);
|
|
45
|
+
}
|
|
46
|
+
setColumns(newColumns);
|
|
47
|
+
};
|
|
48
|
+
return (React.createElement("dl", { style: { minWidth: 300 } },
|
|
49
|
+
React.createElement("dt", { style: dtStyle },
|
|
50
|
+
React.createElement(Checkbox, { checked: checkedALl, onChange: (e) => changeAllHandler(e) }, "ALL")),
|
|
51
|
+
columns.map((item) => {
|
|
52
|
+
return (React.createElement("dd", { style: ddStyle },
|
|
53
|
+
React.createElement(Checkbox, { checked: item.checked === false ? false : true, onChange: (e) => changeHandler(e, item) }, item.title)));
|
|
54
|
+
})));
|
|
55
|
+
});
|
|
56
|
+
export default TableProColumns;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
header?: React.ReactNode;
|
|
5
|
+
buttonArea?: React.ReactNode;
|
|
6
|
+
filterArea?: React.ReactElement;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
rowKey: string;
|
|
9
|
+
dataSource: any;
|
|
10
|
+
columns: any[];
|
|
11
|
+
operationColumn?: any[];
|
|
12
|
+
pagination?: any;
|
|
13
|
+
offsetY?: number;
|
|
14
|
+
filterTitle?: string;
|
|
15
|
+
columnsTitle?: string;
|
|
16
|
+
}
|
|
17
|
+
declare const TablePro: React.FC<IProps>;
|
|
18
|
+
export default TablePro;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { Popover, Button, Typography, Table } from 'antd';
|
|
3
|
+
import { FilterOutlined, MenuOutlined } from '@ant-design/icons';
|
|
4
|
+
import TableProColumns from "./columns";
|
|
5
|
+
const TablePro = memo(({ className, header, buttonArea, filterArea, loading, rowKey, dataSource, pagination, offsetY, columns, operationColumn, columnsTitle, filterTitle }) => {
|
|
6
|
+
const ref = useRef(null);
|
|
7
|
+
const disColumnRef = useRef([]);
|
|
8
|
+
const [y, setY] = useState('100%');
|
|
9
|
+
const [innerColumns, setColumns] = useState(columns);
|
|
10
|
+
const flexColumnStyle = {
|
|
11
|
+
display: 'flex',
|
|
12
|
+
height: '100%',
|
|
13
|
+
flexDirection: 'column'
|
|
14
|
+
};
|
|
15
|
+
const operationWrap = {
|
|
16
|
+
display: 'flex',
|
|
17
|
+
alignItems: 'center',
|
|
18
|
+
justifyContent: 'space-between',
|
|
19
|
+
marginBottom: 20
|
|
20
|
+
};
|
|
21
|
+
const [openFilter, setOpenFilter] = useState(false);
|
|
22
|
+
const [openColumnFilter, setOpenColumnFilter] = useState(false);
|
|
23
|
+
const hideOpenFilter = () => {
|
|
24
|
+
setOpenFilter(false);
|
|
25
|
+
};
|
|
26
|
+
const showColumns = useMemo(() => {
|
|
27
|
+
return innerColumns.filter((c) => c.checked !== false).concat(operationColumn || []);
|
|
28
|
+
}, [innerColumns]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (disColumnRef.current && disColumnRef.current.length > 0 && columns.length > 0) {
|
|
31
|
+
setColumns(columns.map((c) => {
|
|
32
|
+
if (disColumnRef.current.includes(c.key)) {
|
|
33
|
+
return Object.assign(Object.assign({}, c), { checked: false });
|
|
34
|
+
}
|
|
35
|
+
return c;
|
|
36
|
+
}));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (columns.length > 0) {
|
|
40
|
+
setColumns(columns);
|
|
41
|
+
}
|
|
42
|
+
}, [columns]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (ref.current && innerColumns.length > 0) {
|
|
45
|
+
const thead = ref.current.querySelector('thead');
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
if (offsetY && offsetY > 0) {
|
|
48
|
+
setY(ref.current.clientHeight - offsetY);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
setY(ref.current.clientHeight - (thead.clientHeight && thead.clientHeight + (pagination ? 64 : 20)));
|
|
52
|
+
}
|
|
53
|
+
}, 100);
|
|
54
|
+
}
|
|
55
|
+
}, [header, loading, innerColumns]);
|
|
56
|
+
return (React.createElement("div", { style: flexColumnStyle, className: className || '' },
|
|
57
|
+
header ? header : null,
|
|
58
|
+
React.createElement("div", { style: operationWrap },
|
|
59
|
+
buttonArea ? React.createElement("div", null, buttonArea) : null,
|
|
60
|
+
React.createElement("div", null,
|
|
61
|
+
filterArea ? (React.createElement(Popover, { placement: "leftBottom", title: React.createElement(Typography.Title, { level: 5 }, filterTitle), content: React.cloneElement(filterArea, { hide: hideOpenFilter }), trigger: "click", open: openFilter, onOpenChange: (newOpen) => {
|
|
62
|
+
setOpenFilter(newOpen);
|
|
63
|
+
} },
|
|
64
|
+
React.createElement(Button, { type: "text", icon: React.createElement(FilterOutlined, null) }, filterTitle))) : null,
|
|
65
|
+
innerColumns ? (React.createElement(Popover, { placement: "leftBottom", title: React.createElement(Typography.Title, { level: 5 }, columnsTitle), content: React.createElement(TableProColumns, { disColumnRef: disColumnRef, columns: innerColumns, setColumns: setColumns }), trigger: "click", open: openColumnFilter, onOpenChange: (newOpen) => {
|
|
66
|
+
setOpenColumnFilter(newOpen);
|
|
67
|
+
} },
|
|
68
|
+
React.createElement(Button, { type: "text", icon: React.createElement(MenuOutlined, null) }, columnsTitle))) : null)),
|
|
69
|
+
dataSource ? (React.createElement("div", { style: { height: '100%', overflow: 'hidden' }, ref: ref },
|
|
70
|
+
React.createElement(Table, { bordered: true, rowKey: rowKey, columns: showColumns, dataSource: dataSource, scroll: { y }, loading: loading, pagination: pagination || false }))) : null));
|
|
71
|
+
});
|
|
72
|
+
TablePro.defaultProps = {
|
|
73
|
+
filterTitle: "筛选",
|
|
74
|
+
columnsTitle: "显示列"
|
|
75
|
+
};
|
|
76
|
+
export default TablePro;
|
package/lib/index.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export { default as SingleImgUpload } from "./core/single-img-upload";
|
|
|
11
11
|
export { default as SingleFileUpload } from "./core/single-file-upload";
|
|
12
12
|
export { default as AsyncSelect } from "./core/async-select";
|
|
13
13
|
export { default as AsyncTransfer } from "./core/async-transfer";
|
|
14
|
+
export { default as TablePro } from "./core/table-pro";
|
|
14
15
|
export { default as Quill } from "./core/quill";
|
|
15
16
|
export { default as http } from "./helpers/http";
|
package/lib/index.js
CHANGED
|
@@ -11,5 +11,6 @@ export { default as SingleImgUpload } from "./core/single-img-upload";
|
|
|
11
11
|
export { default as SingleFileUpload } from "./core/single-file-upload";
|
|
12
12
|
export { default as AsyncSelect } from "./core/async-select";
|
|
13
13
|
export { default as AsyncTransfer } from "./core/async-transfer";
|
|
14
|
+
export { default as TablePro } from "./core/table-pro";
|
|
14
15
|
export { default as Quill } from "./core/quill";
|
|
15
16
|
export { default as http } from "./helpers/http";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"react-quill": "^2.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "70c2987ae1386cfce5977396381f641072ebcdda"
|
|
48
48
|
}
|