/* eslint-disable react/destructuring-assignment */ import React, { Component } from 'react'; import classNames from 'classnames'; import { isString } from 'lodash'; import { isValid } from '@douyinfe/semi-foundation/form/utils'; import { cssClasses } from '@douyinfe/semi-foundation/form/constants'; import * as ObjectUtil from '@douyinfe/semi-foundation/utils/object'; import ErrorMessage, { ReactFieldError } from './errorMessage'; import Label, { LabelProps } from './label'; import { FormUpdaterContext } from './context'; import { useFormState } from './hooks/index'; import InputGroup, { InputGroupProps as BacisInputGroupProps } from '../input/inputGroup'; import { BaseFormProps, FormState } from './interface'; interface GroupErrorProps { showValidateIcon?: boolean; isInInputGroup?: boolean; error?: ReactFieldError; fieldSet?: string[]; } export interface InputGroupProps extends BacisInputGroupProps { label?: LabelProps; labelPosition?: 'left' | 'top'; } const prefix = cssClasses.PREFIX; // Group component to remove Labels and ErrorMessages from its child fields // Unified insertion of Labels and ErrorMessages from the group level // Get Errors of all field in this group const GroupError = (props: GroupErrorProps) => { const { fieldSet } = props; const formState: FormState = useFormState(); const error = fieldSet.map((field: string) => ObjectUtil.get(formState.errors, field)); if (isValid(error)) { return null; } return ( ); }; class FormInputGroup extends Component { static contextType = FormUpdaterContext; renderLabel(label: LabelProps, formProps: BaseFormProps) { if (label) { if (isString(label)) { return (