1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _overrides = require("../helpers/overrides.js");
|
11 |
|
12 | var _styledComponents = require("./styled-components.js");
|
13 |
|
14 | var _focusVisible = require("../utils/focusVisible.js");
|
15 |
|
16 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
17 |
|
18 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
19 |
|
20 | function _typeof(obj) { "@babel/helpers - typeof"; 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); }
|
21 |
|
22 | 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); }
|
23 |
|
24 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
25 |
|
26 | function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
27 |
|
28 | function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
29 |
|
30 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
31 |
|
32 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
33 |
|
34 | 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); } }
|
35 |
|
36 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
37 |
|
38 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
39 |
|
40 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
41 |
|
42 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
43 |
|
44 | 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); }
|
45 |
|
46 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
47 |
|
48 | function _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; }
|
49 |
|
50 | var TabComponent =
|
51 |
|
52 | function (_React$Component) {
|
53 | _inherits(TabComponent, _React$Component);
|
54 |
|
55 | function TabComponent() {
|
56 | var _getPrototypeOf2;
|
57 |
|
58 | var _this;
|
59 |
|
60 | _classCallCheck(this, TabComponent);
|
61 |
|
62 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
63 | args[_key] = arguments[_key];
|
64 | }
|
65 |
|
66 | _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(TabComponent)).call.apply(_getPrototypeOf2, [this].concat(args)));
|
67 |
|
68 | _defineProperty(_assertThisInitialized(_this), "state", {
|
69 | isFocusVisible: false
|
70 | });
|
71 |
|
72 | _defineProperty(_assertThisInitialized(_this), "handleFocus", function (event) {
|
73 | if ((0, _focusVisible.isFocusVisible)(event)) {
|
74 | _this.setState({
|
75 | isFocusVisible: true
|
76 | });
|
77 | }
|
78 | });
|
79 |
|
80 | _defineProperty(_assertThisInitialized(_this), "handleBlur", function (event) {
|
81 | if (_this.state.isFocusVisible !== false) {
|
82 | _this.setState({
|
83 | isFocusVisible: false
|
84 | });
|
85 | }
|
86 | });
|
87 |
|
88 | _defineProperty(_assertThisInitialized(_this), "onClick", function (e) {
|
89 | var _this$props = _this.props,
|
90 | disabled = _this$props.disabled,
|
91 | onSelect = _this$props.onSelect,
|
92 | onClick = _this$props.onClick;
|
93 |
|
94 | if (disabled) {
|
95 | return;
|
96 | }
|
97 |
|
98 | typeof onClick === 'function' && onClick(e);
|
99 | typeof onSelect === 'function' && onSelect();
|
100 | return;
|
101 | });
|
102 |
|
103 | _defineProperty(_assertThisInitialized(_this), "onKeyDown", function (e) {
|
104 | var _this$props2 = _this.props,
|
105 | disabled = _this$props2.disabled,
|
106 | onSelect = _this$props2.onSelect,
|
107 | onKeyDown = _this$props2.onKeyDown;
|
108 |
|
109 | if (disabled) {
|
110 | return;
|
111 | }
|
112 |
|
113 | typeof onKeyDown === 'function' && onKeyDown(e);
|
114 |
|
115 | if (e.key === 'Enter' || e.which === 32) {
|
116 | typeof onSelect === 'function' && onSelect();
|
117 | e.which === 32 && e.preventDefault();
|
118 | }
|
119 |
|
120 | return;
|
121 | });
|
122 |
|
123 | return _this;
|
124 | }
|
125 |
|
126 | _createClass(TabComponent, [{
|
127 | key: "getSharedProps",
|
128 | value: function getSharedProps() {
|
129 | var _this$props3 = this.props,
|
130 | disabled = _this$props3.disabled,
|
131 | active = _this$props3.active,
|
132 | $orientation = _this$props3.$orientation;
|
133 | return {
|
134 | $disabled: disabled,
|
135 | $active: active,
|
136 | $orientation: $orientation
|
137 | };
|
138 | }
|
139 | }, {
|
140 | key: "render",
|
141 | value: function render() {
|
142 | var _this$props4 = this.props,
|
143 | active = _this$props4.active,
|
144 | disabled = _this$props4.disabled,
|
145 | id = _this$props4.id,
|
146 | _this$props4$override = _this$props4.overrides,
|
147 | overrides = _this$props4$override === void 0 ? {} : _this$props4$override,
|
148 | children = _this$props4.children;
|
149 | var sharedProps = this.getSharedProps();
|
150 | var TabOverride = overrides.Tab;
|
151 |
|
152 | var _getOverrides = (0, _overrides.getOverrides)(TabOverride, _styledComponents.Tab),
|
153 | _getOverrides2 = _slicedToArray(_getOverrides, 2),
|
154 | Tab = _getOverrides2[0],
|
155 | tabProps = _getOverrides2[1];
|
156 |
|
157 | return React.createElement(Tab, _extends({
|
158 | $isFocusVisible: this.state.isFocusVisible,
|
159 | tabIndex: disabled ? -1 : 0,
|
160 | role: "tab",
|
161 | id: id,
|
162 | "aria-selected": active,
|
163 | "aria-disabled": disabled || null
|
164 | }, sharedProps, tabProps, {
|
165 | onFocus: (0, _focusVisible.forkFocus)(tabProps, this.handleFocus),
|
166 | onBlur: (0, _focusVisible.forkBlur)(tabProps, this.handleBlur),
|
167 | onClick: this.onClick,
|
168 | onKeyDown: this.onKeyDown
|
169 | }), children);
|
170 | }
|
171 | }]);
|
172 |
|
173 | return TabComponent;
|
174 | }(React.Component);
|
175 |
|
176 | _defineProperty(TabComponent, "defaultProps", {
|
177 | disabled: false,
|
178 | expanded: false,
|
179 | onSelect: function onSelect() {},
|
180 | onClick: function onClick() {},
|
181 | onKeyDown: function onKeyDown() {},
|
182 | title: ''
|
183 | });
|
184 |
|
185 | var _default = TabComponent;
|
186 | exports.default = _default; |
\ | No newline at end of file |