UNPKG

acud

Version:

acg react 组件库

56 lines • 2.16 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import * as React from 'react'; import RcCollapse from 'rc-collapse'; import classNames from 'classnames'; import OutlinedRight from "acud-icon/es/icons/OutlinedRight"; import toArray from "rc-util/es/Children/toArray"; import CollapsePanel from './CollapsePanel'; import { ConfigContext } from '../config-provider'; import collapseMotion from '../_util/motion'; import { cloneElement } from '../_util/reactNode'; var Collapse = function Collapse(props) { var _React$useContext = React.useContext(ConfigContext), getPrefixCls = _React$useContext.getPrefixCls; var customizePrefixCls = props.prefixCls, _props$className = props.className, className = _props$className === void 0 ? '' : _props$className; var prefixCls = getPrefixCls('collapse', customizePrefixCls); var renderExpandIcon = function renderExpandIcon() { var panelProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var icon = /*#__PURE__*/React.createElement(OutlinedRight, { rotate: panelProps.isActive ? 90 : undefined }); return cloneElement(icon, function () { return { className: classNames(icon.props.className, "".concat(prefixCls, "-arrow")) }; }); }; var openMotion = _extends(_extends({}, collapseMotion), { motionAppear: false, leavedClassName: "".concat(prefixCls, "-content-hidden") }); var getItems = function getItems() { var children = props.children; return toArray(children).map(function (child, index) { var _a; if ((_a = child.props) === null || _a === void 0 ? void 0 : _a.disabled) { var key = child.key || String(index); var childProps = _extends(_extends({}, child.props), { key: key }); return cloneElement(child, childProps); } return child; }); }; return /*#__PURE__*/React.createElement(RcCollapse, _extends({ openMotion: openMotion }, props, { expandIcon: renderExpandIcon, prefixCls: prefixCls, className: className }), getItems()); }; Collapse.Panel = CollapsePanel; export default Collapse;