UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

96 lines (77 loc) 3.16 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _typeof from "@babel/runtime/helpers/typeof"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["className", "children", "compact"]; import React, { Children, isValidElement, useContext } from 'react'; import classNames from 'classnames'; import isNil from 'lodash/isNil'; import isFunction from 'lodash/isFunction'; import omit from 'lodash/omit'; import ConfigContext from '../../../es/config-provider/ConfigContext'; import isFragment from '../_util/isFragment'; import { ShowHelp } from '../field/enum'; var ItemGroup = function ItemGroup(props) { var className = props.className, children = props.children, compact = props.compact, otherProps = _objectWithoutProperties(props, _excluded); var _useContext = useContext(ConfigContext), getProPrefixCls = _useContext.getProPrefixCls; var prefixCls = getProPrefixCls('form-item-group'); var cls = classNames(className, prefixCls, _defineProperty({}, "".concat(prefixCls, "-compact"), compact)); var mapChildren = function mapChildren(child) { if (! /*#__PURE__*/isValidElement(child)) { return undefined; } if (isFragment(child) && child.props) { return Children.map(child.props.children, function (innerChild) { return mapChildren(innerChild); }); } var itemStyle = {}; if (child.props && child.props.style && (child.props.style.originalWidth || child.props.style.width)) { if (child.props.style.width !== '100%') { itemStyle = { width: child.props.style.width }; child.props.style.originalWidth = child.props.style.width; } else { itemStyle = { width: child.props.style.originalWidth || child.props.style.width }; } child.props.style.width = '100%'; } if ((isFunction(child.type) || _typeof(child.type) === 'object') && child.type.__PRO_FORM_ITEM) { return mapChildren(child.props.children); } var childCls = ''; if (compact) { var suffixCls = child.props.suffixCls; var _prefixCls = getProPrefixCls(suffixCls); childCls = "".concat(_prefixCls, "-compact"); } return /*#__PURE__*/React.createElement("span", { className: "".concat(prefixCls, "-item ").concat(childCls), style: _objectSpread({}, itemStyle) }, child); }; var childes = Children.map(children, function (child) { return mapChildren(child); }); if (isNil(childes)) { return null; } var passProps = omit(otherProps, ['label', 'labelWidth', 'labelTooltip', 'help', 'showHelp', 'required', 'useColon', 'requiredMarkAlign', 'colSpan', 'rowSpan', 'newLine']); return /*#__PURE__*/React.createElement("span", _extends({ className: cls }, passProps), childes); }; ItemGroup.displayName = 'ItemGroup'; ItemGroup.defaultProps = { showHelp: ShowHelp.label }; export default ItemGroup; //# sourceMappingURL=ItemGroup.js.map