UNPKG

choerodon-ui

Version:

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

165 lines (143 loc) 7.06 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _createSuper from "@babel/runtime/helpers/createSuper"; import React, { isValidElement, cloneElement, Component } from 'react'; import classNames from 'classnames'; import omit from 'lodash/omit'; import toArray from 'lodash/toArray'; import isArray from 'lodash/isArray'; import animation from '../_util/openAnimation'; import CollapsePanel from './CollapsePanel'; import RcCollapse from '../rc-components/collapse'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import defaultLocale from '../locale-provider/default'; import ConfigContext from '../config-provider/ConfigContext'; var Collapse = /*#__PURE__*/function (_Component) { _inherits(Collapse, _Component); var _super = _createSuper(Collapse); function Collapse() { var _this; _classCallCheck(this, Collapse); _this = _super.apply(this, arguments); _this.renderExpandTextContent = function () { var _classNames; var panelProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var locale = arguments.length > 1 ? arguments[1] : undefined; var localeCode = arguments.length > 2 ? arguments[2] : undefined; var expandIconPositionCof = arguments.length > 3 ? arguments[3] : undefined; var customizePrefixCls = _this.props.prefixCls; var getPrefixCls = _this.context.getPrefixCls; var prefixCls = getPrefixCls('collapse', customizePrefixCls); var iconCls = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-expand-icon"), true), _defineProperty(_classNames, "".concat(prefixCls, "-expanded"), panelProps.isActive), _defineProperty(_classNames, "".concat(prefixCls, "-collapsed"), !panelProps.isActive), _classNames)); var icon = /*#__PURE__*/React.createElement("i", { className: iconCls }); return /*#__PURE__*/React.createElement(React.Fragment, null, expandIconPositionCof === 'left' && icon, panelProps.isActive ? /*#__PURE__*/React.createElement("span", { className: "".concat(prefixCls, "-expand-text"), style: { minWidth: localeCode === 'zh-cn' ? '0.38rem' : '0.52rem' } }, locale.fold) : /*#__PURE__*/React.createElement("span", { className: "".concat(prefixCls, "-expand-text"), style: { minWidth: localeCode === 'zh-cn' ? '0.38rem' : '0.52rem' } }, locale.unfold), expandIconPositionCof === 'right' && icon); }; _this.renderItems = function () { var _this$props = _this.props, children = _this$props.children, parentCollapsible = _this$props.collapsible; var arrayChildren = children; if (!isArray(children)) { arrayChildren = [children]; } return toArray(arrayChildren).map(function (child, index) { if ( /*#__PURE__*/isValidElement(child)) { var key = child.key || String(index); var _child$props = child.props, disabled = _child$props.disabled, collapsible = _child$props.collapsible; if (disabled) { var childProps = _objectSpread(_objectSpread({}, omit(child.props, 'disabled')), {}, { key: key, disabled: collapsible && (collapsible === 'header' || collapsible === 'icon') ? false : disabled }); return /*#__PURE__*/cloneElement(child, childProps); } return /*#__PURE__*/cloneElement(child, _objectSpread(_objectSpread({}, child.props), {}, { key: key, disabled: collapsible ? collapsible === 'disabled' : parentCollapsible === 'disabled' })); } return child; }); }; return _this; } _createClass(Collapse, [{ key: "render", value: function render() { var _classNames2, _this2 = this; var _this$props2 = this.props, customizePrefixCls = _this$props2.prefixCls, _this$props2$classNam = _this$props2.className, className = _this$props2$classNam === void 0 ? '' : _this$props2$classNam, expandIcon = _this$props2.expandIcon, bordered = _this$props2.bordered, expandIconPosition = _this$props2.expandIconPosition, trigger = _this$props2.trigger, ghost = _this$props2.ghost; var _this$context = this.context, getPrefixCls = _this$context.getPrefixCls, getConfig = _this$context.getConfig; var prefixCls = getPrefixCls('collapse', customizePrefixCls); var expandIconPositionCof = expandIconPosition || getConfig('collapseExpandIconPosition'); var expandIconCof = expandIcon || getConfig('collapseExpandIcon'); var triggerCof = trigger || getConfig('collapseTrigger'); var collapseClassName = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-borderless"), !bordered), _defineProperty(_classNames2, "".concat(prefixCls, "-text-action"), expandIconCof === 'text' && expandIconPositionCof === 'left'), _defineProperty(_classNames2, "".concat(prefixCls, "-trigger"), triggerCof === 'header'), _defineProperty(_classNames2, "".concat(prefixCls, "-ghost"), ghost), _defineProperty(_classNames2, "".concat(prefixCls, "-icon-position-").concat(expandIconPositionCof), true), _classNames2), className); var expandIconContent; if (typeof expandIconCof === 'function') { expandIconContent = function expandIconContent(panelProps) { return expandIconCof(panelProps); }; } else if (expandIconCof === 'text') { expandIconContent = function expandIconContent(panelProps) { return /*#__PURE__*/React.createElement(LocaleReceiver, { componentName: "Collapse", defaultLocale: defaultLocale.Collapse }, function (locale, localeCode) { return _this2.renderExpandTextContent(panelProps, locale, localeCode, expandIconPositionCof); }); }; } return /*#__PURE__*/React.createElement(RcCollapse, _extends({}, this.props, { expandIcon: expandIconContent, expandIconPosition: expandIconPositionCof, prefixCls: prefixCls, className: collapseClassName }), this.renderItems()); } }], [{ key: "contextType", get: function get() { return ConfigContext; } }]); return Collapse; }(Component); export { Collapse as default }; Collapse.displayName = 'Collapse'; Collapse.Panel = CollapsePanel; Collapse.defaultProps = { bordered: true, openAnimation: _objectSpread(_objectSpread({}, animation), {}, { appear: function appear() {} }) }; //# sourceMappingURL=Collapse.js.map