listpage-next 0.0.46 → 0.0.48
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/Render.d.ts +18 -0
- package/dist/components/DataTable/components/Render.js +14 -0
- package/dist/components/DataTable/hooks/useColumns.d.ts +3 -0
- package/dist/components/DataTable/hooks/useColumns.js +24 -0
- package/dist/components/DataTable/index.js +5 -5
- package/dist/components/DataTable/typings/index.d.ts +10 -2
- package/dist/demos/demo6.js +12 -1
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JSX } from "react";
|
|
2
|
+
import { DataTableContext } from "../typings";
|
|
3
|
+
export interface RenderProps<T, Record> {
|
|
4
|
+
ctx: DataTableContext;
|
|
5
|
+
defaultValue: T;
|
|
6
|
+
record: Record;
|
|
7
|
+
index: number;
|
|
8
|
+
render: (props: UserRenderComponentProps<T, Record>) => JSX.Element;
|
|
9
|
+
}
|
|
10
|
+
export type UserRenderComponentProps<T, Record> = {
|
|
11
|
+
ctx: DataTableContext;
|
|
12
|
+
value: T;
|
|
13
|
+
onChange: (v: T) => void;
|
|
14
|
+
record: Record;
|
|
15
|
+
index: number;
|
|
16
|
+
};
|
|
17
|
+
export type ColumnRender<R> = <T = any>(props: UserRenderComponentProps<T, R>) => JSX.Element;
|
|
18
|
+
export declare const Render: <T = any, Record = any>(props: RenderProps<T, Record>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useControllableValue } from "ahooks";
|
|
3
|
+
const Render = (props)=>{
|
|
4
|
+
const { render: Component, record, index, ctx } = props;
|
|
5
|
+
const [value, onChange] = useControllableValue(props);
|
|
6
|
+
return /*#__PURE__*/ jsx(Component, {
|
|
7
|
+
value: value,
|
|
8
|
+
onChange: onChange,
|
|
9
|
+
record: record,
|
|
10
|
+
index: index,
|
|
11
|
+
ctx: ctx
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export { Render };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Render } from "../components/Render.js";
|
|
3
|
+
function useColumns(props, ctx) {
|
|
4
|
+
const { columns = [] } = props;
|
|
5
|
+
return columns.map((column)=>{
|
|
6
|
+
const getRender = ()=>{
|
|
7
|
+
if (column.component) return function(value, record, index) {
|
|
8
|
+
return /*#__PURE__*/ jsx(Render, {
|
|
9
|
+
render: column.component,
|
|
10
|
+
defaultValue: value,
|
|
11
|
+
record: record,
|
|
12
|
+
index: index,
|
|
13
|
+
ctx: ctx
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
return column.render;
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
...column,
|
|
20
|
+
render: getRender()
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export { useColumns };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import styled_components from "styled-components";
|
|
2
3
|
import { Card, Pagination, Table } from "antd";
|
|
3
|
-
import
|
|
4
|
+
import { useColumns } from "./hooks/useColumns.js";
|
|
4
5
|
import { useData } from "./hooks/useData.js";
|
|
5
|
-
import styled_components from "styled-components";
|
|
6
6
|
const PaginationContainer = styled_components.div`
|
|
7
7
|
padding: 12px 16px 12px 0;
|
|
8
8
|
border-top: 1px solid #f0f0f0;
|
|
@@ -24,6 +24,7 @@ const DataTable = (props)=>{
|
|
|
24
24
|
refreshDeps,
|
|
25
25
|
pagination: restProps.pagination
|
|
26
26
|
});
|
|
27
|
+
const columns = useColumns(props, {});
|
|
27
28
|
return /*#__PURE__*/ jsxs(Card, {
|
|
28
29
|
title: title,
|
|
29
30
|
extra: extra,
|
|
@@ -37,16 +38,15 @@ const DataTable = (props)=>{
|
|
|
37
38
|
children: /*#__PURE__*/ jsx(Table, {
|
|
38
39
|
bordered: false,
|
|
39
40
|
loading: loading,
|
|
40
|
-
locale: zh_CN.Table,
|
|
41
41
|
...restProps,
|
|
42
|
+
columns: columns,
|
|
42
43
|
dataSource: data,
|
|
43
44
|
pagination: false
|
|
44
45
|
})
|
|
45
46
|
}),
|
|
46
|
-
/*#__PURE__*/ jsx(PaginationContainer, {
|
|
47
|
+
false !== restProps.pagination && /*#__PURE__*/ jsx(PaginationContainer, {
|
|
47
48
|
children: /*#__PURE__*/ jsx(Pagination, {
|
|
48
49
|
align: "end",
|
|
49
|
-
locale: zh_CN.Pagination,
|
|
50
50
|
...pagination,
|
|
51
51
|
...restProps?.pagination,
|
|
52
52
|
onChange: onPaginationChange
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import { TableProps } from "antd";
|
|
2
3
|
import { BaseQueryParams, PaginationData } from "../../../http-client";
|
|
3
|
-
import
|
|
4
|
-
|
|
4
|
+
import { ColumnType } from "antd/es/table";
|
|
5
|
+
import { ColumnRender } from "../components/Render";
|
|
6
|
+
export interface DataTableProps<Record = any> extends Omit<TableProps<Record>, 'dataSource' | 'title' | 'columns'> {
|
|
5
7
|
dataSource?: Record[];
|
|
6
8
|
request?: (pageParams: BaseQueryParams) => Promise<PaginationData<Record>>;
|
|
7
9
|
refreshDeps?: any[];
|
|
8
10
|
title?: React.ReactNode;
|
|
9
11
|
extra?: React.ReactNode;
|
|
12
|
+
columns?: DataTableColumns<Record>[];
|
|
13
|
+
}
|
|
14
|
+
export interface DataTableColumns<Record = any> extends ColumnType<Record> {
|
|
15
|
+
component?: ColumnRender<Record>;
|
|
16
|
+
}
|
|
17
|
+
export interface DataTableContext {
|
|
10
18
|
}
|
package/dist/demos/demo6.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Button } from "antd";
|
|
2
|
+
import { Button, Switch } from "antd";
|
|
3
3
|
import { DataTable } from "../components/DataTable/index.js";
|
|
4
4
|
const columns = [
|
|
5
|
+
{
|
|
6
|
+
key: 'enable',
|
|
7
|
+
title: 'Enable',
|
|
8
|
+
dataIndex: 'enable',
|
|
9
|
+
render: (props)=>/*#__PURE__*/ jsx(Switch, {
|
|
10
|
+
size: "small",
|
|
11
|
+
checked: props.value,
|
|
12
|
+
onChange: (e)=>props.onChange(e)
|
|
13
|
+
})
|
|
14
|
+
},
|
|
5
15
|
{
|
|
6
16
|
title: 'Name',
|
|
7
17
|
dataIndex: 'name',
|
|
@@ -22,6 +32,7 @@ const listdata = Array.from(new Array(100)).map((_, index)=>({
|
|
|
22
32
|
key: index,
|
|
23
33
|
name: `Edward King ${index}`,
|
|
24
34
|
age: 32,
|
|
35
|
+
enable: true,
|
|
25
36
|
address: `London, Park Lane no. ${index}`
|
|
26
37
|
}));
|
|
27
38
|
const request = async (params)=>{
|