listpage-next 0.0.130 → 0.0.132

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.
@@ -1,10 +1,10 @@
1
- import { SelectProps } from "antd";
2
- import { PaginationData } from "../../http-client";
1
+ import { SelectProps } from 'antd';
2
+ import { PaginationData } from '../../http-client';
3
3
  type BaseOption = {
4
4
  label: string;
5
5
  value: string;
6
6
  };
7
- export type AsyncSelectProps<Data extends BaseOption> = Omit<SelectProps, 'options'> & {
7
+ export type AsyncSelectProps<Data extends BaseOption = any> = Omit<SelectProps, 'options'> & {
8
8
  request: (parmas: {
9
9
  current: number;
10
10
  pageSize: number;
@@ -1,7 +1,3 @@
1
1
  import { ColumnType } from 'antd/es/table';
2
- import { DataTableContext, DataTableProps, LinkComponentProps, TagComponentProps, TextComponentProps, TimeComponentProps } from '../typings';
2
+ import { DataTableContext, DataTableProps } from '../typings';
3
3
  export declare function useColumns<Record>(props: DataTableProps<Record>, ctx: DataTableContext): ColumnType<Record>[];
4
- export declare function textRender(value: any, props?: TextComponentProps): import("react/jsx-runtime").JSX.Element;
5
- export declare function timeRender(value: any, props?: TimeComponentProps): import("react/jsx-runtime").JSX.Element;
6
- export declare function tagRender(value: any, props?: TagComponentProps): import("react/jsx-runtime").JSX.Element;
7
- export declare function linkRender(record: any, props?: LinkComponentProps): import("react/jsx-runtime").JSX.Element;
@@ -1,93 +1,9 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import dayjs from "dayjs";
3
- import { Tag, Typography } from "antd";
4
- import { Render } from "../components/Render.js";
5
- import { TextOverflow } from "../../TextOverflow/index.js";
6
- import { styled } from "styled-components";
1
+ import { createColumnRender } from "../utils/render.js";
7
2
  function useColumns(props, ctx) {
8
3
  const { columns = [] } = props;
9
- return columns.map((column)=>{
10
- const getRender = ()=>{
11
- if (column.component) {
12
- if ('text' === column.component) return function(value, record, index) {
13
- return textRender(value, column.props);
14
- };
15
- if ('time' === column.component) return function(value, record, index) {
16
- return timeRender(value, column.props);
17
- };
18
- if ('tag' === column.component) return function(value, record, index) {
19
- return tagRender(value, column.props);
20
- };
21
- if ('link' === column.component) return function(value, record, index) {
22
- return linkRender(record, column.props);
23
- };
24
- return function(value, record, index) {
25
- return /*#__PURE__*/ jsx(Render, {
26
- render: column.component,
27
- defaultValue: value,
28
- record: record,
29
- index: index,
30
- ctx: ctx
31
- });
32
- };
33
- }
34
- return column.render;
35
- };
36
- return {
4
+ return columns.map((column)=>({
37
5
  ...column,
38
- render: getRender()
39
- };
40
- });
6
+ render: createColumnRender(ctx, column)
7
+ }));
41
8
  }
42
- function textRender(value, props) {
43
- return /*#__PURE__*/ jsx(Typography.Text, {
44
- ellipsis: {
45
- tooltip: true
46
- },
47
- ...props,
48
- children: value
49
- });
50
- }
51
- function timeRender(value, props) {
52
- const time = value ? dayjs(value).format(props?.format) : '-';
53
- return /*#__PURE__*/ jsx("span", {
54
- children: time
55
- });
56
- }
57
- function tagRender(value, props) {
58
- return /*#__PURE__*/ jsx(Tag, {
59
- ...props,
60
- children: value
61
- });
62
- }
63
- function linkRender(record, props) {
64
- const getPropName = (propName)=>{
65
- if ('function' == typeof propName) return propName(record);
66
- return record[propName];
67
- };
68
- const title = getPropName(props?.titlePropName || 'title');
69
- const href = getPropName(props?.hrefPropName || 'href');
70
- const aLink = /*#__PURE__*/ jsx(LinkStyle, {
71
- href: href,
72
- target: props?.target,
73
- children: title
74
- });
75
- return /*#__PURE__*/ jsx(TextOverflow, {
76
- text: aLink,
77
- tooltipProps: {
78
- title
79
- }
80
- });
81
- }
82
- const LinkStyle = styled.a`
83
- color: #1677ff;
84
- &:hover {
85
- color: #69b1ff;
86
- }
87
- outline: 0;
88
- text-decoration: none;
89
- transition: color 0.3s;
90
- background-color: transparent;
91
- cursor: pointer;
92
- `;
93
- export { linkRender, tagRender, textRender, timeRender, useColumns };
9
+ export { useColumns };
@@ -1,9 +1,8 @@
1
- import React, { HTMLAttributeAnchorTarget, JSX } from 'react';
2
- import { TableProps, TagProps } from 'antd';
1
+ import React, { JSX } from 'react';
2
+ import { TableProps } from 'antd';
3
3
  import { BaseQueryParams, PaginationData } from '../../../http-client';
4
4
  import { ColumnType } from 'antd/es/table';
5
- import { TextProps } from 'antd/es/typography/Text';
6
- import { ColumnRender } from '../components/Render';
5
+ import { ColumnRenderProps } from './render';
7
6
  export interface DataTableProps<Record = any> extends Omit<TableProps<Record>, 'dataSource' | 'title' | 'columns'> {
8
7
  dataSource?: Record[];
9
8
  request?: (pageParams: BaseQueryParams) => Promise<PaginationData<Record>>;
@@ -16,24 +15,11 @@ export interface DataTableProps<Record = any> extends Omit<TableProps<Record>, '
16
15
  content: JSX.Element;
17
16
  }[];
18
17
  }
19
- export type ComponentType = 'text' | 'time' | 'tag' | 'link';
20
- export type ComponentProps = ComponentType extends 'text' ? TextComponentProps : ComponentType extends 'time' ? TimeComponentProps : ComponentType extends 'tag' ? TagComponentProps : ComponentType extends 'link' ? LinkComponentProps : unknown;
21
- export type TextComponentProps = TextProps;
22
- export type TimeComponentProps = {
23
- format?: string;
24
- };
25
- export type TagComponentProps = TagProps;
26
- export type LinkComponentProps = {
27
- titlePropName?: string | ((record: any) => string);
28
- hrefPropName?: string | ((record: any) => string);
29
- target?: HTMLAttributeAnchorTarget;
30
- };
31
- export interface DataTableColumns<Record = any, Context = any> extends ColumnType<Record> {
32
- component?: ComponentType | ColumnRender<Record, Context>;
33
- props?: ComponentProps;
18
+ export interface DataTableColumns<Record = any, Context = any> extends ColumnType<Record>, Omit<ColumnRenderProps<Record, Context>, 'render'> {
34
19
  }
35
20
  export interface DataTableContext {
36
21
  showFloat: (key: string, record: any) => void;
37
22
  hideFloat: (key: string) => void;
38
23
  refresh: () => void;
39
24
  }
25
+ export * from './render';
@@ -0,0 +1 @@
1
+ export * from "./render.js";
@@ -0,0 +1,21 @@
1
+ import { HTMLAttributeAnchorTarget } from 'react';
2
+ import { TagProps, TypographyProps } from 'antd';
3
+ import { ColumnType } from 'antd/es/table';
4
+ import { ColumnRender } from '../components/Render';
5
+ export type ComponentType = 'text' | 'time' | 'tag' | 'link';
6
+ export type ComponentProps = ComponentType extends 'text' ? TextComponentProps : ComponentType extends 'time' ? TimeComponentProps : ComponentType extends 'tag' ? TagComponentProps : ComponentType extends 'link' ? LinkComponentProps : unknown;
7
+ export type TextComponentProps = TypographyProps['Text'];
8
+ export type TimeComponentProps = {
9
+ format?: string;
10
+ };
11
+ export type TagComponentProps = TagProps;
12
+ export type LinkComponentProps = {
13
+ titlePropName?: string | ((record: any) => string);
14
+ hrefPropName?: string | ((record: any) => string);
15
+ target?: HTMLAttributeAnchorTarget;
16
+ };
17
+ export interface ColumnRenderProps<Record, Context> {
18
+ component?: ComponentType | ColumnRender<Record, Context>;
19
+ props?: ComponentProps;
20
+ render?: ColumnType<Record>['render'];
21
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ import { ColumnRenderProps } from '../typings/render';
2
+ export declare function createColumnRender<Record = any, Context = any, ColumnType extends ColumnRenderProps<Record, Context> = any>(ctx: Context, column: ColumnType): ColumnType['render'];
@@ -0,0 +1,90 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Tag, Typography } from "antd";
3
+ import { styled } from "styled-components";
4
+ import dayjs from "dayjs";
5
+ import { Render } from "../components/Render.js";
6
+ import { TextOverflow } from "../../TextOverflow/index.js";
7
+ function createColumnRender(ctx, column) {
8
+ if (column.component) {
9
+ if ('text' === column.component) return function(value, record, index) {
10
+ return textRender(value, column.props);
11
+ };
12
+ if ('time' === column.component) return function(value, record, index) {
13
+ return timeRender(value, column.props);
14
+ };
15
+ if ('tag' === column.component) return function(value, record, index) {
16
+ return tagRender(value, column.props);
17
+ };
18
+ if ('link' === column.component) return function(value, record, index) {
19
+ return linkRender(record, column.props);
20
+ };
21
+ return function(value, record, index) {
22
+ return /*#__PURE__*/ jsx(Render, {
23
+ render: column.component,
24
+ defaultValue: value,
25
+ record: record,
26
+ index: index,
27
+ ctx: ctx
28
+ });
29
+ };
30
+ }
31
+ return column.render;
32
+ }
33
+ function textRender(value, props) {
34
+ return /*#__PURE__*/ jsx(Typography.Text, {
35
+ ellipsis: {
36
+ tooltip: true
37
+ },
38
+ ...props,
39
+ children: value
40
+ });
41
+ }
42
+ function timeRender(value, props) {
43
+ try {
44
+ const time = value ? dayjs(value).format(props?.format) : '-';
45
+ return /*#__PURE__*/ jsx("span", {
46
+ children: time
47
+ });
48
+ } catch {
49
+ return /*#__PURE__*/ jsx("span", {
50
+ children: "-"
51
+ });
52
+ }
53
+ }
54
+ function tagRender(value, props) {
55
+ return /*#__PURE__*/ jsx(Tag, {
56
+ ...props,
57
+ children: value
58
+ });
59
+ }
60
+ function linkRender(record, props) {
61
+ const getPropName = (propName)=>{
62
+ if ('function' == typeof propName) return propName(record);
63
+ return record[propName];
64
+ };
65
+ const title = getPropName(props?.titlePropName || 'title');
66
+ const href = getPropName(props?.hrefPropName || 'href');
67
+ const aLink = /*#__PURE__*/ jsx(LinkStyle, {
68
+ href: href,
69
+ target: props?.target,
70
+ children: title
71
+ });
72
+ return /*#__PURE__*/ jsx(TextOverflow, {
73
+ text: aLink,
74
+ tooltipProps: {
75
+ title
76
+ }
77
+ });
78
+ }
79
+ const LinkStyle = styled.a`
80
+ color: #1677ff;
81
+ &:hover {
82
+ color: #69b1ff;
83
+ }
84
+ outline: 0;
85
+ text-decoration: none;
86
+ transition: color 0.3s;
87
+ background-color: transparent;
88
+ cursor: pointer;
89
+ `;
90
+ export { createColumnRender };
@@ -1,11 +1,12 @@
1
1
  import { ReactElement, ReactNode } from 'react';
2
2
  import { FormItemProps } from 'antd';
3
- import { ComponentType } from '../../typings';
4
- export interface FilterFormOption {
3
+ import { ComponentProps, ComponentType } from '../../typings';
4
+ export interface FilterFormOption<Type extends ComponentType = any> {
5
5
  name: string;
6
6
  label?: ReactNode;
7
- component?: ComponentType | ReactElement;
7
+ component?: Type | ReactElement;
8
8
  colSpan?: number;
9
+ props?: ComponentProps<Type>;
9
10
  formItemProps?: Omit<FormItemProps, 'children'>;
10
11
  }
11
12
  export interface FilterFormProps<FormValue = any> {
@@ -8,14 +8,14 @@ import { getComponent } from "../../utils/getComponent.js";
8
8
  import { cleanUpFormValues } from "../../utils/format.js";
9
9
  const FilterForm = ({ options, initialValues, onSubmit, onReset, labelInline })=>{
10
10
  const formRef = useRef(null);
11
- const items = useMemo(()=>(options ?? []).map(({ colSpan, component, label, ...props })=>{
12
- const renderComponent = getComponent(component);
11
+ const items = useMemo(()=>(options ?? []).map(({ colSpan, component, label, props, ...formItemProps })=>{
12
+ const renderComponent = getComponent(component, props);
13
13
  return {
14
- key: props.name,
14
+ key: formItemProps.name,
15
15
  node: /*#__PURE__*/ jsx(FilterItem, {
16
16
  labelInline: labelInline,
17
17
  label: label,
18
- formItemProps: props,
18
+ formItemProps: formItemProps,
19
19
  children: renderComponent
20
20
  }),
21
21
  colSpan: colSpan || 2
@@ -1 +1,12 @@
1
- export type ComponentType = 'input' | 'select';
1
+ import { InputProps, SelectProps } from 'antd';
2
+ import { RangePickerProps } from 'antd/es/date-picker';
3
+ import { AsyncSelectProps } from '../../AsyncSelect';
4
+ export type ComponentType = 'input' | 'select' | 'async-select' | 'daterange';
5
+ export type InputComponentProps = InputProps;
6
+ export type SelectComponentProps = SelectProps;
7
+ export type AsyncSelectComponentProps = AsyncSelectProps;
8
+ export type DateRangeComponentProps = {
9
+ value: [string, string];
10
+ onChange: (value: [string | null, string | null]) => void;
11
+ } & Omit<RangePickerProps, 'value' | 'onChange'>;
12
+ export type ComponentProps<ComponentType> = ComponentType extends 'input' ? InputComponentProps : ComponentType extends 'async-select' ? AsyncSelectComponentProps : ComponentType extends 'select' ? SelectComponentProps : ComponentType extends 'daterange' ? DateRangeComponentProps : unknown;
@@ -1,3 +1,3 @@
1
1
  import { ReactElement } from 'react';
2
2
  import { ComponentType } from '../typings/component';
3
- export declare const getComponent: (component?: ReactElement | ComponentType) => import("react/jsx-runtime").JSX.Element;
3
+ export declare const getComponent: (component?: ReactElement | ComponentType, props?: any) => import("react/jsx-runtime").JSX.Element;
@@ -1,16 +1,40 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { Input, Select } from "antd";
3
- const EnhancedInput = (props)=>/*#__PURE__*/ jsx(Input, {
2
+ import dayjs from "dayjs";
3
+ import { DatePicker, Input, Select } from "antd";
4
+ import { useMemo } from "react";
5
+ import { AsyncSelect } from "../../AsyncSelect/index.js";
6
+ const EnhancedRangePicker = (props)=>{
7
+ const { value, onChange } = props;
8
+ const realValue = useMemo(()=>(value ?? []).map((i)=>{
9
+ if (i) return dayjs(i);
10
+ }), [
11
+ value
12
+ ]);
13
+ return /*#__PURE__*/ jsx(DatePicker.RangePicker, {
4
14
  ...props,
5
- onChange: (e)=>props.onChange?.(e.target.value)
15
+ value: realValue,
16
+ onChange: (_, dates)=>{
17
+ onChange?.(dates);
18
+ }
6
19
  });
7
- const getComponent = (component)=>{
20
+ };
21
+ const getComponent = (component, props = {})=>{
8
22
  if ('string' == typeof component) {
9
23
  const type = component;
10
- if ('input' === type) return /*#__PURE__*/ jsx(EnhancedInput, {});
11
- if ('select' === type) return /*#__PURE__*/ jsx(Select, {});
24
+ if ('input' === type) return /*#__PURE__*/ jsx(Input, {
25
+ ...props
26
+ });
27
+ if ('select' === type) return /*#__PURE__*/ jsx(Select, {
28
+ ...props
29
+ });
30
+ if ('async-select' === type) return /*#__PURE__*/ jsx(AsyncSelect, {
31
+ ...props
32
+ });
33
+ if ('daterange' === type) return /*#__PURE__*/ jsx(EnhancedRangePicker, {
34
+ ...props
35
+ });
12
36
  }
13
37
  if (component) return component;
14
- return /*#__PURE__*/ jsx(EnhancedInput, {});
38
+ return /*#__PURE__*/ jsx(Input, {});
15
39
  };
16
40
  export { getComponent };
@@ -1,34 +1,10 @@
1
- import { jsx } from "react/jsx-runtime";
2
1
  import { useListPageStore } from "../context/listpage.js";
3
- import { textRender, timeRender } from "../../DataTable/hooks/useColumns.js";
4
- import { Render } from "../../DataTable/components/Render.js";
2
+ import { createColumnRender } from "../../DataTable/utils/render.js";
5
3
  function useColumns(columns) {
6
4
  const ctx = useListPageStore();
7
- return columns.map((column)=>{
8
- const getRender = ()=>{
9
- if (column.component) {
10
- if ('text' === column.component) return function(value, record, index) {
11
- return textRender(value, column.props);
12
- };
13
- if ('time' === column.component) return function(value, record, index) {
14
- return timeRender(value, column.props);
15
- };
16
- return function(value, record, index) {
17
- return /*#__PURE__*/ jsx(Render, {
18
- render: column.component,
19
- defaultValue: value,
20
- record: record,
21
- index: index,
22
- ctx: ctx
23
- });
24
- };
25
- }
26
- return column.render;
27
- };
28
- return {
5
+ return columns.map((column)=>({
29
6
  ...column,
30
- render: getRender()
31
- };
32
- });
7
+ render: createColumnRender(ctx, column)
8
+ }));
33
9
  }
34
10
  export { useColumns };
@@ -17,22 +17,19 @@ const columns = [
17
17
  width: 80,
18
18
  dataIndex: 'name',
19
19
  key: 'name',
20
- component: 'text',
21
- props: {
22
- ellipsis: {
23
- tooltip: true
24
- }
25
- }
26
- },
27
- {
28
- title: 'Age',
29
- dataIndex: 'age',
30
- key: 'age'
20
+ component: 'text'
31
21
  },
32
22
  {
33
- title: 'Address',
34
- dataIndex: 'address',
35
- key: 'address'
23
+ title: 'LINK',
24
+ dataIndex: 'link',
25
+ key: 'link',
26
+ width: 80,
27
+ component: 'link',
28
+ props: {
29
+ target: '_blank',
30
+ titlePropName: 'link',
31
+ hrefPropName: 'link'
32
+ }
36
33
  }
37
34
  ];
38
35
  const listdata = Array.from(new Array(100)).map((_, index)=>({
@@ -40,6 +37,7 @@ const listdata = Array.from(new Array(100)).map((_, index)=>({
40
37
  name: `Edward King ${index}`,
41
38
  age: 32,
42
39
  enable: true,
40
+ link: 'https://www.baidu.com',
43
41
  address: `London, Park Lane no. ${index}`
44
42
  }));
45
43
  const request = async (params)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next",
3
- "version": "0.0.130",
3
+ "version": "0.0.132",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",