UNPKG

6.13 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 _propTypes = require('prop-types');
14
15var _propTypes2 = _interopRequireDefault(_propTypes);
16
17var _classnames2 = require('classnames');
18
19var _classnames3 = _interopRequireDefault(_classnames2);
20
21function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
22
23function _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; }
24
25function _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; }
26
27function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
28
29function _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; }
30
31function _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); } /**
32 * This source code is quoted from rc-tabs.
33 * homepage: https://github.com/react-component/tabs
34 */
35
36
37var TabBarSwipeableTabs = function (_React$Component) {
38 _inherits(TabBarSwipeableTabs, _React$Component);
39
40 function TabBarSwipeableTabs() {
41 _classCallCheck(this, TabBarSwipeableTabs);
42
43 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
44 }
45
46 TabBarSwipeableTabs.prototype.render = function render() {
47 var _this2 = this;
48
49 var props = this.props;
50 var children = props.panels;
51 var activeKey = props.activeKey;
52 var rst = [];
53 var clsPrefix = props.clsPrefix;
54
55 var _flexWidth = 1 / props.pageSize * 100 + '%';
56 var tabStyle = {
57 WebkitFlexBasis: _flexWidth,
58 flexBasis: _flexWidth
59 };
60
61 _react2["default"].Children.forEach(children, function (child) {
62 var _classnames;
63
64 if (!child) {
65 return;
66 }
67 var key = child.key;
68 var cls = (0, _classnames3["default"])(clsPrefix + '-tab', (_classnames = {}, _defineProperty(_classnames, clsPrefix + '-tab-active', activeKey === key), _defineProperty(_classnames, clsPrefix + '-tab-disabled', child.props.disabled), _classnames));
69 var events = {};
70 if (!child.props.disabled) {
71 events = {
72 onClick: _this2.props.onTabClick.bind(_this2, key)
73 };
74 }
75 var refProps = {};
76 if (activeKey === key) {
77 refProps.ref = _this2.props.saveRef('activeTab');
78 }
79 rst.push(_react2["default"].createElement(
80 'div',
81 _extends({
82 role: 'tab',
83 style: tabStyle,
84 'aria-disabled': child.props.disabled ? 'true' : 'false',
85 'aria-selected': activeKey === key ? 'true' : 'false'
86 }, events, {
87 className: cls,
88 key: key
89 }, refProps),
90 child.props.tab
91 ));
92 });
93
94 return rst;
95 };
96
97 return TabBarSwipeableTabs;
98}(_react2["default"].Component);
99
100exports["default"] = TabBarSwipeableTabs;
101
102
103TabBarSwipeableTabs.propTypes = {
104 pageSize: _propTypes2["default"].number,
105 onTabClick: _propTypes2["default"].func,
106 saveRef: _propTypes2["default"].func,
107 destroyInactiveTabPane: _propTypes2["default"].bool,
108 clsPrefix: _propTypes2["default"].string,
109 activeKey: _propTypes2["default"].string,
110 panels: _propTypes2["default"].node
111};
112
113TabBarSwipeableTabs.defaultProps = {
114 pageSize: 5,
115 onTabClick: function onTabClick() {},
116 saveRef: function saveRef() {}
117};
118module.exports = exports['default'];
\No newline at end of file