-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathreact-simpletabs.js
257 lines (218 loc) · 6.86 KB
/
react-simpletabs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*!
*
* React Simpletabs - Just a simple tabs component built with React
* @version v0.6.1
* @link https://github.com/pedronauck/react-simpletabs
* @license MIT
* @author Pedro Nauck (https://github.com/pedronauck)
*
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object')
exports["ReactSimpleTabs"] = factory(require("react"));
else
root["ReactSimpleTabs"] = factory(root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/** @jsx React.DOM */'use strict';
var React = __webpack_require__(1);
var classNames = __webpack_require__(2);
if (true) {
__webpack_require__(3);
}
var Tabs = React.createClass({
displayName: 'Tabs',
propTypes: {
className: React.PropTypes.oneOfType([
React.PropTypes.array,
React.PropTypes.string,
React.PropTypes.object
]),
tabActive: React.PropTypes.number,
onMount: React.PropTypes.func,
onBeforeChange: React.PropTypes.func,
onAfterChange: React.PropTypes.func,
children: React.PropTypes.node.isRequired
},
getDefaultProps:function () {
return { tabActive: 1 };
},
getInitialState:function () {
return {
tabActive: this.props.tabActive
};
},
componentDidMount:function() {
var index = this.state.tabActive;
var $selectedPanel = this.refs['tab-panel'];
var $selectedMenu = this.refs[("tab-menu-" + index)];
if (this.props.onMount) {
this.props.onMount(index, $selectedPanel, $selectedMenu);
}
},
componentWillReceiveProps: function(newProps){
if(newProps.tabActive){ this.setState({tabActive: newProps.tabActive}) }
},
render:function () {
var className = classNames('tabs', this.props.className);
return (
React.createElement("div", {className: className},
this._getMenuItems(),
this._getSelectedPanel()
)
);
},
setActive:function(index, e) {
var onAfterChange = this.props.onAfterChange;
var onBeforeChange = this.props.onBeforeChange;
var $selectedPanel = this.refs['tab-panel'];
var $selectedTabMenu = this.refs[("tab-menu-" + index)];
if (onBeforeChange) {
var cancel = onBeforeChange(index, $selectedPanel, $selectedTabMenu);
if(cancel === false){ return }
}
this.setState({ tabActive: index }, function() {
if (onAfterChange) {
onAfterChange(index, $selectedPanel, $selectedTabMenu);
}
});
e.preventDefault();
},
_getMenuItems:function () {
if (!this.props.children) {
throw new Error('Tabs must contain at least one Tabs.Panel');
}
var $menuItems = React.Children
.map(this.props.children, function($panel, index) {
if (typeof $panel === 'function') {
$panel = $panel()
}
var ref = ("tab-menu-" + (index + 1));
var title = $panel.props.title;
var classes = classNames(
'tabs-menu-item',
this.state.tabActive === (index + 1) && 'is-active'
);
return (
React.createElement("li", {ref: ref, key: index, className: classes},
React.createElement("a", {href: "#", onClick: this.setActive.bind(this, index + 1)},
title
)
)
);
}.bind(this));
return (
React.createElement("nav", {className: "tabs-navigation"},
React.createElement("ul", {className: "tabs-menu"}, $menuItems)
)
);
},
_getSelectedPanel:function () {
var index = this.state.tabActive - 1;
var $panel
React.Children.forEach(this.props.children, function ($item, i) {
if (index === i) {
$panel = $item;
return;
}
})
return (
React.createElement("article", {ref: "tab-panel", className: "tab-panel"},
$panel
)
);
}
});
Tabs.Panel = React.createClass({
displayName: 'Panel',
propTypes: {
title: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.element
]).isRequired,
children: React.PropTypes.node.isRequired
},
render:function () {
return React.createElement("div", null, this.props.children);
}
});
module.exports = Tabs;
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
/** @jsx React.DOM */function classNames() {
var classes = '';
var arg;
for (var i = 0; i < arguments.length; i++) {
arg = arguments[i];
if (!arg) {
continue;
}
if ('string' === typeof arg || 'number' === typeof arg) {
classes += ' ' + arg;
} else if (Object.prototype.toString.call(arg) === '[object Array]') {
classes += ' ' + classNames.apply(null, arg);
} else if ('object' === typeof arg) {
for (var key in arg) {
if (!arg.hasOwnProperty(key) || !arg[key]) {
continue;
}
classes += ' ' + key;
}
}
}
return classes.substr(1);
}
// safely export classNames in case the script is included directly on a page
if (typeof module !== 'undefined' && module.exports) {
module.exports = classNames;
}
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
// removed by extract-text-webpack-plugin
/***/ }
/******/ ])
});
;