import React from 'react'; import { Col, Row } from '@uiw/react-grid'; import { IProps, HTMLInputProps } from '@uiw/utils'; import { FormFieldsProps } from './Form'; import './style/form-item.less'; export interface FormItemProps extends IProps, HTMLInputProps { inline?: boolean; hasError?: boolean; label?: React.ReactNode; required?: boolean; labelFor?: string; labelClassName?: string; help?: React.ReactNode; labelStyle?: React.CSSProperties; initialValue?: string | number | T; validator?: FormFieldsProps['validator']; } export default class FormItem extends React.PureComponent> { public static defaultProps = { prefixCls: 'w-form-item', }; render() { const { prefixCls, className, required, style, label, labelFor, labelClassName, labelStyle, help, inline, initialValue, validator, hasError, ...otherProps } = this.props; const cls = [prefixCls, className, hasError ? `${prefixCls}-error` : null].filter(Boolean).join(' ').trim(); const labelCls = ['w-form-label', labelClassName].filter(Boolean).join(' ').trim(); if (inline) { return (
{required && } {this.props.children} {help && ( {help} )}
); } return (
{label && ( {required && } )} {this.props.children} {help &&
{help}
}
); } }