1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 |
|
7 | 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; }; })();
|
8 |
|
9 | var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
10 |
|
11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
12 |
|
13 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
14 |
|
15 | 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; }
|
16 |
|
17 | var _react = require('react');
|
18 |
|
19 | var _react2 = _interopRequireDefault(_react);
|
20 |
|
21 | var _reactLibUpdate = require('react/lib/update');
|
22 |
|
23 | var _reactLibUpdate2 = _interopRequireDefault(_reactLibUpdate);
|
24 |
|
25 | var _Tab = require('./Tab');
|
26 |
|
27 | var _Tab2 = _interopRequireDefault(_Tab);
|
28 |
|
29 | var _FunctionTab = require('./FunctionTab');
|
30 |
|
31 | var _FunctionTab2 = _interopRequireDefault(_FunctionTab);
|
32 |
|
33 | var _classnames = require('classnames');
|
34 |
|
35 | var _classnames2 = _interopRequireDefault(_classnames);
|
36 |
|
37 | var Tabs = (function (_React$Component) {
|
38 | _inherits(Tabs, _React$Component);
|
39 |
|
40 | function Tabs(props) {
|
41 | _classCallCheck(this, Tabs);
|
42 |
|
43 | _get(Object.getPrototypeOf(Tabs.prototype), 'constructor', this).call(this, props);
|
44 | this.handleTabClick = this.handleTabClick.bind(this);
|
45 | this.handleAddFrontClick = this.handleAddFrontClick.bind(this);
|
46 | this.handleAddBackClick = this.handleAddBackClick.bind(this);
|
47 | this.handleTabDeleteButton = this.handleTabDeleteButton.bind(this);
|
48 | this.moveTab = this.moveTab.bind(this);
|
49 | this._getPanel = this._getPanel.bind(this);
|
50 |
|
51 | this.state = {
|
52 | activeKey: props.activeKey || props.defaultActiveKey,
|
53 | style: props.style || props.defaultStyle,
|
54 | children: props.children,
|
55 | status: 'static'
|
56 | };
|
57 | }
|
58 |
|
59 | _createClass(Tabs, [{
|
60 | key: 'componentWillReceiveProps',
|
61 | value: function componentWillReceiveProps(nextProps) {
|
62 | if (nextProps.activeKey !== this.state.activeKey) {
|
63 | this.setState({
|
64 | activeKey: nextProps.activeKey
|
65 | });
|
66 | }
|
67 | if (nextProps.children !== this.state.children) {
|
68 | this.setState({
|
69 | children: nextProps.children
|
70 | });
|
71 | }
|
72 | }
|
73 | }, {
|
74 | key: 'handleTabClick',
|
75 | value: function handleTabClick(activeKey) {
|
76 | if (this.props.handleTabClick) {
|
77 | this.props.handleTabClick(activeKey);
|
78 | }
|
79 |
|
80 | this.setState({
|
81 | activeKey: activeKey,
|
82 | panelUpdateKey: -1
|
83 | });
|
84 | }
|
85 | }, {
|
86 | key: 'handleAddFrontClick',
|
87 | value: function handleAddFrontClick() {
|
88 | this.props.handleAddFrontClick();
|
89 | this.setState({
|
90 | panelUpdateKey: 0
|
91 | });
|
92 | }
|
93 | }, {
|
94 | key: 'handleAddBackClick',
|
95 | value: function handleAddBackClick() {
|
96 | this.props.handleAddBackClick();
|
97 | }
|
98 | }, {
|
99 | key: 'handleTabDeleteButton',
|
100 | value: function handleTabDeleteButton(key) {
|
101 | this.props.handleTabDeleteButton();
|
102 | this.setState({
|
103 | panelUpdateKey: key
|
104 | });
|
105 | }
|
106 | }, {
|
107 | key: 'moveTab',
|
108 | value: function moveTab(dragIndex, hoverIndex) {
|
109 | var dragTab = this.state.children[dragIndex];
|
110 | this.props.setMoveData(dragIndex, hoverIndex);
|
111 | }
|
112 | }, {
|
113 | key: '_getPanel',
|
114 | value: function _getPanel() {
|
115 | var that = this;
|
116 | var tab = [];
|
117 | var panel = [];
|
118 | _react2['default'].Children.forEach(this.state.children, function (children, index) {
|
119 |
|
120 | var status, className;
|
121 | if (index === that.state.activeKey) {
|
122 | status = 'active';
|
123 | } else {
|
124 | status = 'inactive';
|
125 | }
|
126 |
|
127 | tab.push(_react2['default'].createElement(_Tab2['default'], { key: 'tab' + index,
|
128 | tabKey: index,
|
129 | title: children.props.title,
|
130 | status: status,
|
131 | style: that.state.style,
|
132 | handleTabClick: that.handleTabClick,
|
133 | tabDeleteButton: that.props.tabDeleteButton,
|
134 | handleTabDeleteButton: that.handleTabDeleteButton,
|
135 | beginDrag: that.props.beginDrag,
|
136 | moveTab: that.moveTab }));
|
137 | if (!children.props.lazy || children.props.lazy && index === that.state.activeKey) {
|
138 | var props = { className: (0, _classnames2['default'])(that.state.style + 'panel', status), status: status, key: index };
|
139 | if (that.state.panelUpdateKey === index) {
|
140 | props.update = true;
|
141 | }
|
142 | panel.push(_react2['default'].cloneElement(children, props));
|
143 | }
|
144 | });
|
145 | if (this.props.addFrontTab && tab.length > 0) {
|
146 |
|
147 | tab.unshift(_react2['default'].createElement(_FunctionTab2['default'], { key: 'ADDFront',
|
148 | tabKey: 'ADD',
|
149 | title: '+',
|
150 | style: that.state.style,
|
151 | handleTabClick: that.handleAddFrontClick }));
|
152 | }
|
153 | if (this.props.addBackTab && tab.length > 0) {
|
154 |
|
155 | tab.push(_react2['default'].createElement(_FunctionTab2['default'], { key: 'ADDBack',
|
156 | tabKey: 'ADD',
|
157 | title: '+',
|
158 | style: that.state.style,
|
159 | handleTabClick: that.handleAddBackClick }));
|
160 | }
|
161 |
|
162 | return { tab: tab, panel: panel };
|
163 | }
|
164 | }, {
|
165 | key: 'render',
|
166 | value: function render() {
|
167 | var deleteButtonTmpl;
|
168 | var opt = this._getPanel();
|
169 | var wrapper = this.state.style + "wrapper";
|
170 | var tabWrapper = this.state.style + "tab__wrapper";
|
171 | var panelWrapper = this.state.style + "panel__wrapper";
|
172 | var noneName = this.props.deleteAllButtonName;
|
173 | if (this.props.deleteAllButton && opt.tab.length > 0) {
|
174 | var className = this.state.style + "delete " + this.props.deleteAllClassname;
|
175 | deleteButtonTmpl = _react2['default'].createElement(
|
176 | 'button',
|
177 | { className: className, onClick: this.props.handleDeleteAllButton },
|
178 | noneName ? noneName : 'None'
|
179 | );
|
180 | }
|
181 |
|
182 | return _react2['default'].createElement(
|
183 | 'div',
|
184 | { className: wrapper },
|
185 | deleteButtonTmpl,
|
186 | _react2['default'].createElement(
|
187 | 'div',
|
188 | { className: tabWrapper },
|
189 | opt.tab
|
190 | ),
|
191 | _react2['default'].createElement(
|
192 | 'div',
|
193 | { className: panelWrapper },
|
194 | opt.panel
|
195 | )
|
196 | );
|
197 | }
|
198 | }], [{
|
199 | key: 'defaultProps',
|
200 | value: {
|
201 | defaultActiveKey: 0,
|
202 | defaultStyle: "tabtab__default__"
|
203 | },
|
204 | enumerable: true
|
205 | }]);
|
206 |
|
207 | return Tabs;
|
208 | })(_react2['default'].Component);
|
209 |
|
210 | exports['default'] = Tabs;
|
211 | module.exports = exports['default']; |
\ | No newline at end of file |