listpage-next 0.0.131 → 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;
@@ -40,10 +40,16 @@ function textRender(value, props) {
40
40
  });
41
41
  }
42
42
  function timeRender(value, props) {
43
- const time = value ? dayjs(value).format(props?.format) : '-';
44
- return /*#__PURE__*/ jsx("span", {
45
- children: time
46
- });
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
+ }
47
53
  }
48
54
  function tagRender(value, props) {
49
55
  return /*#__PURE__*/ jsx(Tag, {
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next",
3
- "version": "0.0.131",
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",