1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | 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; };
|
8 |
|
9 | 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; }; }();
|
10 |
|
11 | var _react = require('react');
|
12 |
|
13 | var React = _interopRequireWildcard(_react);
|
14 |
|
15 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
16 |
|
17 | 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; }
|
18 |
|
19 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
20 |
|
21 | 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; }
|
22 |
|
23 | 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; }
|
24 |
|
25 | var Tabs = function (_React$Component) {
|
26 | _inherits(Tabs, _React$Component);
|
27 |
|
28 | function Tabs(props) {
|
29 | _classCallCheck(this, Tabs);
|
30 |
|
31 | var _this = _possibleConstructorReturn(this, (Tabs.__proto__ || Object.getPrototypeOf(Tabs)).call(this, props));
|
32 |
|
33 | _this.handleTabChange = _this.handleTabChange.bind(_this);
|
34 | _this.handleTabSequence = _this.handleTabSequence.bind(_this);
|
35 | _this.handleEdit = _this.handleEdit.bind(_this);
|
36 | _this.state = {
|
37 | activeIndex: _this.getActiveIndex(props)
|
38 | };
|
39 | return _this;
|
40 | }
|
41 |
|
42 | _createClass(Tabs, [{
|
43 | key: 'getActiveIndex',
|
44 | value: function getActiveIndex(props) {
|
45 | var defaultIndex = props.defaultIndex,
|
46 | activeIndex = props.activeIndex;
|
47 |
|
48 | if (activeIndex) return activeIndex;
|
49 | if (defaultIndex) return defaultIndex;
|
50 | return 0;
|
51 | }
|
52 | }, {
|
53 | key: 'componentWillReceiveProps',
|
54 | value: function componentWillReceiveProps(nextProps) {
|
55 | if (nextProps.activeIndex !== this.props.activeIndex) {
|
56 | this.setState({ activeIndex: nextProps.activeIndex });
|
57 | }
|
58 | }
|
59 | }, {
|
60 | key: 'handleTabChange',
|
61 | value: function handleTabChange(index) {
|
62 | var _props = this.props,
|
63 | activeIndex = _props.activeIndex,
|
64 | onTabChange = _props.onTabChange;
|
65 |
|
66 | if (activeIndex !== 0 && !activeIndex) {
|
67 | this.setState({ activeIndex: index });
|
68 | }
|
69 | if (onTabChange) {
|
70 | onTabChange(index);
|
71 | }
|
72 | }
|
73 | }, {
|
74 | key: 'handleTabSequence',
|
75 | value: function handleTabSequence(_ref) {
|
76 | var oldIndex = _ref.oldIndex,
|
77 | newIndex = _ref.newIndex;
|
78 | var onTabSequenceChange = this.props.onTabSequenceChange;
|
79 |
|
80 | if (onTabSequenceChange) {
|
81 | onTabSequenceChange({ oldIndex: oldIndex, newIndex: newIndex });
|
82 | }
|
83 | }
|
84 | }, {
|
85 | key: 'handleEdit',
|
86 | value: function handleEdit(_ref2) {
|
87 | var type = _ref2.type,
|
88 | index = _ref2.index;
|
89 | var onTabEdit = this.props.onTabEdit;
|
90 |
|
91 | if (onTabEdit) {
|
92 | onTabEdit({ type: type, index: index });
|
93 | }
|
94 | }
|
95 | }, {
|
96 | key: 'render',
|
97 | value: function render() {
|
98 | var _props2 = this.props,
|
99 | children = _props2.children,
|
100 | extraProps = _objectWithoutProperties(_props2, ['children']);
|
101 |
|
102 | var activeIndex = this.state.activeIndex;
|
103 |
|
104 | var props = _extends({
|
105 | handleTabChange: this.handleTabChange,
|
106 | handleTabSequence: this.handleTabSequence,
|
107 | handleEdit: this.handleEdit,
|
108 | activeIndex: activeIndex
|
109 | }, extraProps);
|
110 |
|
111 | return React.createElement(
|
112 | 'div',
|
113 | null,
|
114 | React.Children.map(children, function (child) {
|
115 | return React.cloneElement(child, props);
|
116 | })
|
117 | );
|
118 | }
|
119 | }]);
|
120 |
|
121 | return Tabs;
|
122 | }(React.Component);
|
123 |
|
124 | Tabs.defaultProps = {
|
125 | showModalButton: 4,
|
126 | showArrowButton: 'auto',
|
127 | onTabChange: function onTabChange() {},
|
128 | onTabSequenceChange: function onTabSequenceChange() {},
|
129 | customStyle: {
|
130 | TabList: null,
|
131 | Tab: null,
|
132 | Panel: null,
|
133 | ActionButton: null
|
134 | }
|
135 | };
|
136 | exports.default = Tabs;
|
137 | module.exports = exports['default']; |
\ | No newline at end of file |