UNPKG

5.4 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _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
9var _react = require('react');
10
11var _react2 = _interopRequireDefault(_react);
12
13var _warning = require('warning');
14
15var _warning2 = _interopRequireDefault(_warning);
16
17var _propTypes = require('prop-types');
18
19var _propTypes2 = _interopRequireDefault(_propTypes);
20
21var _utils = require('./utils');
22
23function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
24
25function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
26
27function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
28
29function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
30
31function _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; }
32
33function _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) : _defaults(subClass, superClass); }
34
35var TabBarTabsNode = function (_React$Component) {
36 _inherits(TabBarTabsNode, _React$Component);
37
38 function TabBarTabsNode(props) {
39 _classCallCheck(this, TabBarTabsNode);
40
41 return _possibleConstructorReturn(this, _React$Component.call(this, props));
42 }
43
44 TabBarTabsNode.prototype.onTabClick = function onTabClick(key) {
45 this.props.onTabClick(key);
46 };
47
48 TabBarTabsNode.prototype.render = function render() {
49 var _this2 = this;
50
51 var _props = this.props,
52 children = _props.panels,
53 activeKey = _props.activeKey,
54 clsPrefix = _props.clsPrefix,
55 tabBarGutter = _props.tabBarGutter,
56 saveRef = _props.saveRef,
57 tabBarPosition = _props.tabBarPosition,
58 renderTabBarNode = _props.renderTabBarNode,
59 direction = _props.direction;
60
61 var rst = [];
62
63 _react2["default"].Children.forEach(children, function (child, index) {
64 if (!child) {
65 return;
66 }
67 var key = child.key;
68 var cls = activeKey === key ? clsPrefix + '-tab-active' : '';
69 cls += ' ' + clsPrefix + '-tab';
70 var events = {};
71 if (child.props.disabled) {
72 cls += ' ' + clsPrefix + '-tab-disabled';
73 } else {
74 events = {
75 onClick: _this2.onTabClick.bind(_this2, key)
76 };
77 }
78 var ref = {};
79 if (activeKey === key) {
80 ref.ref = saveRef('activeTab');
81 }
82
83 var gutter = tabBarGutter && index === children.length - 1 ? 0 : tabBarGutter;
84
85 var marginProperty = direction === 'rtl' ? 'marginLeft' : 'marginRight';
86 var style = _defineProperty({}, (0, _utils.isVertical)(tabBarPosition) ? 'marginBottom' : marginProperty, gutter);
87 (0, _warning2["default"])('tab' in child.props, 'There must be `tab` property on children of Tabs.');
88
89 var node = _react2["default"].createElement(
90 'div',
91 _extends({
92 role: 'tab',
93 'aria-disabled': child.props.disabled ? 'true' : 'false',
94 'aria-selected': activeKey === key ? 'true' : 'false'
95 }, events, {
96 className: cls,
97 key: key,
98 style: style
99 }, ref, {
100 nid: child.props.nid,
101 uitype: child.props.uitype,
102 nodekey: key
103 }),
104 child.props.tab
105 );
106
107 if (renderTabBarNode) {
108 node = renderTabBarNode(node);
109 }
110
111 rst.push(node);
112 });
113
114 return _react2["default"].createElement(
115 'div',
116 { ref: saveRef('navTabsContainer') },
117 rst
118 );
119 };
120
121 return TabBarTabsNode;
122}(_react2["default"].Component);
123
124exports["default"] = TabBarTabsNode;
125
126
127TabBarTabsNode.propTypes = {
128 activeKey: _propTypes2["default"].string,
129 panels: _propTypes2["default"].node,
130 clsPrefix: _propTypes2["default"].string,
131 tabBarGutter: _propTypes2["default"].number,
132 onTabClick: _propTypes2["default"].func,
133 saveRef: _propTypes2["default"].func,
134 renderTabBarNode: _propTypes2["default"].func,
135 tabBarPosition: _propTypes2["default"].string,
136 direction: _propTypes2["default"].string
137};
138
139TabBarTabsNode.defaultProps = {
140 panels: [],
141 clsPrefix: [],
142 tabBarGutter: null,
143 onTabClick: function onTabClick() {},
144 saveRef: function saveRef() {}
145};
146module.exports = exports['default'];
\No newline at end of file