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