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 _react = require('react');
|
10 |
|
11 | var _react2 = _interopRequireDefault(_react);
|
12 |
|
13 | var _propTypes = require('prop-types');
|
14 |
|
15 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
16 |
|
17 | var _style = require('./style.scss');
|
18 |
|
19 | var _style2 = _interopRequireDefault(_style);
|
20 |
|
21 | var _bind = require('classnames/bind');
|
22 |
|
23 | var _bind2 = _interopRequireDefault(_bind);
|
24 |
|
25 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
26 |
|
27 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
28 |
|
29 | function _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 |
|
31 | 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; }
|
32 |
|
33 | var Tab = function (_React$Component) {
|
34 | _inherits(Tab, _React$Component);
|
35 |
|
36 | function Tab(props) {
|
37 | _classCallCheck(this, Tab);
|
38 |
|
39 | var _this = _possibleConstructorReturn(this, (Tab.__proto__ || Object.getPrototypeOf(Tab)).call(this, props));
|
40 |
|
41 | _this.formatCount = function () {
|
42 |
|
43 | return _this.props.count.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
44 | };
|
45 |
|
46 | _this.handleClick = function (event) {
|
47 | if (_this.props.onClick && !_this.props.disabled) {
|
48 | _this.props.onClick(event, _this);
|
49 | }
|
50 | };
|
51 |
|
52 | return _this;
|
53 | }
|
54 |
|
55 | _createClass(Tab, [{
|
56 | key: 'render',
|
57 | value: function render() {
|
58 | var cx = _bind2.default.bind(_style2.default);
|
59 | var tabActiveClass = this.props.active ? 'active' : null;
|
60 | var tabDisabledClass = this.props.disabled ? 'disabled' : null;
|
61 | var tabClasses = cx(_style2.default.tab, this.props.optClass, tabActiveClass, tabDisabledClass);
|
62 |
|
63 | return _react2.default.createElement(
|
64 | 'div',
|
65 | { className: tabClasses, onClick: this.handleClick, 'aria-selected': this.props.active },
|
66 | this.props.titlePrefix,
|
67 | this.props.title,
|
68 | ' ',
|
69 | this.props.count ? _react2.default.createElement(
|
70 | 'span',
|
71 | { className: _style2.default.count },
|
72 | '(',
|
73 | this.formatCount(),
|
74 | ')'
|
75 | ) : null,
|
76 | this.props.titleSuffix
|
77 | );
|
78 | }
|
79 | }]);
|
80 |
|
81 | return Tab;
|
82 | }(_react2.default.Component);
|
83 |
|
84 | Tab.defaultProps = {};
|
85 | Tab.propTypes = {
|
86 | |
87 |
|
88 |
|
89 | active: _propTypes2.default.bool,
|
90 | |
91 |
|
92 |
|
93 | disabled: _propTypes2.default.bool,
|
94 | |
95 |
|
96 |
|
97 | count: _propTypes2.default.number,
|
98 | |
99 |
|
100 |
|
101 | optClass: _propTypes2.default.string,
|
102 | |
103 |
|
104 |
|
105 | optTabContentClass: _propTypes2.default.string,
|
106 | |
107 |
|
108 |
|
109 | title: _propTypes2.default.string.isRequired,
|
110 | |
111 |
|
112 |
|
113 | titlePrefix: _propTypes2.default.node,
|
114 | |
115 |
|
116 |
|
117 | titleSuffix: _propTypes2.default.node
|
118 | };
|
119 | exports.default = Tab; |
\ | No newline at end of file |