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.
@@ -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,3 @@
1
+ import { ColumnType } from "antd/es/table";
2
+ import { DataTableContext, DataTableProps } from "../typings";
3
+ export declare function useColumns<Record>(props: DataTableProps<Record>, ctx: DataTableContext): ColumnType<Record>[];
@@ -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 zh_CN from "antd/locale/zh_CN";
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 React from "react";
4
- export interface DataTableProps<Record = any> extends Omit<TableProps<Record>, 'dataSource' | 'title'> {
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
  }
@@ -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)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",