@alicd/crui-form-item
Version:
@alicd/next 中 Form.Item 组件能力的扩展,增加了错误的提示方式 showValidateType ,其他能力和 Form.Item 保持一致,必须放置在 Form 元素中
59 lines (52 loc) • 1.61 kB
JSX
import React from 'react';
import PropTypes from 'prop-types';
import classNames from "classnames";
import {Form} from '@alicd/next';
class FormItem extends React.Component {
static propTypes = {
showValidateType: PropTypes.oneOf([
'help', 'tooltip'
]),
validateTooltipAlign: PropTypes.oneOf([
"tl", "tr", "bl", "br",
]),
};
static defaultProps = {
showValidateType: 'help',
validateTooltipAlign: "tl",
};
render() {
const child = this.props.children;
const {label, labelCol, wrapperCol, help, extra, hasFeedback, style, className: classNameOrg, size, validateTooltipAlign } = this.props;
const className = classNames(classNameOrg, size ? [`next-form-item-${size}`] : []);
if (this.props.showValidateType === 'tooltip') {
return (<Form.Item
label={label}
labelCol={labelCol}
wrapperCol={wrapperCol}
extra={extra}
style={style}
size={size}
className={classNames(
className,
"form-tooltip-explain",
`form-tooltip-explain-${validateTooltipAlign}`)}
hasFeedback={hasFeedback} >
{child || this.props.value}
<span className="form-tooltip-explain-help">{help}</span>
</Form.Item>);
} else {
return (<Form.Item
label={label}
help={help}
labelCol={labelCol}
wrapperCol={wrapperCol}
extra={extra}
style={style}
size={size}
className={className}
hasFeedback={hasFeedback} >{child || this.props.value}</Form.Item>);
}
}
}
export default FormItem;