import React from "react"; import classNames from "classnames"; import { StyledProps } from "../_type"; import { SlideTransition } from "../transition"; import { useConfig } from "../_util/config-context"; export interface FormControlProps extends StyledProps { /** * 表单组件 */ children?: React.ReactNode; /** * 字段状态 */ status?: "success" | "error" | "validating"; /** * 是否展示 icon * @default true */ showStatusIcon?: boolean; /** * 表单说明信息/错误信息 */ message?: React.ReactNode; /** * 表单额外说明信息 * * *可与 `message` 信息同时存在* * * @since 2.6.8 */ extra?: React.ReactNode; /** * 是否增加顶部间距,以对齐标签文本 * @default false */ alignLabelTop?: boolean; /** * 是否为必填字段 * @default false */ required?: boolean; } export const FormControl = React.forwardRef(function FormControl( { status, children, message, extra, alignLabelTop, showStatusIcon = true, className, ...props }: FormControlProps, ref: React.Ref ) { const { classPrefix } = useConfig(); const controlClassName = classNames( `${classPrefix}-form__controls`, { [`${classPrefix}-form__controls--text`]: alignLabelTop, [`is-${status}`]: status, }, className ); return (
{children} {showStatusIcon ? ( ) : ( )} {/* */} {Boolean(message) && (
{message}
)} {Boolean(extra) && (
{extra}
)} {/*
*/}
); }); FormControl.displayName = "FormControl";