listpage-next 0.0.47 → 0.0.50
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.
- package/dist/components/DataTable/components/DataTable.d.ts +2 -0
- package/dist/components/DataTable/components/DataTable.js +58 -0
- package/dist/components/DataTable/hooks/useColumns.js +25 -11
- package/dist/components/DataTable/index.d.ts +2 -2
- package/dist/components/DataTable/index.js +1 -58
- package/dist/components/DataTable/typings/index.d.ts +7 -2
- package/dist/demos/demo6.js +9 -2
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import styled_components from "styled-components";
|
|
3
|
+
import { Card, Pagination, Table } from "antd";
|
|
4
|
+
import { useColumns } from "../hooks/useColumns.js";
|
|
5
|
+
import { useData } from "../hooks/useData.js";
|
|
6
|
+
const PaginationContainer = styled_components.div`
|
|
7
|
+
padding: 12px 16px 12px 0;
|
|
8
|
+
border-top: 1px solid #f0f0f0;
|
|
9
|
+
`;
|
|
10
|
+
const TableContainer = styled_components.div`
|
|
11
|
+
table {
|
|
12
|
+
tr:last-child {
|
|
13
|
+
td {
|
|
14
|
+
border-bottom: none;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
const DataTable = (props)=>{
|
|
20
|
+
const { title, extra, dataSource, request, refreshDeps, ...restProps } = props;
|
|
21
|
+
const { data, loading, pagination, onPaginationChange } = useData({
|
|
22
|
+
dataSource,
|
|
23
|
+
request,
|
|
24
|
+
refreshDeps,
|
|
25
|
+
pagination: restProps.pagination
|
|
26
|
+
});
|
|
27
|
+
const columns = useColumns(props, {});
|
|
28
|
+
return /*#__PURE__*/ jsxs(Card, {
|
|
29
|
+
title: title,
|
|
30
|
+
extra: extra,
|
|
31
|
+
styles: {
|
|
32
|
+
body: {
|
|
33
|
+
padding: 0
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
children: [
|
|
37
|
+
/*#__PURE__*/ jsx(TableContainer, {
|
|
38
|
+
children: /*#__PURE__*/ jsx(Table, {
|
|
39
|
+
bordered: false,
|
|
40
|
+
loading: loading,
|
|
41
|
+
...restProps,
|
|
42
|
+
columns: columns,
|
|
43
|
+
dataSource: data,
|
|
44
|
+
pagination: false
|
|
45
|
+
})
|
|
46
|
+
}),
|
|
47
|
+
false !== restProps.pagination && /*#__PURE__*/ jsx(PaginationContainer, {
|
|
48
|
+
children: /*#__PURE__*/ jsx(Pagination, {
|
|
49
|
+
align: "end",
|
|
50
|
+
...pagination,
|
|
51
|
+
...restProps?.pagination,
|
|
52
|
+
onChange: onPaginationChange
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
export { DataTable };
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Typography } from "antd";
|
|
2
3
|
import { Render } from "../components/Render.js";
|
|
3
4
|
function useColumns(props, ctx) {
|
|
4
5
|
const { columns = [] } = props;
|
|
5
6
|
return columns.map((column)=>{
|
|
6
7
|
const getRender = ()=>{
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
if (column.component) {
|
|
9
|
+
if ('text' === column.component) return function(value, record, index) {
|
|
10
|
+
return textRender(value, column.props);
|
|
11
|
+
};
|
|
12
|
+
return function(value, record, index) {
|
|
13
|
+
return /*#__PURE__*/ jsx(Render, {
|
|
14
|
+
render: column.component,
|
|
15
|
+
defaultValue: value,
|
|
16
|
+
record: record,
|
|
17
|
+
index: index,
|
|
18
|
+
ctx: ctx
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return column.render;
|
|
18
23
|
};
|
|
19
24
|
return {
|
|
20
25
|
...column,
|
|
@@ -22,4 +27,13 @@ function useColumns(props, ctx) {
|
|
|
22
27
|
};
|
|
23
28
|
});
|
|
24
29
|
}
|
|
30
|
+
function textRender(value, props) {
|
|
31
|
+
return /*#__PURE__*/ jsx(Typography.Text, {
|
|
32
|
+
ellipsis: {
|
|
33
|
+
tooltip: true
|
|
34
|
+
},
|
|
35
|
+
...props,
|
|
36
|
+
children: value
|
|
37
|
+
});
|
|
38
|
+
}
|
|
25
39
|
export { useColumns };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
export * from './components/DataTable';
|
|
2
|
+
export { type DataTableColumns, type DataTableProps } from './typings';
|
|
@@ -1,58 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import styled_components from "styled-components";
|
|
3
|
-
import { Card, Pagination, Table } from "antd";
|
|
4
|
-
import { useColumns } from "./hooks/useColumns.js";
|
|
5
|
-
import { useData } from "./hooks/useData.js";
|
|
6
|
-
const PaginationContainer = styled_components.div`
|
|
7
|
-
padding: 12px 16px 12px 0;
|
|
8
|
-
border-top: 1px solid #f0f0f0;
|
|
9
|
-
`;
|
|
10
|
-
const TableContainer = styled_components.div`
|
|
11
|
-
table {
|
|
12
|
-
tr:last-child {
|
|
13
|
-
td {
|
|
14
|
-
border-bottom: none;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
`;
|
|
19
|
-
const DataTable = (props)=>{
|
|
20
|
-
const { title, extra, dataSource, request, refreshDeps, ...restProps } = props;
|
|
21
|
-
const { data, loading, pagination, onPaginationChange } = useData({
|
|
22
|
-
dataSource,
|
|
23
|
-
request,
|
|
24
|
-
refreshDeps,
|
|
25
|
-
pagination: restProps.pagination
|
|
26
|
-
});
|
|
27
|
-
const columns = useColumns(props, {});
|
|
28
|
-
return /*#__PURE__*/ jsxs(Card, {
|
|
29
|
-
title: title,
|
|
30
|
-
extra: extra,
|
|
31
|
-
styles: {
|
|
32
|
-
body: {
|
|
33
|
-
padding: 0
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
children: [
|
|
37
|
-
/*#__PURE__*/ jsx(TableContainer, {
|
|
38
|
-
children: /*#__PURE__*/ jsx(Table, {
|
|
39
|
-
bordered: false,
|
|
40
|
-
loading: loading,
|
|
41
|
-
...restProps,
|
|
42
|
-
columns: columns,
|
|
43
|
-
dataSource: data,
|
|
44
|
-
pagination: false
|
|
45
|
-
})
|
|
46
|
-
}),
|
|
47
|
-
false !== restProps.pagination && /*#__PURE__*/ jsx(PaginationContainer, {
|
|
48
|
-
children: /*#__PURE__*/ jsx(Pagination, {
|
|
49
|
-
align: "end",
|
|
50
|
-
...pagination,
|
|
51
|
-
...restProps?.pagination,
|
|
52
|
-
onChange: onPaginationChange
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
]
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
export { DataTable };
|
|
1
|
+
export * from "./components/DataTable.js";
|
|
@@ -3,6 +3,7 @@ import { TableProps } from "antd";
|
|
|
3
3
|
import { BaseQueryParams, PaginationData } from "../../../http-client";
|
|
4
4
|
import { ColumnType } from "antd/es/table";
|
|
5
5
|
import { ColumnRender } from "../components/Render";
|
|
6
|
+
import { TextProps } from "antd/es/typography/Text";
|
|
6
7
|
export interface DataTableProps<Record = any> extends Omit<TableProps<Record>, 'dataSource' | 'title' | 'columns'> {
|
|
7
8
|
dataSource?: Record[];
|
|
8
9
|
request?: (pageParams: BaseQueryParams) => Promise<PaginationData<Record>>;
|
|
@@ -11,8 +12,12 @@ export interface DataTableProps<Record = any> extends Omit<TableProps<Record>, '
|
|
|
11
12
|
extra?: React.ReactNode;
|
|
12
13
|
columns?: DataTableColumns<Record>[];
|
|
13
14
|
}
|
|
14
|
-
export
|
|
15
|
-
|
|
15
|
+
export type ComponentType = 'text';
|
|
16
|
+
export type ComponentProps = ComponentType extends 'text' ? TextComponentProps : unknown;
|
|
17
|
+
export type TextComponentProps = TextProps;
|
|
18
|
+
export interface DataTableColumns<Record = any> extends ColumnType<Record> {
|
|
19
|
+
component?: ComponentType | ColumnRender<Record>;
|
|
20
|
+
props?: ComponentProps;
|
|
16
21
|
}
|
|
17
22
|
export interface DataTableContext {
|
|
18
23
|
}
|
package/dist/demos/demo6.js
CHANGED
|
@@ -6,7 +6,7 @@ const columns = [
|
|
|
6
6
|
key: 'enable',
|
|
7
7
|
title: 'Enable',
|
|
8
8
|
dataIndex: 'enable',
|
|
9
|
-
|
|
9
|
+
component: (props)=>/*#__PURE__*/ jsx(Switch, {
|
|
10
10
|
size: "small",
|
|
11
11
|
checked: props.value,
|
|
12
12
|
onChange: (e)=>props.onChange(e)
|
|
@@ -14,8 +14,15 @@ const columns = [
|
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
title: 'Name',
|
|
17
|
+
width: 80,
|
|
17
18
|
dataIndex: 'name',
|
|
18
|
-
key: 'name'
|
|
19
|
+
key: 'name',
|
|
20
|
+
component: 'text',
|
|
21
|
+
props: {
|
|
22
|
+
ellipsis: {
|
|
23
|
+
tooltip: true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
19
26
|
},
|
|
20
27
|
{
|
|
21
28
|
title: 'Age',
|