@auth0/quantum-product 2.10.8 → 2.12.0

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 (44) hide show
  1. package/dropdown-menu/dropdown-menu-list-item/dropdown-menu-list-item.js +2 -1
  2. package/dropdown-menu/dropdown-menu.js +1 -1
  3. package/esm/dropdown-menu/dropdown-menu-list-item/dropdown-menu-list-item.js +2 -1
  4. package/esm/dropdown-menu/dropdown-menu.js +1 -1
  5. package/esm/label/label.js +6 -0
  6. package/esm/switch/switch-classes.js +1 -1
  7. package/esm/switch/switch-overrides.js +119 -41
  8. package/esm/switch/switch.js +104 -10
  9. package/esm/tabs/tab/tab-override.js +18 -7
  10. package/esm/tabs/tab-list/tab-list-overrides.js +94 -0
  11. package/esm/tabs/tab-list/tab-list-utils.js +29 -0
  12. package/esm/tabs/tab-list/tab-list.js +111 -10
  13. package/esm/tabs/tab-list/use-tab-list-indicator/index.js +189 -0
  14. package/esm/tabs/tab-list/use-tab-list-keyboard/index.js +56 -0
  15. package/esm/tabs/tab-list/use-tab-list-overflow/index.js +149 -0
  16. package/esm/tabs/tabs-overrides.js +6 -7
  17. package/esm/tabs/tabs.js +12 -20
  18. package/label/label.d.ts +2 -2
  19. package/label/label.js +6 -0
  20. package/package.json +6 -1
  21. package/page/page-header/page-header.d.ts +1 -1
  22. package/switch/switch-classes.d.ts +1 -1
  23. package/switch/switch-classes.js +1 -1
  24. package/switch/switch-overrides.js +119 -41
  25. package/switch/switch.d.ts +1 -1
  26. package/switch/switch.js +103 -9
  27. package/tabs/tab/tab-override.d.ts +1 -1
  28. package/tabs/tab/tab-override.js +18 -7
  29. package/tabs/tab/tab.d.ts +1 -1
  30. package/tabs/tab-list/tab-list-overrides.d.ts +12 -0
  31. package/tabs/tab-list/tab-list-overrides.js +97 -0
  32. package/tabs/tab-list/tab-list-utils.d.ts +32 -0
  33. package/tabs/tab-list/tab-list-utils.js +70 -0
  34. package/tabs/tab-list/tab-list.d.ts +9 -2
  35. package/tabs/tab-list/tab-list.js +111 -11
  36. package/tabs/tab-list/use-tab-list-indicator/index.d.ts +26 -0
  37. package/tabs/tab-list/use-tab-list-indicator/index.js +226 -0
  38. package/tabs/tab-list/use-tab-list-keyboard/index.d.ts +13 -0
  39. package/tabs/tab-list/use-tab-list-keyboard/index.js +93 -0
  40. package/tabs/tab-list/use-tab-list-overflow/index.d.ts +25 -0
  41. package/tabs/tab-list/use-tab-list-overflow/index.js +186 -0
  42. package/tabs/tabs-overrides.d.ts +1 -1
  43. package/tabs/tabs-overrides.js +6 -7
  44. package/tabs/tabs.js +12 -20
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __read = (this && this.__read) || function (o, n) {
36
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
37
+ if (!m) return o;
38
+ var i = m.call(o), r, ar = [], e;
39
+ try {
40
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
41
+ }
42
+ catch (error) { e = { error: error }; }
43
+ finally {
44
+ try {
45
+ if (r && !r.done && (m = i["return"])) m.call(i);
46
+ }
47
+ finally { if (e) throw e.error; }
48
+ }
49
+ return ar;
50
+ };
51
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
52
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
53
+ if (ar || !(i in from)) {
54
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
55
+ ar[i] = from[i];
56
+ }
57
+ }
58
+ return to.concat(ar || Array.prototype.slice.call(from));
59
+ };
60
+ Object.defineProperty(exports, "__esModule", { value: true });
61
+ exports.useTabListOverflow = void 0;
62
+ var React = __importStar(require("react"));
63
+ var tabs_context_1 = require("../../tabs-context");
64
+ var tab_list_utils_1 = require("../tab-list-utils");
65
+ var useTabListOverflow = function (_a) {
66
+ var children = _a.children, maxVisibleTabs = _a.maxVisibleTabs, moreLabel = _a.moreLabel, getOverflowCountLabel = _a.getOverflowCountLabel;
67
+ var _b = (0, tabs_context_1.useTabsContext)(), onChange = _b.onChange, value = _b.value;
68
+ var allChildren = React.useMemo(function () { return React.Children.toArray(children); }, [children]);
69
+ var resolvedChildren = React.useMemo(function () {
70
+ return allChildren.map(function (child, index) {
71
+ if (!(0, tab_list_utils_1.isTabChild)(child) || child.props.value !== undefined) {
72
+ return child;
73
+ }
74
+ return React.cloneElement(child, { value: (0, tab_list_utils_1.getResolvedChildValue)(child, index) });
75
+ });
76
+ }, [allChildren]);
77
+ var defaultTabOrder = React.useMemo(function () { return resolvedChildren.map(function (child, index) { return (0, tab_list_utils_1.getChildOrderValue)(child, index); }); }, [resolvedChildren]);
78
+ var childByOrderValue = React.useMemo(function () {
79
+ return new Map(defaultTabOrder.map(function (orderValue, index) { return [orderValue, resolvedChildren[index]]; }));
80
+ }, [defaultTabOrder, resolvedChildren]);
81
+ var baseVisibleTabCount = React.useMemo(function () {
82
+ var normalizedMaxVisibleTabs = Number.isFinite(maxVisibleTabs) && maxVisibleTabs > 0 ? maxVisibleTabs : resolvedChildren.length;
83
+ return Math.min(resolvedChildren.length, normalizedMaxVisibleTabs);
84
+ }, [resolvedChildren.length, maxVisibleTabs]);
85
+ var _c = __read(React.useState(function () {
86
+ return (0, tab_list_utils_1.createOverflowState)({
87
+ baseVisibleTabCount: baseVisibleTabCount,
88
+ moreLabel: moreLabel,
89
+ defaultTabOrder: defaultTabOrder,
90
+ });
91
+ }), 2), overflowState = _c[0], setOverflowState = _c[1];
92
+ var shouldResetOverflowState = overflowState.baselineVisibleTabCount !== baseVisibleTabCount ||
93
+ overflowState.baselineMoreLabel !== moreLabel ||
94
+ !(0, tab_list_utils_1.areValueArraysEqual)(overflowState.baselineTabOrder, defaultTabOrder);
95
+ var hasValidOrderedTabValues = overflowState.orderedTabValues !== undefined &&
96
+ overflowState.orderedTabValues.length === defaultTabOrder.length &&
97
+ overflowState.orderedTabValues.every(function (orderValue) { return childByOrderValue.has(orderValue); });
98
+ var overflowCompensation = shouldResetOverflowState ? 0 : overflowState.overflowCompensation;
99
+ var orderedTabValues = shouldResetOverflowState || !hasValidOrderedTabValues ? undefined : overflowState.orderedTabValues;
100
+ var minimumVisibleTabCount = baseVisibleTabCount > 0 ? 1 : 0;
101
+ var visibleTabCount = Math.max(minimumVisibleTabCount, baseVisibleTabCount - overflowCompensation);
102
+ var orderedChildren = React.useMemo(function () {
103
+ if (!orderedTabValues || orderedTabValues.length !== resolvedChildren.length) {
104
+ return resolvedChildren;
105
+ }
106
+ var mappedChildren = orderedTabValues.map(function (orderValue) { return childByOrderValue.get(orderValue); });
107
+ if (mappedChildren.some(function (child) { return child === undefined; })) {
108
+ return resolvedChildren;
109
+ }
110
+ return mappedChildren;
111
+ }, [childByOrderValue, orderedTabValues, resolvedChildren]);
112
+ var resetOverflowState = React.useCallback(function () {
113
+ setOverflowState((0, tab_list_utils_1.createOverflowState)({
114
+ baseVisibleTabCount: baseVisibleTabCount,
115
+ moreLabel: moreLabel,
116
+ defaultTabOrder: defaultTabOrder,
117
+ }));
118
+ }, [baseVisibleTabCount, defaultTabOrder, moreLabel]);
119
+ var handleChange = React.useCallback(function (_evt, newValue) {
120
+ if (orderedTabValues !== undefined) {
121
+ resetOverflowState();
122
+ }
123
+ if (onChange) {
124
+ onChange(newValue);
125
+ }
126
+ }, [onChange, orderedTabValues, resetOverflowState]);
127
+ var _d = React.useMemo(function () {
128
+ var shouldOverflow = orderedChildren.length > visibleTabCount;
129
+ if (!shouldOverflow) {
130
+ return {
131
+ visibleChildren: orderedChildren,
132
+ overflowChildren: [],
133
+ };
134
+ }
135
+ var visible = orderedChildren.slice(0, visibleTabCount);
136
+ var selectedChild = orderedChildren.find(function (child) { return (0, tab_list_utils_1.isTabChild)(child) && child.props.value === value; });
137
+ if (selectedChild && !visible.includes(selectedChild) && visibleTabCount > 0) {
138
+ visible = __spreadArray(__spreadArray([], __read(visible.slice(0, Math.max(visibleTabCount - 1, 0))), false), [selectedChild], false);
139
+ }
140
+ var visibleSet = new Set(visible);
141
+ var overflow = orderedChildren.filter(function (child) { return !visibleSet.has(child); });
142
+ return {
143
+ visibleChildren: visible,
144
+ overflowChildren: overflow,
145
+ };
146
+ }, [orderedChildren, value, visibleTabCount]), visibleChildren = _d.visibleChildren, overflowChildren = _d.overflowChildren;
147
+ var hasOverflow = overflowChildren.length > 0;
148
+ var overflowCountLabel = React.useMemo(function () { return getOverflowCountLabel(overflowChildren.length); }, [getOverflowCountLabel, overflowChildren.length]);
149
+ var isSelectedValueVisible = React.useMemo(function () { return visibleChildren.some(function (child) { return (0, tab_list_utils_1.isTabChild)(child) && child.props.value === value; }); }, [value, visibleChildren]);
150
+ var isSelectedValueInOverflow = React.useMemo(function () { return overflowChildren.some(function (child) { return (0, tab_list_utils_1.isTabChild)(child) && child.props.value === value; }); }, [overflowChildren, value]);
151
+ var promoteTabValue = React.useCallback(function (tabValue) {
152
+ var _a;
153
+ var nextOrderedChildren = __spreadArray([], __read(orderedChildren), false);
154
+ var lastVisibleIndex = baseVisibleTabCount - 1;
155
+ var selectedIndex = nextOrderedChildren.findIndex(function (orderedChild) { return (0, tab_list_utils_1.isTabChild)(orderedChild) && orderedChild.props.value === tabValue; });
156
+ if (selectedIndex !== -1 && lastVisibleIndex >= 0 && selectedIndex !== lastVisibleIndex) {
157
+ _a = __read([
158
+ nextOrderedChildren[selectedIndex],
159
+ nextOrderedChildren[lastVisibleIndex],
160
+ ], 2), nextOrderedChildren[lastVisibleIndex] = _a[0], nextOrderedChildren[selectedIndex] = _a[1];
161
+ }
162
+ setOverflowState((0, tab_list_utils_1.createOverflowState)({
163
+ baseVisibleTabCount: baseVisibleTabCount,
164
+ moreLabel: moreLabel,
165
+ defaultTabOrder: defaultTabOrder,
166
+ orderedTabValues: nextOrderedChildren.map(function (orderedChild, index) { return (0, tab_list_utils_1.getChildOrderValue)(orderedChild, index); }),
167
+ }));
168
+ }, [baseVisibleTabCount, defaultTabOrder, moreLabel, orderedChildren]);
169
+ return {
170
+ value: value,
171
+ onChange: onChange,
172
+ baseVisibleTabCount: baseVisibleTabCount,
173
+ minimumVisibleTabCount: minimumVisibleTabCount,
174
+ defaultTabOrder: defaultTabOrder,
175
+ visibleChildren: visibleChildren,
176
+ overflowChildren: overflowChildren,
177
+ hasOverflow: hasOverflow,
178
+ overflowCountLabel: overflowCountLabel,
179
+ isSelectedValueVisible: isSelectedValueVisible,
180
+ isSelectedValueInOverflow: isSelectedValueInOverflow,
181
+ handleChange: handleChange,
182
+ setOverflowState: setOverflowState,
183
+ promoteTabValue: promoteTabValue,
184
+ };
185
+ };
186
+ exports.useTabListOverflow = useTabListOverflow;
@@ -1,3 +1,3 @@
1
- import type { TabsProps, TabsClassKey } from '@mui/material/Tabs';
1
+ import type { TabsClassKey, TabsProps } from '@mui/material/Tabs';
2
2
  import type { ComponentOverrideCreator } from '../theme/create-component-overrides';
3
3
  export declare const createMuiTabsOverrides: ComponentOverrideCreator<TabsProps, TabsClassKey>;
@@ -2,21 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createMuiTabsOverrides = void 0;
4
4
  var createMuiTabsOverrides = function (_a) {
5
- var tokens = _a.tokens;
5
+ var spacing = _a.spacing;
6
6
  return {
7
7
  defaultProps: {
8
8
  indicatorColor: 'primary',
9
9
  textColor: 'primary',
10
10
  },
11
11
  styleOverrides: {
12
- indicator: {
13
- backgroundColor: tokens.color_border_selected,
12
+ root: {
13
+ minHeight: 'unset',
14
14
  },
15
15
  flexContainer: {
16
- display: 'block',
17
- },
18
- scroller: {
19
- borderBottom: "1px solid ".concat(tokens.color_border_default),
16
+ display: 'flex',
17
+ gap: spacing(0.5),
18
+ paddingBottom: spacing(1),
20
19
  },
21
20
  },
22
21
  };
package/tabs/tabs.js CHANGED
@@ -37,23 +37,17 @@ exports.Tabs = void 0;
37
37
  var React = __importStar(require("react"));
38
38
  var tabs_context_1 = require("./tabs-context");
39
39
  var Tabs = function (_a) {
40
- var baseId = _a.baseId, fullWidth = _a.fullWidth, onChange = _a.onChange, selectedValue = _a.value, isLazy = _a.isLazy, children = _a.children;
41
- var getTabPanelId = function (value) { return "".concat(baseId, "-tabpanel-").concat(value); };
42
- var getTabId = function (value) { return "".concat(baseId, "-tab-").concat(value); };
43
- var getTabProps = function (value) {
44
- return {
45
- id: getTabId(value),
46
- 'aria-controls': getTabPanelId(value),
47
- };
48
- };
49
- var getTabPanelProps = function (value) {
50
- return {
51
- role: 'tabpanel',
52
- hidden: selectedValue !== value,
53
- id: getTabPanelId(value),
54
- 'aria-labelledby': getTabId(value),
55
- };
56
- };
40
+ var baseId = _a.baseId, fullWidth = _a.fullWidth, onChange = _a.onChange, selectedValue = _a.value, _b = _a.isLazy, isLazy = _b === void 0 ? true : _b, children = _a.children;
41
+ var getTabProps = React.useCallback(function (value) { return ({
42
+ id: "".concat(baseId, "-tab-").concat(value),
43
+ 'aria-controls': "".concat(baseId, "-tabpanel-").concat(value),
44
+ }); }, [baseId]);
45
+ var getTabPanelProps = React.useCallback(function (value) { return ({
46
+ role: 'tabpanel',
47
+ hidden: selectedValue !== value,
48
+ id: "".concat(baseId, "-tabpanel-").concat(value),
49
+ 'aria-labelledby': "".concat(baseId, "-tab-").concat(value),
50
+ }); }, [baseId, selectedValue]);
57
51
  var ctxValue = React.useMemo(function () { return ({
58
52
  onChange: onChange,
59
53
  getTabProps: getTabProps,
@@ -61,9 +55,7 @@ var Tabs = function (_a) {
61
55
  value: selectedValue,
62
56
  isLazy: isLazy,
63
57
  fullWidth: fullWidth,
64
- }); },
65
- // eslint-disable-next-line react-hooks/exhaustive-deps
66
- [selectedValue, baseId, onChange, isLazy, fullWidth]);
58
+ }); }, [selectedValue, onChange, isLazy, fullWidth, getTabProps, getTabPanelProps]);
67
59
  return React.createElement(tabs_context_1.TabsContext.Provider, { value: ctxValue }, children);
68
60
  };
69
61
  exports.Tabs = Tabs;