@instructure/ui-tabs 11.6.0 → 11.6.1-snapshot-129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/CHANGELOG.md +48 -308
  2. package/es/Tabs/{Panel → v1/Panel}/index.js +2 -2
  3. package/es/Tabs/{Tab → v1/Tab}/index.js +2 -2
  4. package/es/Tabs/{index.js → v1/index.js} +2 -2
  5. package/es/Tabs/v2/Panel/index.js +126 -0
  6. package/es/Tabs/v2/Panel/props.js +26 -0
  7. package/es/Tabs/v2/Panel/styles.js +81 -0
  8. package/es/Tabs/v2/Tab/index.js +118 -0
  9. package/es/Tabs/v2/Tab/props.js +26 -0
  10. package/es/Tabs/v2/Tab/styles.js +145 -0
  11. package/es/Tabs/v2/index.js +396 -0
  12. package/es/Tabs/v2/props.js +26 -0
  13. package/es/Tabs/v2/styles.js +145 -0
  14. package/es/{index.js → exports/a.js} +3 -3
  15. package/es/exports/b.js +26 -0
  16. package/lib/Tabs/v1/Panel/index.js +132 -0
  17. package/lib/Tabs/v1/Tab/index.js +125 -0
  18. package/lib/Tabs/v1/index.js +410 -0
  19. package/lib/Tabs/{Panel → v2/Panel}/index.js +3 -4
  20. package/lib/Tabs/v2/Panel/props.js +31 -0
  21. package/lib/Tabs/v2/Panel/styles.js +87 -0
  22. package/lib/Tabs/{Tab → v2/Tab}/index.js +3 -4
  23. package/lib/Tabs/v2/Tab/props.js +31 -0
  24. package/lib/Tabs/v2/Tab/styles.js +151 -0
  25. package/lib/Tabs/{index.js → v2/index.js} +5 -6
  26. package/lib/Tabs/v2/props.js +31 -0
  27. package/lib/Tabs/v2/styles.js +151 -0
  28. package/lib/{index.js → exports/a.js} +4 -4
  29. package/lib/exports/b.js +26 -0
  30. package/package.json +46 -24
  31. package/src/Tabs/{Panel → v1/Panel}/index.tsx +2 -2
  32. package/src/Tabs/{Tab → v1/Tab}/index.tsx +3 -3
  33. package/src/Tabs/{Tab → v1/Tab}/props.ts +1 -1
  34. package/src/Tabs/{index.tsx → v1/index.tsx} +3 -3
  35. package/src/Tabs/{props.ts → v1/props.ts} +1 -1
  36. package/src/Tabs/v2/Panel/index.tsx +138 -0
  37. package/src/Tabs/v2/Panel/props.ts +100 -0
  38. package/src/Tabs/v2/Panel/styles.ts +92 -0
  39. package/src/Tabs/v2/README.md +559 -0
  40. package/src/Tabs/v2/Tab/index.tsx +123 -0
  41. package/src/Tabs/v2/Tab/props.ts +80 -0
  42. package/src/Tabs/v2/Tab/styles.ts +161 -0
  43. package/src/Tabs/v2/index.tsx +547 -0
  44. package/src/Tabs/v2/props.ts +126 -0
  45. package/src/Tabs/v2/styles.ts +156 -0
  46. package/src/{index.ts → exports/a.ts} +6 -6
  47. package/src/exports/b.ts +31 -0
  48. package/tsconfig.build.tsbuildinfo +1 -1
  49. package/types/Tabs/v1/Panel/index.d.ts.map +1 -0
  50. package/types/Tabs/v1/Panel/props.d.ts.map +1 -0
  51. package/types/Tabs/v1/Panel/styles.d.ts.map +1 -0
  52. package/types/Tabs/v1/Panel/theme.d.ts.map +1 -0
  53. package/types/Tabs/{Tab → v1/Tab}/index.d.ts +1 -1
  54. package/types/Tabs/v1/Tab/index.d.ts.map +1 -0
  55. package/types/Tabs/{Tab → v1/Tab}/props.d.ts +1 -1
  56. package/types/Tabs/v1/Tab/props.d.ts.map +1 -0
  57. package/types/Tabs/v1/Tab/styles.d.ts.map +1 -0
  58. package/types/Tabs/v1/Tab/theme.d.ts.map +1 -0
  59. package/types/Tabs/{index.d.ts → v1/index.d.ts} +1 -1
  60. package/types/Tabs/v1/index.d.ts.map +1 -0
  61. package/types/Tabs/{props.d.ts → v1/props.d.ts} +1 -1
  62. package/types/Tabs/v1/props.d.ts.map +1 -0
  63. package/types/Tabs/v1/styles.d.ts.map +1 -0
  64. package/types/Tabs/v1/theme.d.ts.map +1 -0
  65. package/types/Tabs/v2/Panel/index.d.ts +46 -0
  66. package/types/Tabs/v2/Panel/index.d.ts.map +1 -0
  67. package/types/Tabs/v2/Panel/props.d.ts +46 -0
  68. package/types/Tabs/v2/Panel/props.d.ts.map +1 -0
  69. package/types/Tabs/v2/Panel/styles.d.ts +19 -0
  70. package/types/Tabs/v2/Panel/styles.d.ts.map +1 -0
  71. package/types/Tabs/v2/Tab/index.d.ts +43 -0
  72. package/types/Tabs/v2/Tab/index.d.ts.map +1 -0
  73. package/types/Tabs/v2/Tab/props.d.ts +33 -0
  74. package/types/Tabs/v2/Tab/props.d.ts.map +1 -0
  75. package/types/Tabs/v2/Tab/styles.d.ts +20 -0
  76. package/types/Tabs/v2/Tab/styles.d.ts.map +1 -0
  77. package/types/Tabs/v2/index.d.ts +80 -0
  78. package/types/Tabs/v2/index.d.ts.map +1 -0
  79. package/types/Tabs/v2/props.d.ts +68 -0
  80. package/types/Tabs/v2/props.d.ts.map +1 -0
  81. package/types/Tabs/v2/styles.d.ts +19 -0
  82. package/types/Tabs/v2/styles.d.ts.map +1 -0
  83. package/types/exports/a.d.ts +7 -0
  84. package/types/exports/a.d.ts.map +1 -0
  85. package/types/exports/b.d.ts +7 -0
  86. package/types/exports/b.d.ts.map +1 -0
  87. package/types/Tabs/Panel/index.d.ts.map +0 -1
  88. package/types/Tabs/Panel/props.d.ts.map +0 -1
  89. package/types/Tabs/Panel/styles.d.ts.map +0 -1
  90. package/types/Tabs/Panel/theme.d.ts.map +0 -1
  91. package/types/Tabs/Tab/index.d.ts.map +0 -1
  92. package/types/Tabs/Tab/props.d.ts.map +0 -1
  93. package/types/Tabs/Tab/styles.d.ts.map +0 -1
  94. package/types/Tabs/Tab/theme.d.ts.map +0 -1
  95. package/types/Tabs/index.d.ts.map +0 -1
  96. package/types/Tabs/props.d.ts.map +0 -1
  97. package/types/Tabs/styles.d.ts.map +0 -1
  98. package/types/Tabs/theme.d.ts.map +0 -1
  99. package/types/index.d.ts +0 -7
  100. package/types/index.d.ts.map +0 -1
  101. /package/es/Tabs/{Panel → v1/Panel}/props.js +0 -0
  102. /package/es/Tabs/{Panel → v1/Panel}/styles.js +0 -0
  103. /package/es/Tabs/{Panel → v1/Panel}/theme.js +0 -0
  104. /package/es/Tabs/{Tab → v1/Tab}/props.js +0 -0
  105. /package/es/Tabs/{Tab → v1/Tab}/styles.js +0 -0
  106. /package/es/Tabs/{Tab → v1/Tab}/theme.js +0 -0
  107. /package/es/Tabs/{props.js → v1/props.js} +0 -0
  108. /package/es/Tabs/{styles.js → v1/styles.js} +0 -0
  109. /package/es/Tabs/{theme.js → v1/theme.js} +0 -0
  110. /package/lib/Tabs/{Panel → v1/Panel}/props.js +0 -0
  111. /package/lib/Tabs/{Panel → v1/Panel}/styles.js +0 -0
  112. /package/lib/Tabs/{Panel → v1/Panel}/theme.js +0 -0
  113. /package/lib/Tabs/{Tab → v1/Tab}/props.js +0 -0
  114. /package/lib/Tabs/{Tab → v1/Tab}/styles.js +0 -0
  115. /package/lib/Tabs/{Tab → v1/Tab}/theme.js +0 -0
  116. /package/lib/Tabs/{props.js → v1/props.js} +0 -0
  117. /package/lib/Tabs/{styles.js → v1/styles.js} +0 -0
  118. /package/lib/Tabs/{theme.js → v1/theme.js} +0 -0
  119. /package/src/Tabs/{Panel → v1/Panel}/props.ts +0 -0
  120. /package/src/Tabs/{Panel → v1/Panel}/styles.ts +0 -0
  121. /package/src/Tabs/{Panel → v1/Panel}/theme.ts +0 -0
  122. /package/src/Tabs/{README.md → v1/README.md} +0 -0
  123. /package/src/Tabs/{Tab → v1/Tab}/styles.ts +0 -0
  124. /package/src/Tabs/{Tab → v1/Tab}/theme.ts +0 -0
  125. /package/src/Tabs/{styles.ts → v1/styles.ts} +0 -0
  126. /package/src/Tabs/{theme.ts → v1/theme.ts} +0 -0
  127. /package/types/Tabs/{Panel → v1/Panel}/index.d.ts +0 -0
  128. /package/types/Tabs/{Panel → v1/Panel}/props.d.ts +0 -0
  129. /package/types/Tabs/{Panel → v1/Panel}/styles.d.ts +0 -0
  130. /package/types/Tabs/{Panel → v1/Panel}/theme.d.ts +0 -0
  131. /package/types/Tabs/{Tab → v1/Tab}/styles.d.ts +0 -0
  132. /package/types/Tabs/{Tab → v1/Tab}/theme.d.ts +0 -0
  133. /package/types/Tabs/{styles.d.ts → v1/styles.d.ts} +0 -0
  134. /package/types/Tabs/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,396 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["children", "elementRef", "maxWidth", "variant", "margin", "screenReaderLabel", "onRequestTabChange", "tabOverflow", "styles"];
3
+ var _dec, _class, _Tabs;
4
+ /*
5
+ * The MIT License (MIT)
6
+ *
7
+ * Copyright (c) 2015 - present Instructure, Inc.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ import { cloneElement, Children, Component } from 'react';
29
+ import keycode from 'keycode';
30
+ import { View } from '@instructure/ui-view/latest';
31
+ import { matchComponentTypes, safeCloneElement, passthroughProps } from '@instructure/ui-react-utils';
32
+ import { logError as error } from '@instructure/console';
33
+ import { uid } from '@instructure/uid';
34
+ import { Focusable } from '@instructure/ui-focusable';
35
+ import { getBoundingClientRect } from '@instructure/ui-dom-utils';
36
+ import { debounce } from '@instructure/debounce';
37
+ import { px } from '@instructure/ui-utils';
38
+ import { withStyle } from '@instructure/emotion';
39
+ import generateStyle from "./styles.js";
40
+ import { Tab } from "./Tab/index.js";
41
+ import { Panel } from "./Panel/index.js";
42
+ import { allowedProps } from "./props.js";
43
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
44
+ /**
45
+ ---
46
+ category: components
47
+ ---
48
+ **/
49
+ let Tabs = (_dec = withStyle(generateStyle), _dec(_class = (_Tabs = class Tabs extends Component {
50
+ constructor(props) {
51
+ super(props);
52
+ this._tabList = null;
53
+ this._focusable = null;
54
+ this._tabListPosition = void 0;
55
+ this._debounced = void 0;
56
+ this._resizeListener = void 0;
57
+ this.ref = null;
58
+ this.handleRef = el => {
59
+ const elementRef = this.props.elementRef;
60
+ this.ref = el;
61
+ if (typeof elementRef === 'function') {
62
+ elementRef(el);
63
+ }
64
+ };
65
+ this.handleTabClick = (event, {
66
+ index
67
+ }) => {
68
+ const nextTab = this.getNextTab(index, 0);
69
+ this.fireOnChange(event, nextTab);
70
+ };
71
+ this.handleTabKeyDown = (event, {
72
+ index
73
+ }) => {
74
+ let nextTab;
75
+ if (event.keyCode === keycode.codes.up || event.keyCode === keycode.codes.left) {
76
+ // Select next tab to the left
77
+ nextTab = this.getNextTab(index, -1);
78
+ } else if (event.keyCode === keycode.codes.down || event.keyCode === keycode.codes.right) {
79
+ // Select next tab to the right
80
+ nextTab = this.getNextTab(index, 1);
81
+ }
82
+ if (nextTab) {
83
+ event.preventDefault();
84
+ this.fireOnChange(event, nextTab);
85
+ }
86
+ };
87
+ this.handleResize = () => {
88
+ this.setState({
89
+ withTabListOverflow: this._tabList.scrollWidth > this._tabList.offsetWidth
90
+ });
91
+ this._tabListPosition = getBoundingClientRect(this._tabList);
92
+ };
93
+ this.handleFocusableRef = el => {
94
+ this._focusable = el;
95
+ };
96
+ this.handleTabListRef = el => {
97
+ this._tabList = el;
98
+ };
99
+ this.handleScroll = event => {
100
+ if (this.props.tabOverflow !== 'scroll' || !this.state.withTabListOverflow) {
101
+ event.preventDefault();
102
+ return;
103
+ }
104
+ const tabList = event.currentTarget;
105
+ const scrollLeftMax = Math.round(tabList.scrollWidth - getBoundingClientRect(tabList).width);
106
+ const scrollLeft = Math.floor(Math.abs(tabList.scrollLeft));
107
+ this.setState({
108
+ showStartOverLay: scrollLeft > 0,
109
+ showEndOverLay: scrollLeft < scrollLeftMax
110
+ });
111
+ };
112
+ this.state = {
113
+ withTabListOverflow: false,
114
+ showStartOverLay: false,
115
+ showEndOverLay: false
116
+ };
117
+ }
118
+ componentDidMount() {
119
+ var _this$props$makeStyle, _this$props;
120
+ if (this.props.tabOverflow === 'scroll' && this._tabList) {
121
+ this.startScrollOverflow();
122
+ }
123
+ if (this.props.shouldFocusOnRender) {
124
+ this.focus();
125
+ }
126
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
127
+ }
128
+ componentDidUpdate(prevProps, prevState) {
129
+ var _this$props$makeStyle2, _this$props2;
130
+ if (this.props.shouldFocusOnRender && !prevProps.shouldFocusOnRender) {
131
+ this.focus();
132
+ }
133
+
134
+ // start event listeners for scroll overflow
135
+ if (prevProps.tabOverflow === 'stack' && this.props.tabOverflow === 'scroll') {
136
+ this.startScrollOverflow();
137
+ }
138
+
139
+ // cancel event listeners for scroll overflow
140
+ if (prevProps.tabOverflow === 'scroll' && this.props.tabOverflow === 'stack') {
141
+ this.cancelScrollOverflow();
142
+ }
143
+
144
+ // we need to recalculate the scroll overflow if the style changes
145
+ if (this.props.tabOverflow === 'scroll' && prevProps.styles !== this.props.styles) {
146
+ this.handleResize();
147
+ }
148
+
149
+ // when tabList is set as overflown,
150
+ // make sure active tab is always visible
151
+ if (this.props.tabOverflow === 'scroll' && this._tabList && !prevState.withTabListOverflow && this.state.withTabListOverflow) {
152
+ const activeTabEl = this._tabList.querySelector('[aria-selected="true"]');
153
+ this.showActiveTabIfOverlayed(activeTabEl);
154
+ }
155
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
156
+ }
157
+ componentWillUnmount() {
158
+ this.cancelScrollOverflow();
159
+ }
160
+ startScrollOverflow() {
161
+ this.handleResize();
162
+ this._debounced = debounce(this.handleResize, 300, {
163
+ leading: true,
164
+ trailing: true
165
+ });
166
+ this._tabListPosition = getBoundingClientRect(this._tabList);
167
+ this._resizeListener = new ResizeObserver(entries => {
168
+ for (const entry of entries) {
169
+ const newWidth = entry.contentRect.width;
170
+ if (this._tabListPosition.width !== newWidth) {
171
+ var _this$_debounced;
172
+ (_this$_debounced = this._debounced) === null || _this$_debounced === void 0 ? void 0 : _this$_debounced.call(this);
173
+ }
174
+ }
175
+ });
176
+ this._resizeListener.observe(this._tabList);
177
+ }
178
+ cancelScrollOverflow() {
179
+ if (this._resizeListener) {
180
+ this._resizeListener.disconnect();
181
+ }
182
+ if (this._debounced) {
183
+ this._debounced.cancel();
184
+ }
185
+ }
186
+ getOverlayWidth() {
187
+ const _this$props3 = this.props,
188
+ variant = _this$props3.variant,
189
+ tabOverflow = _this$props3.tabOverflow,
190
+ styles = _this$props3.styles;
191
+ if (styles && tabOverflow === 'scroll') {
192
+ if (variant === 'default') {
193
+ return px(styles === null || styles === void 0 ? void 0 : styles.scrollOverlayWidthDefault);
194
+ } else {
195
+ return px(styles === null || styles === void 0 ? void 0 : styles.scrollOverlayWidthSecondary);
196
+ }
197
+ }
198
+ return 0;
199
+ }
200
+ showActiveTabIfOverlayed(activeTabEl) {
201
+ if (this._tabList && this._tabListPosition && typeof this._tabList.scrollTo === 'function' // test for scrollTo support
202
+ ) {
203
+ const tabPosition = getBoundingClientRect(activeTabEl);
204
+ const tabListPosition = this._tabListPosition;
205
+ const tabListBoundStart = tabListPosition.left + this.getOverlayWidth();
206
+ const tabListBoundEnd = tabListPosition.right + this.getOverlayWidth();
207
+ const tabPositionStart = tabPosition.left;
208
+ const tabPositionEnd = tabPosition.right;
209
+ if (tabListBoundEnd > tabPositionEnd) {
210
+ const offset = Math.round(tabListBoundEnd - tabPositionEnd);
211
+ this._tabList.scrollTo({
212
+ top: 0,
213
+ left: this._tabList.scrollLeft + offset,
214
+ behavior: 'smooth'
215
+ });
216
+ } else if (tabListBoundStart > tabPositionStart) {
217
+ const offset = Math.round(tabListBoundStart - tabPositionStart);
218
+ this._tabList.scrollTo({
219
+ top: 0,
220
+ left: this._tabList.scrollLeft - offset,
221
+ behavior: 'smooth'
222
+ });
223
+ }
224
+ }
225
+ }
226
+ getNextTab(startIndex, step) {
227
+ const tabs = Children.toArray(this.props.children).map(child => matchComponentTypes(child, [Panel]) && child);
228
+ const count = tabs.length;
229
+ const change = step < 0 ? step + count : step;
230
+ error(startIndex >= 0 && startIndex < count, `[Tabs] Invalid tab index: '${startIndex}'.`);
231
+ let nextIndex = startIndex;
232
+ let nextTab;
233
+ do {
234
+ nextIndex = (nextIndex + change) % count;
235
+ nextTab = tabs[nextIndex];
236
+ } while (nextTab && nextTab.props && nextTab.props.isDisabled);
237
+ error(nextIndex >= 0 && nextIndex < count, `[Tabs] Invalid tab index: '${nextIndex}'.`);
238
+ return {
239
+ index: nextIndex,
240
+ id: nextTab.props.id
241
+ };
242
+ }
243
+ fireOnChange(event, {
244
+ index,
245
+ id
246
+ }) {
247
+ if (typeof this.props.onRequestTabChange === 'function') {
248
+ this.props.onRequestTabChange(event, {
249
+ index,
250
+ id
251
+ });
252
+ }
253
+
254
+ // this is needed because keypress cancels scrolling. So we have to trigger the scrolling
255
+ // one "tick" later than the keypress
256
+ setTimeout(() => {
257
+ if (this.state.withTabListOverflow) {
258
+ const tab = id ? this._tabList.querySelector(`#tab-${CSS.escape(id)}`) : null;
259
+ this.showActiveTabIfOverlayed(tab);
260
+ }
261
+ }, 0);
262
+ }
263
+ createTab(index, generatedId, selected, panel) {
264
+ const id = panel.props.id || generatedId;
265
+ return _jsx(Tab, {
266
+ variant: this.props.variant,
267
+ id: `tab-${id}`,
268
+ controls: panel.props.id || `panel-${id}`,
269
+ index: index,
270
+ isSelected: selected,
271
+ isDisabled: panel.props.isDisabled,
272
+ onClick: this.handleTabClick,
273
+ onKeyDown: this.handleTabKeyDown,
274
+ isOverflowScroll: this.props.tabOverflow === 'scroll',
275
+ children: panel.props.renderTitle
276
+ }, `tab-${index}`);
277
+ }
278
+ clonePanel(index, generatedId, selected, panel, activePanel) {
279
+ const id = panel.props.id || generatedId;
280
+
281
+ // fixHeight can be 0, so simply `fixheight` could return falsy value
282
+ const hasFixedHeight = typeof this.props.fixHeight !== 'undefined';
283
+ const commonProps = {
284
+ id: panel.props.id || `panel-${id}`,
285
+ labelledBy: `tab-${id}`,
286
+ isSelected: selected,
287
+ variant: this.props.variant,
288
+ maxHeight: !hasFixedHeight ? this.props.maxHeight : void 0,
289
+ minHeight: !hasFixedHeight ? this.props.minHeight : '100%'
290
+ };
291
+ let activePanelClone = null;
292
+ if (activePanel !== void 0) {
293
+ // cloning active panel with a proper custom key as a workaround because
294
+ // safeCloneElement overwrites it with the key from the original element
295
+ activePanelClone = /*#__PURE__*/cloneElement(activePanel, {
296
+ key: `panel-${index}`
297
+ });
298
+ return safeCloneElement(activePanelClone, {
299
+ padding: activePanelClone.props.padding || this.props.padding,
300
+ textAlign: activePanelClone.props.textAlign || this.props.textAlign,
301
+ ...commonProps
302
+ });
303
+ } else {
304
+ return safeCloneElement(panel, {
305
+ key: `panel-${index}`,
306
+ padding: panel.props.padding || this.props.padding,
307
+ textAlign: panel.props.textAlign || this.props.textAlign,
308
+ ...commonProps
309
+ });
310
+ }
311
+ }
312
+ focus() {
313
+ this._focusable && typeof this._focusable.focus === 'function' && this._focusable.focus();
314
+ }
315
+ render() {
316
+ const panels = [];
317
+ const tabs = [];
318
+ const _this$props4 = this.props,
319
+ children = _this$props4.children,
320
+ elementRef = _this$props4.elementRef,
321
+ maxWidth = _this$props4.maxWidth,
322
+ variant = _this$props4.variant,
323
+ margin = _this$props4.margin,
324
+ screenReaderLabel = _this$props4.screenReaderLabel,
325
+ onRequestTabChange = _this$props4.onRequestTabChange,
326
+ tabOverflow = _this$props4.tabOverflow,
327
+ styles = _this$props4.styles,
328
+ props = _objectWithoutProperties(_this$props4, _excluded);
329
+ const activePanels = Children.toArray(children).filter(child => matchComponentTypes(child, [Panel])).filter(child => child.props.active);
330
+ if (activePanels.length > 1) {
331
+ error(false, `[Tabs] Only one Panel can be marked as active.`);
332
+ }
333
+ const selectedChildIndex = Children.toArray(children).filter(child => matchComponentTypes(child, [Panel])).findIndex(child => child.props.isSelected && !child.props.isDisabled);
334
+ const selectedIndex = selectedChildIndex >= 0 ? selectedChildIndex : 0;
335
+ Children.toArray(children).map((child, index) => {
336
+ if (matchComponentTypes(child, [Panel])) {
337
+ const selected = !child.props.isDisabled && (child.props.isSelected || selectedIndex === index);
338
+ const id = uid();
339
+ tabs.push(this.createTab(index, id, selected, child));
340
+ if (activePanels.length === 1) {
341
+ panels.push(this.clonePanel(index, id, selected, child, activePanels[0]));
342
+ } else {
343
+ panels.push(this.clonePanel(index, id, selected, child));
344
+ }
345
+ } else {
346
+ panels.push(child);
347
+ }
348
+ });
349
+ const withScrollFade = tabOverflow === 'scroll' && this.state.withTabListOverflow;
350
+
351
+ // suppress overlay whenever final Tab is active, or Firefox will cover it
352
+ const startScrollOverlay = this.state.showStartOverLay ? _jsx("span", {
353
+ css: styles === null || styles === void 0 ? void 0 : styles.startScrollOverlay
354
+ }, "start-overlay") : null;
355
+ const endScrollOverlay = this.state.showEndOverLay ? _jsx("span", {
356
+ css: styles === null || styles === void 0 ? void 0 : styles.endScrollOverlay
357
+ }, "end-overlay") : null;
358
+ return _jsxs(View, {
359
+ ...passthroughProps(props),
360
+ elementRef: this.handleRef,
361
+ maxWidth: maxWidth,
362
+ margin: margin,
363
+ as: "div",
364
+ css: styles === null || styles === void 0 ? void 0 : styles.container,
365
+ "data-cid": "Tabs",
366
+ children: [_jsx(Focusable, {
367
+ ref: this.handleFocusableRef,
368
+ children: () => _jsx(View, {
369
+ as: "div",
370
+ position: "relative",
371
+ borderRadius: "medium",
372
+ shouldAnimateFocus: false,
373
+ css: styles === null || styles === void 0 ? void 0 : styles.tabs,
374
+ children: _jsxs(View, {
375
+ as: "div",
376
+ role: "tablist",
377
+ css: styles === null || styles === void 0 ? void 0 : styles.tabList,
378
+ "aria-label": screenReaderLabel,
379
+ elementRef: this.handleTabListRef,
380
+ onScroll: this.handleScroll,
381
+ children: [tabs, withScrollFade && startScrollOverlay, withScrollFade && endScrollOverlay]
382
+ })
383
+ })
384
+ }), _jsx("div", {
385
+ css: styles === null || styles === void 0 ? void 0 : styles.panelsContainer,
386
+ children: panels
387
+ })]
388
+ });
389
+ }
390
+ }, _Tabs.displayName = "Tabs", _Tabs.componentId = 'Tabs', _Tabs.allowedProps = allowedProps, _Tabs.defaultProps = {
391
+ variant: 'default',
392
+ shouldFocusOnRender: false,
393
+ tabOverflow: 'stack'
394
+ }, _Tabs.Panel = Panel, _Tabs.Tab = Tab, _Tabs)) || _class);
395
+ export default Tabs;
396
+ export { Tabs, Panel };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const allowedProps = ['children', 'variant', 'screenReaderLabel', 'onRequestTabChange', 'maxWidth', 'maxHeight', 'minHeight', 'fixHeight', 'margin', 'padding', 'textAlign', 'elementRef', 'tabOverflow', 'shouldFocusOnRender'];
26
+ export { allowedProps };
@@ -0,0 +1,145 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @param {Object} params the props and passed through data of the component, the style is applied to
32
+ * @return {Object} The final style object, which will be used in the component
33
+ */
34
+ const generateStyle = (componentTheme, params) => {
35
+ const variant = params.variant,
36
+ tabOverflow = params.tabOverflow,
37
+ fixHeight = params.fixHeight;
38
+
39
+ // fixHeight can be 0, so simply `fixheight` could return falsy value
40
+ const hasFixedHeight = typeof fixHeight !== 'undefined';
41
+ const variants = {
42
+ default: {
43
+ container: {
44
+ background: componentTheme.defaultBackground
45
+ },
46
+ tabs: {
47
+ marginBottom: `calc(${componentTheme.tabVerticalOffset} * -1)`
48
+ },
49
+ scrollOverlay: {
50
+ width: componentTheme.scrollOverlayWidthDefault
51
+ }
52
+ },
53
+ secondary: {
54
+ container: {
55
+ background: componentTheme.defaultBackground
56
+ },
57
+ tabs: {},
58
+ scrollOverlay: {
59
+ width: componentTheme.scrollOverlayWidthSecondary
60
+ }
61
+ }
62
+ };
63
+ const tabOverflowVariants = {
64
+ stack: {
65
+ flexFlow: 'row wrap'
66
+ },
67
+ scroll: {
68
+ marginBottom: variant === 'secondary' ? `calc(${componentTheme.tabVerticalOffset} * -1)` : 0,
69
+ overflowX: 'auto',
70
+ ...(variant === 'default' && {
71
+ '&::-webkit-scrollbar-track': {
72
+ backgroundColor: 'transparent'
73
+ },
74
+ '&::-webkit-scrollbar': {
75
+ height: '0.0625rem',
76
+ backgroundColor: 'transparent'
77
+ },
78
+ '&::-webkit-scrollbar-thumb': {
79
+ backgroundColor: 'transparent'
80
+ }
81
+ }),
82
+ scrollbarWidth: 'none'
83
+ }
84
+ };
85
+ const commonOverlay = {
86
+ height: `calc(100% - (${componentTheme.tabVerticalOffset} + 0.25rem))`,
87
+ position: 'absolute',
88
+ zIndex: componentTheme.zIndex,
89
+ top: '0',
90
+ pointerEvents: 'none',
91
+ ...variants[variant].scrollOverlay
92
+ };
93
+ return {
94
+ tabs: {
95
+ label: 'tabs',
96
+ flexShrink: 0,
97
+ flexGrow: 0,
98
+ ...variants[variant].tabs
99
+ },
100
+ container: {
101
+ label: 'tabs__container',
102
+ display: 'flex',
103
+ flexDirection: 'column',
104
+ height: fixHeight,
105
+ ...variants[variant].container
106
+ },
107
+ tabList: {
108
+ label: 'tabs__tabList',
109
+ display: 'flex',
110
+ width: '100%',
111
+ ...tabOverflowVariants[tabOverflow]
112
+ },
113
+ panelsContainer: {
114
+ label: 'tabs__panelsContainer',
115
+ flexShrink: 1,
116
+ flexGrow: 1,
117
+ display: 'flex',
118
+ flexDirection: 'column',
119
+ ...(hasFixedHeight && {
120
+ overflowY: 'hidden'
121
+ })
122
+ },
123
+ endScrollOverlay: {
124
+ label: 'tabs__endScrollOverlay',
125
+ insetInlineEnd: '0',
126
+ background: `linear-gradient(to left, ${componentTheme.scrollFadeColor} 0%, rgba(255, 255, 255, 0) 100%)`,
127
+ '[dir="rtl"] &': {
128
+ background: `linear-gradient(to right, ${componentTheme.scrollFadeColor} 0%, rgba(255, 255, 255, 0) 100%)`
129
+ },
130
+ ...commonOverlay
131
+ },
132
+ startScrollOverlay: {
133
+ label: 'tabs__startScrollOverlay',
134
+ insetInlineStart: '0',
135
+ background: `linear-gradient(to right, ${componentTheme.scrollFadeColor} 0%, rgba(255, 255, 255, 0) 100%)`,
136
+ '[dir="rtl"] &': {
137
+ background: `linear-gradient(to left, ${componentTheme.scrollFadeColor} 0%, rgba(255, 255, 255, 0) 100%)`
138
+ },
139
+ ...commonOverlay
140
+ },
141
+ scrollOverlayWidthDefault: componentTheme.scrollOverlayWidthDefault,
142
+ scrollOverlayWidthSecondary: componentTheme.scrollOverlayWidthSecondary
143
+ };
144
+ };
145
+ export default generateStyle;
@@ -21,6 +21,6 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- export { Tabs } from "./Tabs/index.js";
25
- export { Panel as TabsPanel } from "./Tabs/Panel/index.js";
26
- export { Tab as TabsTab } from "./Tabs/Tab/index.js";
24
+ export { Tabs } from "../Tabs/v1/index.js";
25
+ export { Panel as TabsPanel } from "../Tabs/v1/Panel/index.js";
26
+ export { Tab as TabsTab } from "../Tabs/v1/Tab/index.js";
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ export { Tabs } from "../Tabs/v2/index.js";
25
+ export { Panel as TabsPanel } from "../Tabs/v2/Panel/index.js";
26
+ export { Tab as TabsTab } from "../Tabs/v2/Tab/index.js";