listpage-next 0.0.153 → 0.0.155

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,4 +1,7 @@
1
1
  import { SwitchProps } from 'antd';
2
+ export interface AsyncSwitchProps extends SwitchProps {
3
+ syncChange?: (value: boolean) => Promise<void>;
4
+ }
2
5
  export declare const AsyncSwitch: (props: SwitchProps & {
3
6
  syncChange?: (value: boolean) => Promise<void>;
4
7
  }) => import("react/jsx-runtime").JSX.Element;
@@ -19,9 +19,10 @@ const AsyncSwitch = (props)=>{
19
19
  setLoading(true);
20
20
  try {
21
21
  await props.syncChange?.(checked);
22
+ } catch {
23
+ onChange(!checked);
22
24
  } finally{
23
25
  setLoading(false);
24
- onChange(!checked);
25
26
  }
26
27
  }
27
28
  });
@@ -1,5 +1,5 @@
1
1
  import { HTMLAttributeAnchorTarget } from 'react';
2
- import { TagProps, TypographyProps } from 'antd';
2
+ import { SwitchProps, TagProps, TypographyProps } from 'antd';
3
3
  import { ColumnType } from 'antd/es/table';
4
4
  import { ColumnRender } from '../components/Render';
5
5
  export type ComponentType = 'text' | 'time' | 'tag' | 'link' | 'switch';
@@ -14,7 +14,9 @@ export type LinkComponentProps = {
14
14
  hrefPropName?: string | ((record: any) => string);
15
15
  target?: HTMLAttributeAnchorTarget;
16
16
  };
17
- export type SwitchComponentProps = {};
17
+ export type SwitchComponentProps = SwitchProps & {
18
+ syncChange?: (value: boolean, record: any) => Promise<void>;
19
+ };
18
20
  export interface ColumnRenderProps<Record, Context> {
19
21
  component?: ComponentType | ColumnRender<Record, Context>;
20
22
  props?: ComponentProps;
@@ -8,19 +8,19 @@ import { AsyncSwitch } from "../../AsyncSwitch/index.js";
8
8
  function createColumnRender(ctx, column) {
9
9
  if (column.component) {
10
10
  if ('text' === column.component) return function(value, record, index) {
11
- return textRender(value, column.props);
11
+ return textRender(value, record, column.props);
12
12
  };
13
13
  if ('time' === column.component) return function(value, record, index) {
14
- return timeRender(value, column.props);
14
+ return timeRender(value, record, column.props);
15
15
  };
16
16
  if ('tag' === column.component) return function(value, record, index) {
17
- return tagRender(value, column.props);
17
+ return tagRender(value, record, column.props);
18
18
  };
19
19
  if ('link' === column.component) return function(value, record, index) {
20
- return linkRender(record, column.props);
20
+ return linkRender(value, record, column.props);
21
21
  };
22
22
  if ('switch' === column.component) return function(value, record, index) {
23
- return switchRender(value, column.props);
23
+ return switchRender(value, record, column.props);
24
24
  };
25
25
  return function(value, record, index) {
26
26
  return /*#__PURE__*/ jsx(Render, {
@@ -34,7 +34,7 @@ function createColumnRender(ctx, column) {
34
34
  }
35
35
  return column.render;
36
36
  }
37
- function textRender(value, props) {
37
+ function textRender(value, record, props) {
38
38
  return /*#__PURE__*/ jsx(Typography.Text, {
39
39
  ellipsis: {
40
40
  tooltip: true
@@ -43,7 +43,7 @@ function textRender(value, props) {
43
43
  children: value
44
44
  });
45
45
  }
46
- function timeRender(value, props) {
46
+ function timeRender(value, record, props) {
47
47
  try {
48
48
  const time = value ? dayjs(value).format(props?.format) : '-';
49
49
  return /*#__PURE__*/ jsx("span", {
@@ -55,13 +55,13 @@ function timeRender(value, props) {
55
55
  });
56
56
  }
57
57
  }
58
- function tagRender(value, props) {
58
+ function tagRender(value, record, props) {
59
59
  return /*#__PURE__*/ jsx(Tag, {
60
60
  ...props,
61
61
  children: value
62
62
  });
63
63
  }
64
- function linkRender(record, props) {
64
+ function linkRender(value, record, props) {
65
65
  const getPropName = (propName)=>{
66
66
  if ('function' == typeof propName) return propName(record);
67
67
  return record[propName];
@@ -80,10 +80,13 @@ function linkRender(record, props) {
80
80
  }
81
81
  });
82
82
  }
83
- function switchRender(value, props) {
83
+ function switchRender(value, record, props) {
84
84
  return /*#__PURE__*/ jsx(AsyncSwitch, {
85
85
  defaultValue: value,
86
- ...props
86
+ ...props,
87
+ syncChange: async (checked)=>{
88
+ await props?.syncChange?.(checked, record);
89
+ }
87
90
  });
88
91
  }
89
92
  const LinkStyle = styled.a`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next",
3
- "version": "0.0.153",
3
+ "version": "0.0.155",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",