wex-ui-lib 1.4.1 → 1.4.2

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.
package/dist/index.cjs.js CHANGED
@@ -2556,29 +2556,37 @@ var ItemContent = newStyled.div(templateObject_5$1 || (templateObject_5$1 = __ma
2556
2556
  var templateObject_1$1, templateObject_2$1, templateObject_3$1, templateObject_4$1, templateObject_5$1;
2557
2557
 
2558
2558
  var Tabs = function (_a) {
2559
- var tabs = _a.tabs, font = _a.font, _b = _a.displayMode, displayMode = _b === undefined ? "dark" : _b, accentColor = _a.accentColor, tabPadding = _a.tabPadding, onTabChange = _a.onTabChange;
2560
- var _c = React.useState(0), activeTab = _c[0], setActiveTab = _c[1];
2561
- var _d = React.useState({ left: 0, width: 0 }), indicatorStyle = _d[0], setIndicatorStyle = _d[1];
2559
+ var _b, _c;
2560
+ var tabs = _a.tabs, font = _a.font, _d = _a.displayMode, displayMode = _d === undefined ? "dark" : _d, accentColor = _a.accentColor, tabPadding = _a.tabPadding, onTabChange = _a.onTabChange, activeTabId = _a.activeTabId;
2561
+ var _e = React.useState((_b = tabs[0]) === null || _b === undefined ? undefined : _b.id), internalActiveTabId = _e[0], setInternalActiveTabId = _e[1];
2562
+ var isControlled = activeTabId !== undefined;
2563
+ var activeTab = isControlled ? activeTabId : internalActiveTabId;
2564
+ var _f = React.useState({ left: 0, width: 0 }), indicatorStyle = _f[0], setIndicatorStyle = _f[1];
2562
2565
  var tabRefs = React.useRef([]);
2563
2566
  React.useEffect(function () {
2564
- onTabChange && onTabChange(tabs[activeTab].id || tabs[activeTab].label);
2565
- var updateIndicator = function (index) {
2566
- var tab = tabRefs.current[index];
2567
- if (tab) {
2568
- setIndicatorStyle({ left: tab.offsetLeft, width: tab.offsetWidth });
2567
+ onTabChange && onTabChange(activeTab);
2568
+ var updateIndicator = function () {
2569
+ var index = tabs.findIndex(function (tab) { return tab.id === activeTab; });
2570
+ if (index !== -1) {
2571
+ var tab = tabRefs.current[index];
2572
+ if (tab) {
2573
+ setIndicatorStyle({ left: tab.offsetLeft, width: tab.offsetWidth });
2574
+ }
2569
2575
  }
2570
2576
  };
2571
- updateIndicator(activeTab);
2577
+ updateIndicator();
2572
2578
  }, [activeTab]);
2579
+ var handleTabClick = function (id) {
2580
+ if (!isControlled) {
2581
+ setInternalActiveTabId(id);
2582
+ }
2583
+ onTabChange === null || onTabChange === undefined ? undefined : onTabChange(id);
2584
+ };
2573
2585
  return (React.createElement(TabsContainer, null,
2574
2586
  React.createElement(TabsList, null,
2575
- tabs.map(function (tab, index) { return (React.createElement(Tab
2576
- // @ts-ignore
2577
- , {
2578
- // @ts-ignore
2579
- ref: function (el) { return (tabRefs.current[index] = el); }, key: index, active: activeTab === index, onClick: function () { return setActiveTab(index); }, font: font, accentColor: accentColor, displayMode: displayMode, tabPadding: tabPadding }, (font === null || font === undefined ? undefined : font.casing) ? formatText(tab.label, font.casing) : tab.label)); }),
2587
+ tabs.map(function (tab, index) { return (React.createElement(Tab, { ref: function (el) { tabRefs.current[index] = el; }, key: tab.id, active: activeTab === tab.id, onClick: function () { return handleTabClick(tab.id); }, font: font, accentColor: accentColor, displayMode: displayMode, tabPadding: tabPadding }, (font === null || font === undefined ? undefined : font.casing) ? formatText(tab.label, font.casing) : tab.label)); }),
2580
2588
  React.createElement(ActiveIndicator, { accentColor: accentColor, left: indicatorStyle.left, width: indicatorStyle.width })),
2581
- React.createElement(TabPanel, null, tabs[activeTab].content)));
2589
+ React.createElement(TabPanel, null, (_c = tabs.find(function (tab) { return tab.id === activeTab; })) === null || _c === undefined ? undefined : _c.content)));
2582
2590
  };
2583
2591
  var TabsContainer = newStyled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100%;\n position: relative;\n"], ["\n width: 100%;\n position: relative;\n"])));
2584
2592
  var TabsList = newStyled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n justify-content: center;\n position: relative;\n"], ["\n display: flex;\n justify-content: center;\n position: relative;\n"])));