3.0.0 • Published 11 months ago

@kne/react-form-helper v3.0.0

Weekly downloads
27
License
ISC
Repository
github
Last release
11 months ago

react-form-helper

描述

react-form的辅助工具包

安装

npm i --save @kne/react-form-helper

概述

桥接UI组件库的Form输入组件和@kne/react-form

示例(全屏)

示例代码

  • 基本示例
  • 简单的form到input组件的绑定
  • _ReactFormHelper(@kne/current-lib),antd(antd),_ReactForm(@kne/react-form),remoteLoader(@kne/remote-loader)
const { createWithRemoteLoader } = remoteLoader;
const { hooks, widget, utils } = _ReactFormHelper;
const { default: Form, useSubmit } = _ReactForm;
const { Input: InputField, Button, Flex } = antd;

const { useDecorator } = hooks;
const { EnterSubmit, FormStore, ScrollToError } = widget;

const Input = (props) => {
  const render = useDecorator(Object.assign({ placeholder: `请输入${props.label}` }, props));
  return render(InputField);
};

const SubmitButton = ({ type = 'primary', realTime, realtime, disabled = false, ...props }) => {
  const { isPass, isLoading, ...submitProps } = useSubmit(props);
  if (typeof realTime === 'boolean') {
    console.error(`warning: realTime参数已废弃,请使用realtime,后续版本可能回删除realTime的支持`);
  }
  return (<Button type={type} loading={isLoading}
                  disabled={disabled || (realtime ? !isPass : false)} {...props} {...submitProps} />);
};

const BaseExample = createWithRemoteLoader({
  modules: ['InfoPage', 'Modal@useConfirmModal']
})(({ remoteModules }) => {
  const [InfoPage, useConfirmModal] = remoteModules;
  const modal = useConfirmModal();
  const formInner = <Flex vertical gap="middle">
    <Input name="name" label="名称" rule="REQ LEN-0-10" />
    <Input name="email" label="邮箱" rule="REQ EMAIL" />
    <SubmitButton>提交</SubmitButton>
  </Flex>;
  return <InfoPage>
    <InfoPage.Part title="简单表单">
      <Form onSubmit={(data) => {
        modal({
          type: 'info', message: JSON.stringify(data, null, 2)
        });
      }}>
        {formInner}
      </Form>
    </InfoPage.Part>
    <InfoPage.Part title="自动滚动到错误位置">
      <Form onSubmit={(data) => {
        modal({
          type: 'info', message: JSON.stringify(data, null, 2)
        });
      }} onError={(errors) => {
        modal({
          type: 'error',
          message: JSON.stringify(errors.map((item) => ({ label: item.label, errMsg: item.errMsg })), null, 2)
        });
      }}>
        <ScrollToError />
        {formInner}
      </Form>
    </InfoPage.Part>
    <InfoPage.Part title="回车提交表单">
      <Form onSubmit={(data) => {
        modal({
          type: 'info', message: JSON.stringify(data, null, 2)
        });
      }} onError={(errors) => {
        modal({
          type: 'error',
          message: JSON.stringify(errors.map((item) => ({ label: item.label, errMsg: item.errMsg })), null, 2)
        });
      }}>
        <EnterSubmit>
          {formInner}
        </EnterSubmit>
      </Form>
    </InfoPage.Part>
    <InfoPage.Part title="表单缓存">
      <Form onSubmit={(data) => {
        modal({
          type: 'info', message: JSON.stringify(data, null, 2)
        });
      }} onError={(errors) => {
        modal({
          type: 'error',
          message: JSON.stringify(errors.map((item) => ({ label: item.label, errMsg: item.errMsg })), null, 2)
        });
      }}>
        <FormStore cache="test-form-cache" />
        <EnterSubmit>
          {formInner}
        </EnterSubmit>
      </Form>
    </InfoPage.Part>
  </InfoPage>;
});

render(<BaseExample />);

API

3.0.0-alpha.0

11 months ago

3.0.0

11 months ago

1.1.0

1 year ago

1.0.36

2 years ago

1.0.33

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.22

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.21

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.20

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.12

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

5 years ago

1.0.0-alpha.10

5 years ago

1.0.0-alpha.9

5 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha.0

5 years ago