yylib-quick-mobile
Version:
yylib-quick-mobile
145 lines (116 loc) • 5.87 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _accordion = require('antd-mobile/lib/accordion');
var _accordion2 = _interopRequireDefault(_accordion);
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
require('antd-mobile/lib/accordion/style/css');
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
require('./YYAccordion.less');
var _FunctionUtil = require('../../utils/FunctionUtil');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var YYAccordionDev = function (_Component) {
_inherits(YYAccordionDev, _Component);
function YYAccordionDev(props) {
_classCallCheck(this, YYAccordionDev);
var _this = _possibleConstructorReturn(this, (YYAccordionDev.__proto__ || Object.getPrototypeOf(YYAccordionDev)).call(this, props));
_this.onChange = function (e) {
_this.setState({ activeKey: e });
if ((0, _FunctionUtil.isFunction)(_this.props.onChange)) {
setTimeout(function () {
_this.props.onChange(e);
}, 300);
}
};
_this.state = {
activeKey: props.expandAll ? _this.getKey() : ['0']
};
return _this;
}
_createClass(YYAccordionDev, [{
key: 'getKey',
value: function getKey() {
var children = this.props.children;
children = children && children.constructor == Array ? children : [children];
var keys = [];
children && children.map(function (item, index) {
keys.push(String(index));
});
return keys;
}
}, {
key: 'getAccordionPanel',
value: function getAccordionPanel() {
var _props = this.props,
children = _props.children,
restProps = _objectWithoutProperties(_props, ['children']);
if (children) {
Array.prototype.slice.call(children);
children = children && children.constructor == Array ? children : [children];
return children.map(function (item, index) {
var _item$props = item.props,
uititle = _item$props.uititle,
badge = _item$props.badge,
icon = _item$props.icon,
selectedIcon = _item$props.selectedIcon,
iconColor = _item$props.iconColor,
selectedIconColor = _item$props.selectedIconColor,
dot = _item$props.dot,
selected = _item$props.selected,
nid = _item$props.nid,
child = _item$props.children;
return _react2.default.createElement(
_accordion2.default.Panel,
_extends({}, restProps, {
header: uititle,
key: index
}),
child
);
});
}
return [];
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextprops) {
this.setState({
activeKey: nextprops.expandAll ? this.getKey() : ['0']
});
}
}, {
key: 'render',
value: function render() {
var _props2 = this.props,
mode = _props2.mode,
visible = _props2.visible,
children = _props2.children,
restProps = _objectWithoutProperties(_props2, ['mode', 'visible', 'children']);
var wrapClz = (0, _classnames2.default)('yy-accordion', !visible && 'hidden', this.props.className);
return _react2.default.createElement(
_accordion2.default,
_extends({}, restProps, {
accordion: mode === 'accordion' ? true : false,
defaultActiveKey: this.state.activeKey,
activeKey: this.state.activeKey,
className: wrapClz,
onChange: this.onChange }),
this.getAccordionPanel()
);
}
}]);
return YYAccordionDev;
}(_react.Component);
YYAccordionDev.defaultProps = {
visible: true
};
exports.default = YYAccordionDev;
;