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 _reactDnd = require('react-dnd');
|
38 |
|
39 | var _reactDndHtml5Backend = require('react-dnd-html5-backend');
|
40 |
|
41 | var _reactDndHtml5Backend2 = _interopRequireDefault(_reactDndHtml5Backend);
|
42 |
|
43 | var Tabs = (function (_React$Component) {
|
44 | _inherits(Tabs, _React$Component);
|
45 |
|
46 | function Tabs(props) {
|
47 | _classCallCheck(this, _Tabs);
|
48 |
|
49 | _get(Object.getPrototypeOf(_Tabs.prototype), 'constructor', this).call(this, props);
|
50 | this.handleTabClick = this.handleTabClick.bind(this);
|
51 | this.handleAddFrontClick = this.handleAddFrontClick.bind(this);
|
52 | this.handleAddBackClick = this.handleAddBackClick.bind(this);
|
53 | this.handleTabDeleteButton = this.handleTabDeleteButton.bind(this);
|
54 | this.moveTab = this.moveTab.bind(this);
|
55 | this._getPanel = this._getPanel.bind(this);
|
56 |
|
57 | this.state = {
|
58 | activeKey: props.activeKey || props.defaultActiveKey,
|
59 | style: props.style || props.defaultStyle,
|
60 | children: props.children,
|
61 | status: 'static'
|
62 | };
|
63 | }
|
64 |
|
65 | _createClass(Tabs, [{
|
66 | key: 'componentWillReceiveProps',
|
67 | value: function componentWillReceiveProps(nextProps) {
|
68 | if (nextProps.activeKey !== this.state.activeKey) {
|
69 | this.setState({
|
70 | activeKey: nextProps.activeKey
|
71 | });
|
72 | }
|
73 | if (nextProps.children !== this.state.children) {
|
74 | this.setState({
|
75 | children: nextProps.children
|
76 | });
|
77 | }
|
78 | }
|
79 | }, {
|
80 | key: 'handleTabClick',
|
81 | value: function handleTabClick(activeKey) {
|
82 | if (this.props.handleTabClick) {
|
83 | this.props.handleTabClick(activeKey);
|
84 | }
|
85 |
|
86 | this.setState({
|
87 | activeKey: activeKey,
|
88 | panelUpdateKey: -1
|
89 | });
|
90 | }
|
91 | }, {
|
92 | key: 'handleAddFrontClick',
|
93 | value: function handleAddFrontClick() {
|
94 | this.props.handleAddFrontClick();
|
95 | this.setState({
|
96 | panelUpdateKey: 0
|
97 | });
|
98 | }
|
99 | }, {
|
100 | key: 'handleAddBackClick',
|
101 | value: function handleAddBackClick() {
|
102 | this.props.handleAddBackClick();
|
103 | }
|
104 | }, {
|
105 | key: 'handleTabDeleteButton',
|
106 | value: function handleTabDeleteButton(key) {
|
107 | this.props.handleTabDeleteButton();
|
108 | this.setState({
|
109 | panelUpdateKey: key
|
110 | });
|
111 | }
|
112 | }, {
|
113 | key: 'moveTab',
|
114 | value: function moveTab(dragIndex, hoverIndex) {
|
115 | var dragTab = this.state.children[dragIndex];
|
116 | this.props.setMoveData(dragIndex, hoverIndex);
|
117 | }
|
118 | }, {
|
119 | key: '_getPanel',
|
120 | value: function _getPanel() {
|
121 | var that = this;
|
122 | var tab = [];
|
123 | var panel = [];
|
124 | _react2['default'].Children.forEach(this.state.children, function (children, index) {
|
125 |
|
126 | var status, className;
|
127 | if (index === that.state.activeKey) {
|
128 | status = 'active';
|
129 | } else {
|
130 | status = 'inactive';
|
131 | }
|
132 |
|
133 | tab.push(_react2['default'].createElement(_Tab2['default'], { key: 'tab' + index,
|
134 | tabKey: index,
|
135 | title: children.props.title,
|
136 | status: status,
|
137 | style: that.state.style,
|
138 | handleTabClick: that.handleTabClick,
|
139 | tabDeleteButton: that.props.tabDeleteButton,
|
140 | handleTabDeleteButton: that.handleTabDeleteButton,
|
141 | beginDrag: that.props.beginDrag,
|
142 | moveTab: that.moveTab }));
|
143 | if (!children.props.lazy || children.props.lazy && index === that.state.activeKey) {
|
144 | var props = { className: (0, _classnames2['default'])(that.state.style + 'panel', status), status: status, key: index };
|
145 | if (that.state.panelUpdateKey === index) {
|
146 | props.update = true;
|
147 | }
|
148 | panel.push(_react2['default'].cloneElement(children, props));
|
149 | }
|
150 | });
|
151 | if (this.props.addFrontTab && tab.length > 0) {
|
152 |
|
153 | tab.unshift(_react2['default'].createElement(_FunctionTab2['default'], { key: 'ADDFront',
|
154 | tabKey: 'ADD',
|
155 | title: '+',
|
156 | style: that.state.style,
|
157 | handleTabClick: that.handleAddFrontClick }));
|
158 | }
|
159 | if (this.props.addBackTab && tab.length > 0) {
|
160 |
|
161 | tab.push(_react2['default'].createElement(_FunctionTab2['default'], { key: 'ADDBack',
|
162 | tabKey: 'ADD',
|
163 | title: '+',
|
164 | style: that.state.style,
|
165 | handleTabClick: that.handleAddBackClick }));
|
166 | }
|
167 |
|
168 | return { tab: tab, panel: panel };
|
169 | }
|
170 | }, {
|
171 | key: 'render',
|
172 | value: function render() {
|
173 | var deleteButtonTmpl;
|
174 | var opt = this._getPanel();
|
175 | var wrapper = this.state.style + "wrapper";
|
176 | var tabWrapper = this.state.style + "tab__wrapper";
|
177 | var panelWrapper = this.state.style + "panel__wrapper";
|
178 | var noneName = this.props.deleteAllButtonName;
|
179 | if (this.props.deleteAllButton && opt.tab.length > 0) {
|
180 | var className = this.state.style + "delete button btn-primary bg-red";
|
181 | deleteButtonTmpl = _react2['default'].createElement(
|
182 | 'button',
|
183 | { className: className, onClick: this.props.handleDeleteAllButton },
|
184 | noneName ? noneName : 'None'
|
185 | );
|
186 | }
|
187 |
|
188 | return _react2['default'].createElement(
|
189 | 'div',
|
190 | { className: wrapper },
|
191 | deleteButtonTmpl,
|
192 | _react2['default'].createElement(
|
193 | 'div',
|
194 | { className: tabWrapper },
|
195 | opt.tab
|
196 | ),
|
197 | _react2['default'].createElement(
|
198 | 'div',
|
199 | { className: panelWrapper },
|
200 | opt.panel
|
201 | )
|
202 | );
|
203 | }
|
204 | }], [{
|
205 | key: 'defaultProps',
|
206 | value: {
|
207 | defaultActiveKey: 0,
|
208 | defaultStyle: "tabtab__default__"
|
209 | },
|
210 | enumerable: true
|
211 | }]);
|
212 |
|
213 | var _Tabs = Tabs;
|
214 | Tabs = (0, _reactDnd.DragDropContext)(_reactDndHtml5Backend2['default'])(Tabs) || Tabs;
|
215 | return Tabs;
|
216 | })(_react2['default'].Component);
|
217 |
|
218 | exports['default'] = Tabs;
|
219 | module.exports = exports['default']; |
\ | No newline at end of file |