listpage-next 0.0.50 → 0.0.52
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 +1 -0
- package/dist/components/DataTable/components/DataTable.js +13 -3
- package/dist/components/DataTable/context/index.d.ts +14 -0
- package/dist/components/DataTable/context/index.js +48 -0
- package/dist/components/DataTable/hooks/useColumns.js +10 -0
- package/dist/components/DataTable/typings/index.d.ts +12 -3
- package/package.json +1 -1
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DataTableProps } from "../typings";
|
|
2
|
+
export declare const DataTableComponent: <Record = any>(props: DataTableProps<Record>) => import("react/jsx-runtime").JSX.Element;
|
|
2
3
|
export declare const DataTable: <Record = any>(props: DataTableProps<Record>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,6 +3,7 @@ import styled_components from "styled-components";
|
|
|
3
3
|
import { Card, Pagination, Table } from "antd";
|
|
4
4
|
import { useColumns } from "../hooks/useColumns.js";
|
|
5
5
|
import { useData } from "../hooks/useData.js";
|
|
6
|
+
import { FloatProvider, useFloatContext } from "../context/index.js";
|
|
6
7
|
const PaginationContainer = styled_components.div`
|
|
7
8
|
padding: 12px 16px 12px 0;
|
|
8
9
|
border-top: 1px solid #f0f0f0;
|
|
@@ -16,7 +17,7 @@ const TableContainer = styled_components.div`
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
`;
|
|
19
|
-
const
|
|
20
|
+
const DataTableComponent = (props)=>{
|
|
20
21
|
const { title, extra, dataSource, request, refreshDeps, ...restProps } = props;
|
|
21
22
|
const { data, loading, pagination, onPaginationChange } = useData({
|
|
22
23
|
dataSource,
|
|
@@ -24,7 +25,10 @@ const DataTable = (props)=>{
|
|
|
24
25
|
refreshDeps,
|
|
25
26
|
pagination: restProps.pagination
|
|
26
27
|
});
|
|
27
|
-
const
|
|
28
|
+
const floatCtx = useFloatContext();
|
|
29
|
+
const columns = useColumns(props, {
|
|
30
|
+
...floatCtx
|
|
31
|
+
});
|
|
28
32
|
return /*#__PURE__*/ jsxs(Card, {
|
|
29
33
|
title: title,
|
|
30
34
|
extra: extra,
|
|
@@ -55,4 +59,10 @@ const DataTable = (props)=>{
|
|
|
55
59
|
]
|
|
56
60
|
});
|
|
57
61
|
};
|
|
58
|
-
|
|
62
|
+
const DataTable = (props)=>/*#__PURE__*/ jsx(FloatProvider, {
|
|
63
|
+
floats: props.floats,
|
|
64
|
+
children: /*#__PURE__*/ jsx(DataTableComponent, {
|
|
65
|
+
...props
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
export { DataTable, DataTableComponent };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { JSX } from 'react';
|
|
2
|
+
export interface FloatContextProps {
|
|
3
|
+
showFloat: (key: string, record: any) => void;
|
|
4
|
+
hideFloat: (key: string) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const FloatContext: React.Context<FloatContextProps | undefined>;
|
|
7
|
+
export declare const useFloatContext: () => FloatContextProps;
|
|
8
|
+
export declare const FloatProvider: (props: {
|
|
9
|
+
floats?: {
|
|
10
|
+
key: string;
|
|
11
|
+
content: JSX.Element;
|
|
12
|
+
}[];
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cloneElement, createContext, useCallback, useContext, useRef, useState } from "react";
|
|
3
|
+
const FloatContext = /*#__PURE__*/ createContext(void 0);
|
|
4
|
+
const useFloatContext = ()=>{
|
|
5
|
+
const context = useContext(FloatContext);
|
|
6
|
+
if (!context) throw new Error('useFloatContext must be used within a FloatContextProvider');
|
|
7
|
+
return context;
|
|
8
|
+
};
|
|
9
|
+
const FloatProvider = (props)=>{
|
|
10
|
+
const { floats = [], children } = props;
|
|
11
|
+
const floatsMapRef = useRef({});
|
|
12
|
+
const [eles, setEles] = useState([]);
|
|
13
|
+
const showFloat = useCallback((key, record)=>{
|
|
14
|
+
if (!floatsMapRef.current[key]) {
|
|
15
|
+
const content = floats.find((i)=>i.key === key)?.content;
|
|
16
|
+
if (!content) return;
|
|
17
|
+
floatsMapRef.current[key] = /*#__PURE__*/ cloneElement(content, {
|
|
18
|
+
record
|
|
19
|
+
});
|
|
20
|
+
setEles([
|
|
21
|
+
...eles,
|
|
22
|
+
content
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
}, [
|
|
26
|
+
eles
|
|
27
|
+
]);
|
|
28
|
+
const hideFloat = useCallback((key)=>{
|
|
29
|
+
if (!floatsMapRef.current[key]) return;
|
|
30
|
+
setEles(eles.filter((i)=>i !== floatsMapRef.current[key]));
|
|
31
|
+
delete floatsMapRef.current[key];
|
|
32
|
+
}, [
|
|
33
|
+
eles
|
|
34
|
+
]);
|
|
35
|
+
return /*#__PURE__*/ jsx(FloatContext.Provider, {
|
|
36
|
+
value: {
|
|
37
|
+
showFloat,
|
|
38
|
+
hideFloat
|
|
39
|
+
},
|
|
40
|
+
children: /*#__PURE__*/ jsxs(Fragment, {
|
|
41
|
+
children: [
|
|
42
|
+
children,
|
|
43
|
+
eles
|
|
44
|
+
]
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
export { FloatContext, FloatProvider, useFloatContext };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import dayjs from "dayjs";
|
|
2
3
|
import { Typography } from "antd";
|
|
3
4
|
import { Render } from "../components/Render.js";
|
|
4
5
|
function useColumns(props, ctx) {
|
|
@@ -9,6 +10,9 @@ function useColumns(props, ctx) {
|
|
|
9
10
|
if ('text' === column.component) return function(value, record, index) {
|
|
10
11
|
return textRender(value, column.props);
|
|
11
12
|
};
|
|
13
|
+
if ('time' === column.component) return function(value, record, index) {
|
|
14
|
+
return timeRender(value, column.props);
|
|
15
|
+
};
|
|
12
16
|
return function(value, record, index) {
|
|
13
17
|
return /*#__PURE__*/ jsx(Render, {
|
|
14
18
|
render: column.component,
|
|
@@ -36,4 +40,10 @@ function textRender(value, props) {
|
|
|
36
40
|
children: value
|
|
37
41
|
});
|
|
38
42
|
}
|
|
43
|
+
function timeRender(value, props) {
|
|
44
|
+
const time = value ? dayjs(value).format(props?.format) : '-';
|
|
45
|
+
return /*#__PURE__*/ jsx("span", {
|
|
46
|
+
children: time
|
|
47
|
+
});
|
|
48
|
+
}
|
|
39
49
|
export { useColumns };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { JSX } from "react";
|
|
2
2
|
import { TableProps } from "antd";
|
|
3
3
|
import { BaseQueryParams, PaginationData } from "../../../http-client";
|
|
4
4
|
import { ColumnType } from "antd/es/table";
|
|
@@ -11,13 +11,22 @@ export interface DataTableProps<Record = any> extends Omit<TableProps<Record>, '
|
|
|
11
11
|
title?: React.ReactNode;
|
|
12
12
|
extra?: React.ReactNode;
|
|
13
13
|
columns?: DataTableColumns<Record>[];
|
|
14
|
+
floats?: {
|
|
15
|
+
key: string;
|
|
16
|
+
content: JSX.Element;
|
|
17
|
+
}[];
|
|
14
18
|
}
|
|
15
|
-
export type ComponentType = 'text';
|
|
16
|
-
export type ComponentProps = ComponentType extends 'text' ? TextComponentProps : unknown;
|
|
19
|
+
export type ComponentType = 'text' | 'time';
|
|
20
|
+
export type ComponentProps = ComponentType extends 'text' ? TextComponentProps : ComponentType extends 'time' ? TimeComponentProps : unknown;
|
|
17
21
|
export type TextComponentProps = TextProps;
|
|
22
|
+
export type TimeComponentProps = {
|
|
23
|
+
format?: string;
|
|
24
|
+
};
|
|
18
25
|
export interface DataTableColumns<Record = any> extends ColumnType<Record> {
|
|
19
26
|
component?: ComponentType | ColumnRender<Record>;
|
|
20
27
|
props?: ComponentProps;
|
|
21
28
|
}
|
|
22
29
|
export interface DataTableContext {
|
|
30
|
+
showFloat: (key: string, record: any) => void;
|
|
31
|
+
hideFloat: (key: string) => void;
|
|
23
32
|
}
|