@plesk/ui-library 3.42.0 → 3.43.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 (69) hide show
  1. package/cjs/components/CodeEditor/CodeEditor.js +1 -2
  2. package/cjs/components/Icon/constants.js +0 -1
  3. package/cjs/components/List/List.js +6 -3
  4. package/cjs/components/Tabs/FakeTabs.js +58 -0
  5. package/cjs/components/Tabs/Tab.js +0 -1
  6. package/cjs/components/Tabs/TabClose.js +35 -0
  7. package/cjs/components/Tabs/TabIcon.js +22 -0
  8. package/cjs/components/Tabs/TabLabel.js +34 -0
  9. package/cjs/components/Tabs/TabList.js +120 -0
  10. package/cjs/components/Tabs/TabListItem.js +75 -0
  11. package/cjs/components/Tabs/Tabs.js +98 -537
  12. package/cjs/components/Tabs/useActive.js +19 -0
  13. package/cjs/components/Tabs/useWidths.js +102 -0
  14. package/cjs/components/Toaster/PanelView.js +15 -13
  15. package/cjs/components/Toolbar/ToolbarMenu.js +0 -1
  16. package/cjs/components/Toolbar/index.js +1 -8
  17. package/cjs/components/index.js +0 -7
  18. package/cjs/index.js +1 -1
  19. package/dist/plesk-ui-library-rtl.css +1 -1
  20. package/dist/plesk-ui-library-rtl.css.map +1 -1
  21. package/dist/plesk-ui-library.css +1 -1
  22. package/dist/plesk-ui-library.css.map +1 -1
  23. package/dist/plesk-ui-library.js +668 -608
  24. package/dist/plesk-ui-library.js.map +1 -1
  25. package/dist/plesk-ui-library.min.js +5 -5
  26. package/dist/plesk-ui-library.min.js.map +1 -1
  27. package/esm/components/CodeEditor/CodeEditor.js +1 -2
  28. package/esm/components/Icon/constants.js +0 -1
  29. package/esm/components/List/List.js +6 -3
  30. package/esm/components/Tabs/FakeTabs.js +51 -0
  31. package/esm/components/Tabs/Tab.js +0 -1
  32. package/esm/components/Tabs/TabClose.js +28 -0
  33. package/esm/components/Tabs/TabIcon.js +14 -0
  34. package/esm/components/Tabs/TabLabel.js +27 -0
  35. package/esm/components/Tabs/TabList.js +111 -0
  36. package/esm/components/Tabs/TabListItem.js +68 -0
  37. package/esm/components/Tabs/Tabs.js +100 -537
  38. package/esm/components/Tabs/useActive.js +12 -0
  39. package/esm/components/Tabs/useWidths.js +95 -0
  40. package/esm/components/Toaster/PanelView.js +15 -13
  41. package/esm/components/Toolbar/ToolbarMenu.js +0 -1
  42. package/esm/components/Toolbar/index.js +1 -2
  43. package/esm/components/index.js +1 -1
  44. package/esm/index.js +1 -1
  45. package/package.json +9 -10
  46. package/styleguide/build/bundle.ef040f7a.js +2 -0
  47. package/styleguide/index.html +2 -2
  48. package/types/components/Carousel/Carousel.d.ts +1 -1
  49. package/types/components/Label/Label.d.ts +1 -1
  50. package/types/components/List/List.d.ts +8 -2
  51. package/types/components/Tabs/FakeTabs.d.ts +9 -0
  52. package/types/components/Tabs/SearchBar.d.ts +3 -3
  53. package/types/components/Tabs/TabClose.d.ts +9 -0
  54. package/types/components/Tabs/TabIcon.d.ts +7 -0
  55. package/types/components/Tabs/TabLabel.d.ts +9 -0
  56. package/types/components/Tabs/TabList.d.ts +14 -0
  57. package/types/components/Tabs/TabListItem.d.ts +12 -0
  58. package/types/components/Tabs/Tabs.d.ts +2 -52
  59. package/types/components/Tabs/useActive.d.ts +1 -0
  60. package/types/components/Tabs/useWidths.d.ts +16 -0
  61. package/types/components/Toolbar/index.d.ts +0 -1
  62. package/types/components/index.d.ts +1 -1
  63. package/types/utils/types/ComponentProps.d.ts +1 -1
  64. package/types/utils/types/PolymorphicComponent.d.ts +2 -2
  65. package/cjs/components/Toolbar/ToolbarBetaProvider.js +0 -23
  66. package/esm/components/Toolbar/ToolbarBetaProvider.js +0 -16
  67. package/styleguide/build/bundle.7ac8a2af.js +0 -2
  68. package/types/components/Toolbar/ToolbarBetaProvider.d.ts +0 -5
  69. /package/styleguide/build/{bundle.7ac8a2af.js.LICENSE.txt → bundle.ef040f7a.js.LICENSE.txt} +0 -0
@@ -1,21 +1,14 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  // Copyright 1999-2025. WebPros International GmbH. All rights reserved.
3
2
 
4
3
  import classNames from 'classnames';
5
- import { Children, cloneElement, Component, Fragment, isValidElement } from 'react';
6
- import Measure from 'react-measure';
4
+ import { Children, cloneElement, useRef, useState } from 'react';
7
5
  import { CLS_PREFIX } from '../../constants';
8
- import Dropdown from '../Dropdown';
9
- import Icon, { ICON_SIZE_16 } from '../Icon';
10
- import Label from '../Label';
11
- import Menu, { MenuItem } from '../Menu';
12
6
  import ResponsiveContext from '../ResponsiveContext';
13
- import { wrapFunction } from '../utils';
14
- import Tab from './Tab';
15
- import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
16
- const ADDON_LEFT_PADDING = 5;
17
- const MIN_ADDON_WIDTH_DEFAULT = 150;
18
- const COLLAPSED_SEARCH_WIDTH = 60;
7
+ import FakeTabs from './FakeTabs';
8
+ import TabList from './TabList';
9
+ import { useActive } from './useActive';
10
+ import { useWidths } from './useWidths';
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
12
  /**
20
13
  * `Tabs` component is a content area with a group of individual [Tab](#!/Tab) elements, each displaying different content
21
14
  * in the same screen area. `Tabs` are used when you have too much content to display in one place at the same time, so
@@ -23,430 +16,65 @@ const COLLAPSED_SEARCH_WIDTH = 60;
23
16
  * group name and a navigation button.
24
17
  * @since 0.0.35
25
18
  */
26
- class Tabs extends Component {
27
- constructor() {
28
- super(...arguments);
29
- _defineProperty(this, "state", {
30
- active: this.props.active || 1,
31
- collapsedLength: 0,
32
- compact: false,
33
- searching: false,
34
- monospacedWidth: 0
35
- });
36
- _defineProperty(this, "widths", void 0);
37
- _defineProperty(this, "addon", void 0);
38
- _defineProperty(this, "tabsnavRef", void 0);
39
- _defineProperty(this, "moreTabsRef", null);
40
- _defineProperty(this, "checkAdaptive", () => {
41
- let {
42
- compact,
43
- searching,
44
- collapsedLength
45
- } = this.state;
46
- const {
47
- addonMinWidth: addonMinWidthProp,
48
- search,
49
- monospaced
50
- } = this.props;
51
- const {
52
- widths,
53
- addon
54
- } = this;
55
- let monospacedWidth = 0;
56
- const getMonospacedWidth = () => monospacedWidth;
57
- if (!widths) {
58
- return;
59
- }
60
- const addonMinWidth = ADDON_LEFT_PADDING + (addonMinWidthProp || (search?.props.minWidth ?? MIN_ADDON_WIDTH_DEFAULT));
61
- const searchWidth = compact && search ? COLLAPSED_SEARCH_WIDTH + ADDON_LEFT_PADDING : 0;
62
- const {
63
- more,
64
- container,
65
- margin
66
- } = widths;
67
- let tabs = widths.tabs.slice();
68
- const tabsNumber = tabs.length;
69
- let lastTabIndex = tabsNumber - 1 - collapsedLength;
70
- if (monospaced) {
71
- monospacedWidth = Math.max(...tabs.slice(0, lastTabIndex + 1));
72
- tabs = tabs.map(getMonospacedWidth);
73
- }
74
- const getListWidth = () => {
75
- let listWidth = monospaced ? margin * Math.max(0, tabsNumber - 1 - Math.max(0, collapsedLength - 1)) : 0;
76
- for (let i = 0; i <= lastTabIndex; ++i) {
77
- listWidth += tabs[i];
78
- }
79
- if (collapsedLength) {
80
- listWidth += more;
81
- }
82
- return listWidth;
83
- };
84
- let spaceForAddon = container - getListWidth();
85
- if (addon && !collapsedLength && !compact && spaceForAddon <= addonMinWidth) {
86
- compact = true;
87
- }
88
- let freeSpace = spaceForAddon - searchWidth;
89
- if (freeSpace <= 0) {
90
- // collapse
91
- for (let i = lastTabIndex; i >= 0; --i) {
92
- let width = tabs[i];
93
- if (monospaced && widths.tabs[i] === monospacedWidth) {
94
- monospacedWidth = widths.tabs.slice(0, lastTabIndex).reduce((max, tab) => tab > max ? tab : max, 0);
95
- tabs = tabs.map(getMonospacedWidth);
96
- width += (widths.tabs[i] - monospacedWidth) * lastTabIndex;
97
- }
98
- if (collapsedLength === 0) {
99
- width -= more;
100
- }
101
- freeSpace += width;
102
- ++collapsedLength;
103
- --lastTabIndex;
104
- if (freeSpace > 0) {
105
- break;
106
- }
107
- }
108
- } else {
109
- // expand
110
- for (let i = lastTabIndex + 1; i < tabsNumber; ++i) {
111
- let width = tabs[i];
112
- if (monospaced && widths.tabs[i] > monospacedWidth) {
113
- monospacedWidth = widths.tabs[i];
114
- tabs = tabs.map(getMonospacedWidth);
115
- width = monospacedWidth + (monospacedWidth - width) * (lastTabIndex + 1);
116
- }
117
- if (collapsedLength === 1) {
118
- width -= more;
119
- }
120
- if (freeSpace <= width) {
121
- break;
122
- }
123
- freeSpace -= width;
124
- --collapsedLength;
125
- ++lastTabIndex;
126
- }
127
- }
128
- if (collapsedLength || compact) {
129
- spaceForAddon = container - getListWidth();
130
- if (collapsedLength) {
131
- compact = true;
132
- } else if (spaceForAddon >= addonMinWidth) {
133
- compact = false;
134
- searching = false;
135
- }
136
- }
137
- const newState = {
138
- compact,
139
- searching,
140
- collapsedLength,
141
- monospacedWidth
142
- };
143
- for (const key of Object.keys(newState)) {
144
- if (JSON.stringify(newState[key]) === JSON.stringify(this.state[key])) {
145
- delete newState[key];
146
- }
147
- }
148
- if (Object.keys(newState).length) {
149
- this.setState(newState, () => {
150
- if (typeof newState.collapsedLength !== 'undefined' && this.state.collapsedLength !== newState.collapsedLength) {
151
- this.checkAdaptive();
152
- }
153
- });
154
- }
155
- });
156
- _defineProperty(this, "handleStartSearching", () => {
157
- this.setState({
158
- searching: true
159
- });
160
- });
161
- _defineProperty(this, "handleCancelSearching", () => {
162
- this.setState({
163
- searching: false
164
- }, this.checkAdaptive);
165
- });
166
- _defineProperty(this, "handleResize", () => {
167
- const {
168
- baseClassName
169
- } = this.props;
170
- if (this.tabsnavRef) {
171
- const tabElements = this.tabsnavRef.querySelectorAll(`.${baseClassName}__tab-list--fake .${baseClassName}__tab`);
172
- const more = tabElements[tabElements.length - 1];
173
- const tabs = Array.prototype.slice.call(tabElements, 0, -1).map(el => el.offsetWidth);
174
- this.widths = {
175
- tabs,
176
- more: more.offsetWidth,
177
- container: this.tabsnavRef.offsetWidth,
178
- margin: more.offsetWidth - (more.querySelector(`.${baseClassName}__link`)?.offsetWidth ?? 0)
179
- };
180
- }
181
- this.checkAdaptive();
182
- });
183
- _defineProperty(this, "handleAddonResize", contentRect => {
184
- this.addon = contentRect.bounds;
185
- this.checkAdaptive();
186
- });
187
- _defineProperty(this, "renderTabItem", (tab, index, tabMode) => {
188
- const {
189
- baseClassName
190
- } = this.props;
191
- const {
192
- monospacedWidth,
193
- active
194
- } = this.state;
195
- if (!tab || tab.type !== Tab) {
196
- return null;
197
- }
198
- const {
199
- title,
200
- label,
201
- icon,
202
- onActivate,
203
- onClose,
204
- component: Tag = 'a',
205
- ...tabProps
206
- } = tab.props;
207
- const selected = index + 1 === active;
208
- const key = index.toString();
209
- const tabIcon = Icon.create(icon, {
210
- size: ICON_SIZE_16,
211
- className: `${baseClassName}__tab-icon`
212
- });
213
- const tabLabel = this.renderTabLabel(tabMode, label);
214
- const tabClose = this.renderTabClose(tabMode, onClose);
215
- const handleClick = () => this.onClick(index + 1);
216
- tabProps.tabIndex = tabProps.tabIndex || 0;
217
- tabProps.onKeyDown = wrapFunction(tabProps.onKeyDown, e => {
218
- if (e.key === 'Enter') {
219
- e.currentTarget.click();
220
- }
221
- });
222
- if (tabMode === 'menu-item') {
223
- return /*#__PURE__*/_jsx(MenuItem, {
224
- icon: tabIcon,
225
- label: /*#__PURE__*/_jsxs(Fragment, {
226
- children: [tabLabel, tabClose]
227
- }),
228
- active: selected,
229
- onClick: handleClick,
230
- className: `${baseClassName}__menu-item`,
231
- component: Tag,
232
- ...tabProps,
233
- children: title
234
- }, key);
235
- }
236
- return /*#__PURE__*/_jsx("li", {
237
- className: classNames(`${baseClassName}__tab`, selected && `${baseClassName}__tab--selected`, tabClose && `${baseClassName}__tab--closable`),
238
- role: "presentation",
239
- children: /*#__PURE__*/_jsxs(Tag, {
240
- className: `${baseClassName}__link`,
241
- role: "tab",
242
- "aria-selected": selected || undefined,
243
- style: {
244
- width: monospacedWidth || undefined
245
- },
246
- onClick: handleClick,
247
- ...tabProps,
248
- children: [tabIcon, /*#__PURE__*/_jsx("span", {
249
- className: `${baseClassName}__tab-title`,
250
- children: title
251
- }), tabLabel, tabClose]
252
- })
253
- }, key);
254
- });
255
- }
256
- static getDerivedStateFromProps(props, state) {
257
- const {
258
- active
259
- } = props;
260
- const {
261
- prevActive
262
- } = state;
263
- const nextState = {};
264
- if (active && active !== prevActive) {
265
- nextState.active = active;
266
- }
267
- nextState.prevActive = active;
268
- return nextState;
269
- }
270
- componentDidUpdate() {
271
- if (!this.widths || Children.count(this.props.children) !== this.widths.tabs.length) {
272
- setTimeout(() => this.handleResize());
273
- }
274
- }
275
- onClick(active) {
276
- this.setState({
277
- active
278
- });
279
- const tab = Array.isArray(this.props.children) ? this.props.children[active - 1] : this.props.children;
19
+ const Tabs = _ref => {
20
+ let {
21
+ baseClassName = `${CLS_PREFIX}tabs`,
22
+ className,
23
+ addon,
24
+ placeholder,
25
+ children,
26
+ active: externalActive,
27
+ addonMinWidth,
28
+ monospaced,
29
+ search,
30
+ ...props
31
+ } = _ref;
32
+ const addonElement = addon || placeholder;
33
+ const tabNavRef = useRef(null);
34
+ const tabListRef = useRef(null);
35
+ const fakeAddonRef = useRef(null);
36
+ const childrenCount = Children.count(children);
37
+ const [active, setActive] = useActive(externalActive);
38
+ const {
39
+ monospacedWidth,
40
+ recalculateWidths,
41
+ compact,
42
+ visibleLength
43
+ } = useWidths({
44
+ monospaced,
45
+ tabNavRef,
46
+ tabListRef,
47
+ fakeAddonRef,
48
+ baseClassName,
49
+ childrenCount
50
+ });
51
+ const handleTabClick = active => {
52
+ setActive(active);
53
+ const tab = Array.isArray(children) ? children[active - 1] : children;
280
54
  tab?.props?.onActivate?.();
281
- }
282
- renderTabLabel(tabMode, label) {
283
- const {
284
- baseClassName
285
- } = this.props;
286
- if (typeof label === 'string') {
287
- return /*#__PURE__*/_jsx(Label, {
288
- className: `${baseClassName}__${tabMode}-label`,
289
- intent: "danger",
290
- children: label
291
- });
292
- }
293
- if (/*#__PURE__*/isValidElement(label)) {
294
- return /*#__PURE__*/cloneElement(label, {
295
- className: classNames(`${baseClassName}__${tabMode}-label`, label.props.className)
296
- });
297
- }
298
- return null;
299
- }
300
- renderTabClose(tabMode, onClose) {
301
- const {
302
- baseClassName
303
- } = this.props;
304
- if (typeof onClose === 'function') {
305
- return /*#__PURE__*/_jsx("button", {
306
- className: `${baseClassName}__${tabMode}-close`,
307
- type: "button",
308
- onClick: e => {
309
- e.preventDefault();
310
- e.stopPropagation();
311
- onClose(e);
312
- },
313
- children: /*#__PURE__*/_jsx(Icon, {
314
- className: `${baseClassName}__${tabMode}-close-icon`,
315
- name: "cross-mark"
316
- })
317
- });
318
- }
55
+ };
56
+ const [searching, setSearching] = useState(false);
57
+ if (!childrenCount) {
319
58
  return null;
320
59
  }
321
- renderFakeTabs() {
322
- const {
323
- baseClassName,
324
- children
325
- } = this.props;
326
- const childrenCount = Children.count(children);
327
- if (!childrenCount || !children) {
328
- return null;
329
- }
330
- return /*#__PURE__*/_jsxs("ul", {
331
- className: classNames(`${baseClassName}__tab-list`, `${baseClassName}__tab-list--fake`),
332
- children: [Children.map(children, tab => {
333
- if (!tab || tab.type !== Tab) {
334
- return null;
335
- }
336
- const {
337
- title,
338
- label,
339
- icon,
340
- onActivate,
341
- onClose,
342
- ...tabProps
343
- } = tab.props;
344
- const iconBlock = Icon.create(icon, {
345
- size: ICON_SIZE_16,
346
- className: `${baseClassName}__tab-icon`
347
- });
348
- const closeBlock = this.renderTabClose('tab', onClose);
349
- return /*#__PURE__*/_jsxs("li", {
350
- className: classNames(`${baseClassName}__tab`, closeBlock && `${baseClassName}__tab--closable`),
351
- children: [/*#__PURE__*/_jsxs("a", {
352
- className: `${baseClassName}__link`,
353
- tabIndex: -1,
354
- style: tabProps.style,
355
- children: [iconBlock, /*#__PURE__*/_jsx("span", {
356
- className: `${baseClassName}__tab-title`,
357
- children: title
358
- }), this.renderTabLabel('tab', label)]
359
- }), closeBlock]
360
- }, `${title}`);
361
- }), /*#__PURE__*/_jsx("li", {
362
- className: classNames(`${baseClassName}__tab`, `${baseClassName}__tab--more`),
363
- children: /*#__PURE__*/_jsx("a", {
364
- className: `${baseClassName}__link`,
365
- tabIndex: -1,
366
- children: /*#__PURE__*/_jsx(Icon, {
367
- name: "three-dots-horizontal"
368
- })
369
- })
370
- })]
371
- });
372
- }
373
- createTabItems() {
374
- const {
375
- children
376
- } = this.props;
377
- const {
378
- collapsedLength
379
- } = this.state;
380
- const visibleItems = [];
381
- const hiddenItems = [];
382
- const lastTabIndex = Children.count(children) - 1 - collapsedLength;
383
- Children.forEach(children, (child, index) => {
384
- const hidden = index > lastTabIndex;
385
- const tabMode = hidden ? 'menu-item' : 'tab';
386
- const renderedTab = this.renderTabItem(child, index, tabMode);
387
- if (renderedTab) {
388
- (hidden ? hiddenItems : visibleItems).push(renderedTab);
389
- }
390
- });
391
- return {
392
- visibleItems,
393
- hiddenItems
394
- };
395
- }
396
- renderTabList() {
397
- const {
398
- baseClassName,
399
- children
400
- } = this.props;
401
- const {
402
- active
403
- } = this.state;
404
- if (!Children.toArray(children).length) {
405
- return null;
406
- }
407
- const {
408
- visibleItems,
409
- hiddenItems
410
- } = this.createTabItems();
411
- const moreSelected = active > visibleItems.length;
412
- return /*#__PURE__*/_jsxs("ul", {
413
- className: `${baseClassName}__tab-list`,
414
- role: "tablist",
415
- children: [visibleItems, hiddenItems.length > 0 && /*#__PURE__*/_jsx("li", {
416
- ref: ref => this.moreTabsRef = ref,
417
- className: classNames(`${baseClassName}__tab`, moreSelected && `${baseClassName}__tab--selected`, `${baseClassName}__tab--more`),
418
- role: "presentation",
419
- "aria-selected": moreSelected || undefined,
420
- children: /*#__PURE__*/_jsx(Dropdown, {
421
- className: `${baseClassName}__dropdown`,
422
- menu: /*#__PURE__*/_jsx(Menu, {
423
- children: hiddenItems
424
- }),
425
- menuPlacement: "bottom-end",
426
- children: /*#__PURE__*/_jsx("a", {
427
- className: `${baseClassName}__link`,
428
- role: "tab",
429
- tabIndex: 0,
430
- "aria-selected": moreSelected || undefined,
431
- children: /*#__PURE__*/_jsx(Icon, {
432
- name: "three-dots-horizontal"
433
- })
434
- })
435
- })
436
- })]
437
- });
438
- }
439
- renderSearchBar(searchProps) {
440
- const {
441
- baseClassName,
442
- search
443
- } = this.props;
60
+ const renderSearchBar = () => {
444
61
  if (!search) {
445
62
  return null;
446
63
  }
447
- const {
448
- compact
449
- } = this.state;
64
+ const handleStartSearching = () => setSearching(true);
65
+ const handleCancelSearching = () => setSearching(false);
66
+ const searchProps = {
67
+ className: `${baseClassName}__search-bar`,
68
+ collapsable: compact,
69
+ onExpand: handleStartSearching,
70
+ onCollapse: handleCancelSearching,
71
+ ...(searching ? {
72
+ autoFocus: true,
73
+ responsive: false,
74
+ maxWidth: 'none',
75
+ minWidth: 'unset'
76
+ } : {})
77
+ };
450
78
  const clone = /*#__PURE__*/cloneElement(search, searchProps);
451
79
  if (compact) {
452
80
  return /*#__PURE__*/_jsx(ResponsiveContext.Provider, {
@@ -458,112 +86,47 @@ class Tabs extends Component {
458
86
  });
459
87
  }
460
88
  return clone;
89
+ };
90
+ const addonStyle = {};
91
+ if (search && !compact) {
92
+ addonStyle.maxWidth = search.props.maxWidth;
461
93
  }
462
- render() {
463
- const {
464
- baseClassName,
465
- className,
466
- addon,
467
- placeholder,
468
- children,
469
- active,
470
- addonMinWidth,
471
- monospaced,
472
- search,
473
- ...props
474
- } = this.props;
475
- const {
476
- compact,
477
- searching
478
- } = this.state;
479
- const childrenCount = Children.count(children);
480
- if (!childrenCount) {
481
- return null;
482
- }
483
- const addonElement = addon || placeholder;
484
- let addonBlock = addonElement;
485
- const addonProps = {};
486
- let searchBlock = null;
487
- if (search) {
488
- const searchProps = {
489
- collapsable: compact,
490
- onExpand: this.handleStartSearching,
491
- onCollapse: this.handleCancelSearching
492
- };
493
- if (compact) {
494
- if (searching) {
495
- searchProps.maxWidth = undefined;
496
- searchProps.minWidth = undefined;
497
- searchProps.autoFocus = true;
498
- searchProps.responsive = false;
499
- } else {
500
- searchProps.onSearch = this.handleStartSearching;
501
- }
502
- searchBlock = this.renderSearchBar(searchProps);
503
- } else if (addonElement) {
504
- searchProps.key = 1;
505
- addonBlock = /*#__PURE__*/_jsxs(_Fragment, {
506
- children: [this.renderSearchBar(searchProps), /*#__PURE__*/cloneElement(addonElement, {
507
- key: 2
508
- })]
509
- });
510
- } else {
511
- addonProps.style = {
512
- maxWidth: search.props.maxWidth
513
- };
514
- addonBlock = this.renderSearchBar(searchProps);
515
- }
516
- }
517
- return /*#__PURE__*/_jsxs("div", {
518
- className: classNames(baseClassName, className),
519
- ...props,
520
- children: [/*#__PURE__*/_jsx(Measure, {
521
- onResize: this.handleResize,
522
- innerRef: ref => this.tabsnavRef = ref,
523
- children: _ref => {
524
- let {
525
- measureRef
526
- } = _ref;
527
- return /*#__PURE__*/_jsxs("div", {
528
- className: classNames(`${baseClassName}__nav`, compact && `${baseClassName}__nav--compact`, searching && `${baseClassName}__nav--searching`, search && `${baseClassName}__nav--search`),
529
- ref: measureRef,
530
- children: [this.renderTabList(), /*#__PURE__*/_jsx(Measure, {
531
- onResize: this.handleResize,
532
- children: _ref2 => {
533
- let {
534
- measureRef: ref
535
- } = _ref2;
536
- const fakeTabs = this.renderFakeTabs();
537
- return fakeTabs ? /*#__PURE__*/cloneElement(fakeTabs, {
538
- ref
539
- }) : null;
540
- }
541
- }), searchBlock, addonBlock && /*#__PURE__*/_jsx(Measure, {
542
- onResize: this.handleAddonResize,
543
- bounds: true,
544
- children: _ref3 => {
545
- let {
546
- measureRef: ref
547
- } = _ref3;
548
- return /*#__PURE__*/_jsx("div", {
549
- className: `${baseClassName}__addon`,
550
- ref: ref,
551
- ...addonProps,
552
- children: addonBlock
553
- });
554
- }
555
- })]
556
- });
557
- }
558
- }), /*#__PURE__*/_jsx("div", {
559
- className: `${baseClassName}__tab-panel`,
560
- role: "tabpanel",
561
- children: Children.map(children, (tab, index) => index + 1 === this.state.active ? tab : null)
94
+ return /*#__PURE__*/_jsxs("div", {
95
+ className: classNames(baseClassName, className),
96
+ ...props,
97
+ children: [compact && addonElement && /*#__PURE__*/_jsx("div", {
98
+ className: `${baseClassName}__addon ${baseClassName}__addon--compact`,
99
+ children: addonElement
100
+ }), /*#__PURE__*/_jsxs("div", {
101
+ className: classNames(`${baseClassName}__nav`, compact && `${baseClassName}__nav--compact`, searching && `${baseClassName}__nav--searching`, search && `${baseClassName}__nav--search`),
102
+ ref: tabNavRef,
103
+ children: [/*#__PURE__*/_jsx(TabList, {
104
+ tabListRef: tabListRef,
105
+ active: active,
106
+ onTabClick: handleTabClick,
107
+ visibleLength: visibleLength,
108
+ monospacedWidth: monospacedWidth,
109
+ baseClassName: baseClassName,
110
+ children: children
111
+ }), compact && renderSearchBar(), !compact && (addonElement || search) && /*#__PURE__*/_jsxs("div", {
112
+ className: `${baseClassName}__addon`,
113
+ style: addonStyle,
114
+ children: [renderSearchBar(), addonElement]
115
+ }), /*#__PURE__*/_jsx(FakeTabs, {
116
+ onResize: recalculateWidths,
117
+ baseClassName: baseClassName,
118
+ children: children
119
+ }), addonElement && /*#__PURE__*/_jsx("div", {
120
+ ref: fakeAddonRef,
121
+ className: `${baseClassName}__addon-fake-wrapper`,
122
+ "aria-hidden": true,
123
+ children: addonElement
562
124
  })]
563
- });
564
- }
565
- }
566
- _defineProperty(Tabs, "defaultProps", {
567
- baseClassName: `${CLS_PREFIX}tabs`
568
- });
125
+ }), /*#__PURE__*/_jsx("div", {
126
+ className: `${baseClassName}__tab-panel`,
127
+ role: "tabpanel",
128
+ children: Children.map(children, (tab, index) => index + 1 === active ? tab : null)
129
+ })]
130
+ });
131
+ };
569
132
  export default Tabs;
@@ -0,0 +1,12 @@
1
+ // Copyright 1999-2025. WebPros International GmbH. All rights reserved.
2
+
3
+ import { useState } from 'react';
4
+ export const useActive = externalActive => {
5
+ const [active, setActive] = useState(externalActive || 1);
6
+ const [prevExternalActive, setPrevExternalActive] = useState(externalActive);
7
+ if (externalActive && externalActive !== prevExternalActive) {
8
+ setPrevExternalActive(externalActive);
9
+ setActive(externalActive);
10
+ }
11
+ return [active, setActive];
12
+ };