loners-form
Version:
为工作而生,基于 antd 而生的可配置化表单
51 lines (50 loc) • 2.62 kB
TypeScript
import type { ReactNode } from 'react';
import type { ColProps } from 'antd/lib/grid/col';
import type { FormInstance } from 'antd/lib/form';
import type { RowProps } from 'antd/lib/row';
import type { FormItemProps } from 'antd/lib/form/FormItem';
import type { RadioGroupProps } from 'antd/lib/radio/interface';
import type { CommonSelectGoProps } from '../SelectGo';
import type { RangePickerGoProps } from '../RangePickerGo';
import type { InputGoProps } from '../InputGo';
import type { TextAreaGoProps } from '../TextareaGo';
import type { InputNumberGoProps } from '../InputNumberGo';
import type { InputLoadingGoProps } from '../InputLoadingGo';
import type { SwitchGoProps } from '../SwitchGo';
import type { ShowQA } from '../interface';
export declare type FormToolAction = 'edit' | 'add' | 'readonly';
export declare type ShowFunc = (fm: FormInstance, action?: FormToolAction) => boolean;
export declare type FormItemType = 'InputText' | 'SimpleSelect' | 'RadioGroup' | 'RangePicker' | 'InputNumber' | 'Switch' | 'InputLoading' | 'Textarea' | 'Customize' | string | undefined;
export declare type SyncToQueryFunc = (queryValue: string | number, urlParams: Record<string, string | number>) => any;
export declare type SelectTool = CommonSelectGoProps;
export declare type InputTool = InputGoProps & InputNumberGoProps & InputLoadingGoProps & TextAreaGoProps;
export declare type RangePickerTool = RangePickerGoProps;
export declare type ExtraTool = RadioGroupProps & SwitchGoProps;
export declare type RadioTool = RadioGroupProps;
export declare type FieldProps = {
showQA?: ShowQA;
} & (InputTool | SelectTool | ExtraTool | RangePickerTool);
export declare type RenderFormItemProps = FormItemProps<any>;
export interface FormToolItem extends FormItemProps<any> {
type?: FormItemType;
show?: ShowFunc;
disabled?: (action?: FormToolAction) => boolean;
fieldProps?: FieldProps;
colProps?: ColProps;
/** 仅 type = Customize 生效 */
renderFormItem?: (fm: FormInstance, action?: FormToolAction, fieldProps?: {
disabled: boolean;
[key: string]: any;
}) => ReactNode;
/** 仅 type = Customize 生效 */
render?: (fm: FormInstance, action?: FormToolAction, formItemProps?: RenderFormItemProps) => ReactNode;
renderText?: (text: any, record: any, fm: FormInstance) => ReactNode;
/** 单独配置将 urlParams 同步到 query request */
syncToQuery?: boolean | SyncToQueryFunc;
}
export interface FormToolProps extends RowProps {
items?: FormToolItem[];
className?: string;
action?: FormToolAction;
children?: ReactNode;
}