import { FC, ReactElement, ReactNode } from 'react'; import { ItemTypeProps } from './itemType'; import { validateFunctionType } from './validateFunction'; import { LabelProps } from '../Label'; import { HelperTextProps } from '../HelperText'; import './index.scss'; export type formInputType = 'checkGroup' | 'select' | 'radioGroup' | 'textarea' | 'default' | 'switch' | 'number' | 'file' | 'comboSelect' | ReactNode | string | FC; /** * 表单操作项的其他配置 */ interface inputProps { [name: string]: any; } /** * 校验规则 * 一条校验规则对应一个错误提示 */ export interface ruleType { /** * 校验方法 * @return {boolean | string}, 子定义校验方法时 返回 false 或 字符串 均为校验失败 true为校验通过 */ validate?: { required?: boolean | validateFunctionType; maxlength?: number | validateFunctionType; minLength?: number | validateFunctionType; pattern?: RegExp | validateFunctionType; disOnlySpace?: boolean | validateFunctionType; [name: string]: validateFunctionType | boolean | number | RegExp | undefined; }; message?: { [name: string]: string; }; } /** * form 表单组件属性 * @typedef {Object} FormItemProps */ export interface FormItemProps { /** * 表单项形态,默认 horizontal */ type?: 'vertical' | 'horizontal'; /** * 输入框类型 * 仅支持para-ui/code/里面有的数据组件 */ itemType?: formInputType; /** * 输入框类型 * 仅支持para-ui/code/里面有的数据组件 */ InputType?: formInputType; /** * 输入框其他属性配置 */ inputProps?: inputProps; /** * label props */ labelProps?: LabelProps; /** * 报错提示其他配置 */ helperTextProps?: HelperTextProps; /** * 文字宽度, 只对 type === vertical,状态下生效 */ labelWidth?: number; /** * 是否禁用 */ disabled?: boolean; /** * 值改变传出 */ change?: (value: any) => void; /** * 不显示 该选项 */ hide?: boolean; /** * 提示。会有label上出现个图标提示 */ tips?: string; /** * 文字描述 */ label?: string | ((props: FormItemProps) => ReactNode); /** * 隐藏 label */ hideLabel?: boolean; /** * 隐藏 error */ hideError?: boolean; /** * name,一般对应后台属性,需要唯一性 */ name: string; /** * 校验规则 */ rules?: ruleType; /** * 设置值的方法 */ setValue?: Function; /** * 报错信息 */ errorMessage?: string; /** * 回填数据 */ backData?: { [name: string]: any; }; /** * 是否启用必填框,不允许输入纯空格 */ disOnlySpace?: boolean; /** * 必填显示渲染方式 */ requiredElement?: ReactElement | string; /** * 隐藏默认必填标记 */ disRequiredElement?: boolean; /** * 其他配置 */ [name: string]: any; /** * 自定义class */ className?: string; /** * 默认值 * 会被backData,回填数据替换 */ defaultValue?: any; /** * 是否是paraui表单组件 * */ isComponent?: boolean; } /** * form 表单单行组件 * @author zhanzl * @description 用于根据配置自动生成表单 */ declare const FormItem: FC; export default FormItem;