1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.TabButton = exports.Tab = exports.Tabs = void 0;
|
7 |
|
8 | var _react = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _TabButton = _interopRequireDefault(require("./TabButton"));
|
11 |
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 |
|
14 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
15 |
|
16 | function _extends() { _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; }; return _extends.apply(this, arguments); }
|
17 |
|
18 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
19 |
|
20 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
21 |
|
22 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
23 |
|
24 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
25 |
|
26 | 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); } }
|
27 |
|
28 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
29 |
|
30 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
31 |
|
32 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
33 |
|
34 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
35 |
|
36 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
37 |
|
38 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
39 |
|
40 | var TabContext = _react.default.createContext({
|
41 | activeTab: null,
|
42 | setActiveTab: function setActiveTab() {}
|
43 | });
|
44 |
|
45 | var Tabs =
|
46 |
|
47 | function (_Component) {
|
48 | _inherits(Tabs, _Component);
|
49 |
|
50 | function Tabs(props) {
|
51 | var _this;
|
52 |
|
53 | _classCallCheck(this, Tabs);
|
54 |
|
55 | _this = _possibleConstructorReturn(this, _getPrototypeOf(Tabs).call(this, props));
|
56 |
|
57 | _this.setActiveTab = function (tab) {
|
58 | _this.setState({
|
59 | activeTab: tab
|
60 | });
|
61 | };
|
62 |
|
63 | _this.state = {
|
64 | activeTab: null,
|
65 | setActiveTab: _this.setActiveTab
|
66 | };
|
67 | return _this;
|
68 | }
|
69 |
|
70 | _createClass(Tabs, [{
|
71 | key: "componentDidMount",
|
72 | value: function componentDidMount() {
|
73 | var initialTab = this.props.initialTab;
|
74 |
|
75 | if (initialTab != null) {
|
76 | this.setActiveTab(initialTab);
|
77 | }
|
78 | }
|
79 | }, {
|
80 | key: "render",
|
81 | value: function render() {
|
82 | var children = this.props.children;
|
83 | return _react.default.createElement(TabContext.Provider, {
|
84 | value: this.state
|
85 | }, children);
|
86 | }
|
87 | }]);
|
88 |
|
89 | return Tabs;
|
90 | }(_react.Component);
|
91 |
|
92 | exports.Tabs = Tabs;
|
93 |
|
94 | var Tab = function Tab(_ref) {
|
95 | var children = _ref.children,
|
96 | tabKey = _ref.tabKey;
|
97 | return _react.default.createElement(TabContext.Consumer, null, function (_ref2) {
|
98 | var activeTab = _ref2.activeTab;
|
99 | return tabKey === activeTab && children;
|
100 | });
|
101 | };
|
102 |
|
103 | exports.Tab = Tab;
|
104 |
|
105 | var TabButton = function TabButton(_ref3) {
|
106 | var children = _ref3.children,
|
107 | tabKey = _ref3.tabKey,
|
108 | props = _objectWithoutProperties(_ref3, ["children", "tabKey"]);
|
109 |
|
110 | return _react.default.createElement(TabContext.Consumer, null, function (_ref4) {
|
111 | var activeTab = _ref4.activeTab,
|
112 | setActiveTab = _ref4.setActiveTab;
|
113 | return _react.default.createElement(_TabButton.default, _extends({
|
114 | onClick: function onClick() {
|
115 | return setActiveTab(tabKey);
|
116 | },
|
117 | active: tabKey === activeTab
|
118 | }, props), children);
|
119 | });
|
120 | };
|
121 |
|
122 | exports.TabButton = TabButton; |
\ | No newline at end of file |