@jdcfe/yep-react
Version:
一套移动端的React组件库
71 lines (59 loc) • 2.73 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import * as React from 'react';
import classNames from 'classnames';
var CollapseGroup = /*#__PURE__*/function (_React$PureComponent) {
_inherits(CollapseGroup, _React$PureComponent);
var _super = _createSuper(CollapseGroup);
function CollapseGroup(props) {
var _this;
_classCallCheck(this, CollapseGroup);
_this = _super.call(this, props);
_this.state = {
defaultOpenIndex: props.defaultOpenIndex
};
return _this;
}
_createClass(CollapseGroup, [{
key: "onToggle",
value: function onToggle(isOpen, index) {
this.setState({
defaultOpenIndex: isOpen ? index : -1
});
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var _this$props = this.props,
className = _this$props.className,
prefixCls = _this$props.prefixCls,
style = _this$props.style;
var cls = classNames(className, prefixCls);
var defaultOpenIndex = this.state.defaultOpenIndex;
var children = React.Children.toArray(this.props.children);
return /*#__PURE__*/React.createElement("div", {
className: cls,
style: style
}, children.map(function (item, index) {
return /*#__PURE__*/React.cloneElement(item, {
isOpen: index === defaultOpenIndex,
onToggle: function onToggle(isOpen) {
return _this2.onToggle(isOpen, index);
}
});
}));
}
}]);
return CollapseGroup;
}(React.PureComponent);
export { CollapseGroup as default };
CollapseGroup.defaultProps = {
prefixCls: 'Yep-collapses',
style: {}
};