ant-d pro ProFormText 二次封装

这里没啥好说的 只是单纯的合并了’password’ | ‘textArea’ 此外配合其他封装

/*
 * @Author: your name
 * @Date: 2021-10-28 18:01:14
 * @LastEditTime: 2022-02-22 15:19:03
 * @LastEditors: Mao 
 * @Description: In User Settings Edit
 * @FilePath: \archives-web\src\components\myComponents\myProFormText.tsx
 */
import { ProFormText, ProFormTextArea } from '@ant-design/pro-form';
import type { FieldProps, ProFormFieldItemProps } from '@ant-design/pro-form/lib/interface';
import type { InputProps } from 'antd';
import type { PasswordProps, TextAreaProps } from 'antd/lib/input';

interface IProps {
  isShow?: boolean;
  fieldProps?: FieldProps & InputProps & PasswordProps & TextAreaProps;
  type?: 'password' | 'textArea';
  formProps?: ProFormFieldItemProps<InputProps>;
  className?: string;
  disabled?: boolean;
}
const MyProFormText: React.FC<IProps> = (props) => {
  const createEl = () => {
    const { formProps, fieldProps, className } = props;
    if (props.isShow === false) {
      return null;
    }
    let el = (
      <ProFormText
        // 文本框去除首位空格  有name属性生效
        getValueFromEvent={(e) => {
          return e.target.value.toString().replace(/(^\s*)|(\s*$)/g, '');
        }}
        {...formProps}
        fieldProps={{ className: `${className}`, disabled: props.disabled, ...fieldProps }}
      />
    );

    if (props.type === 'password') {
      el = <ProFormText.Password {...formProps} fieldProps={{ ...fieldProps }} />;
    }
    if (props.type === 'textArea') {
      el = <ProFormTextArea {...formProps} fieldProps={{ ...fieldProps }} />;
    }
    return el;
  };

  return createEl();
};

export default MyProFormText;
{/* <MyProFormText
  type="textArea"
  formProps={{
    name: 'name',
    label: 'label名',
    rules: [{ required: true }],
  }}
  fieldProps={{ allowClear: true, placeholder: '请输入', style: { width: '180px' } }}
/> */}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值