@uiw/react-form
Version:
Form component
87 lines • 2.84 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["prefixCls", "className", "required", "style", "label", "labelFor", "labelClassName", "labelStyle", "help", "inline", "initialValue", "validator", "hasError"];
import React from 'react';
import { Col, Row } from '@uiw/react-grid';
import "./style/form-item.css";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
export default class FormItem extends React.PureComponent {
render() {
var _this$props = this.props,
{
prefixCls,
className,
required,
style,
label,
labelFor,
labelClassName,
labelStyle,
help,
inline,
hasError
} = _this$props,
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
var cls = [prefixCls, className, hasError ? prefixCls + "-error" : null].filter(Boolean).join(' ').trim();
var labelCls = ['w-form-label', labelClassName].filter(Boolean).join(' ').trim();
if (inline) {
return /*#__PURE__*/_jsxs("div", _extends({
className: cls,
style: style
}, otherProps, {
children: [/*#__PURE__*/_jsxs(Row, {
children: [/*#__PURE__*/_jsxs(Col, {
fixed: true,
className: labelCls,
children: [required && /*#__PURE__*/_jsx("label", {
style: {
color: 'red'
},
children: "*"
}), /*#__PURE__*/_jsx("label", {
style: labelStyle,
htmlFor: labelFor,
children: label
})]
}), /*#__PURE__*/_jsx(Col, {
className: "w-form-row",
children: this.props.children
})]
}), help && /*#__PURE__*/_jsx(Row, {
children: /*#__PURE__*/_jsx(Col, {
className: "w-form-help",
children: help
})
})]
}));
}
return /*#__PURE__*/_jsxs("div", _extends({
className: cls,
style: style
}, otherProps, {
children: [label && /*#__PURE__*/_jsxs(React.Fragment, {
children: [required && /*#__PURE__*/_jsx("label", {
style: {
color: 'red'
},
children: "*"
}), /*#__PURE__*/_jsx("label", {
className: labelCls,
style: labelStyle,
htmlFor: labelFor,
children: label
})]
}), /*#__PURE__*/_jsx(Col, {
className: "w-form-row",
children: this.props.children
}), help && /*#__PURE__*/_jsx("div", {
className: "w-form-help",
children: help
})]
}));
}
}
FormItem.defaultProps = {
prefixCls: 'w-form-item'
};