react-better-html 1.1.261 → 1.1.262
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.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +23 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -519,12 +519,12 @@ type TabsProps = {
|
|
|
519
519
|
style?: "default" | "borderRadiusTop" | "box";
|
|
520
520
|
gap?: number;
|
|
521
521
|
noBottomLine?: boolean;
|
|
522
|
-
onChange?: (tab: Tab) => void;
|
|
522
|
+
onChange?: (tab: Tab["id"]) => void;
|
|
523
523
|
children?: React.ReactNode;
|
|
524
524
|
} & ComponentMarginProps;
|
|
525
525
|
type TabsRef = {
|
|
526
526
|
selectedTab: Tab["id"];
|
|
527
|
-
selectTab: (
|
|
527
|
+
selectTab: (tabId: Tab["id"]) => void;
|
|
528
528
|
};
|
|
529
529
|
type TabsComponent = {
|
|
530
530
|
(props: ComponentPropWithRef<TabsRef, TabsProps>): React.ReactElement;
|
package/dist/index.d.ts
CHANGED
|
@@ -519,12 +519,12 @@ type TabsProps = {
|
|
|
519
519
|
style?: "default" | "borderRadiusTop" | "box";
|
|
520
520
|
gap?: number;
|
|
521
521
|
noBottomLine?: boolean;
|
|
522
|
-
onChange?: (tab: Tab) => void;
|
|
522
|
+
onChange?: (tab: Tab["id"]) => void;
|
|
523
523
|
children?: React.ReactNode;
|
|
524
524
|
} & ComponentMarginProps;
|
|
525
525
|
type TabsRef = {
|
|
526
526
|
selectedTab: Tab["id"];
|
|
527
|
-
selectTab: (
|
|
527
|
+
selectTab: (tabId: Tab["id"]) => void;
|
|
528
528
|
};
|
|
529
529
|
type TabsComponent = {
|
|
530
530
|
(props: ComponentPropWithRef<TabsRef, TabsProps>): React.ReactElement;
|
package/dist/index.js
CHANGED
|
@@ -7503,41 +7503,41 @@ var TabsComponent = (0, import_react29.forwardRef)(function Tabs({ tabs, name, a
|
|
|
7503
7503
|
const firstRenderPassedRef = (0, import_react29.useRef)(false);
|
|
7504
7504
|
const tabsRef = (0, import_react29.useRef)({});
|
|
7505
7505
|
const tabsGap = gap ?? (style === "box" ? theme2.styles.gap / 2 : 0);
|
|
7506
|
-
const [
|
|
7507
|
-
const
|
|
7506
|
+
const [selectedTabId, setSelectedTabId] = (0, import_react29.useState)(() => {
|
|
7507
|
+
const selectedTabId2 = tabs[0];
|
|
7508
7508
|
if (urlQuery) {
|
|
7509
7509
|
const tabQueryValue = urlQuery.getQuery(name ?? defaultTabName);
|
|
7510
|
-
if (!tabQueryValue) return
|
|
7510
|
+
if (!tabQueryValue) return selectedTabId2.id;
|
|
7511
7511
|
const queryTab = tabs.find((tab) => tab.id === tabQueryValue);
|
|
7512
|
-
if (queryTab) return queryTab;
|
|
7512
|
+
if (queryTab) return queryTab.id;
|
|
7513
7513
|
}
|
|
7514
|
-
return
|
|
7514
|
+
return selectedTabId2.id;
|
|
7515
7515
|
});
|
|
7516
7516
|
const [rerenderState, setRerenderState] = (0, import_react29.useState)(0);
|
|
7517
7517
|
const onClickTab = (0, import_react29.useCallback)(
|
|
7518
|
-
(
|
|
7519
|
-
|
|
7520
|
-
onChange?.(
|
|
7518
|
+
(tabId) => {
|
|
7519
|
+
setSelectedTabId(tabId);
|
|
7520
|
+
onChange?.(tabId);
|
|
7521
7521
|
if (urlQuery) {
|
|
7522
7522
|
urlQuery.setQuery({
|
|
7523
|
-
[name ?? defaultTabName]:
|
|
7523
|
+
[name ?? defaultTabName]: tabId
|
|
7524
7524
|
});
|
|
7525
7525
|
}
|
|
7526
7526
|
},
|
|
7527
7527
|
[onChange, name, urlQuery]
|
|
7528
7528
|
);
|
|
7529
7529
|
const width = (0, import_react29.useMemo)(
|
|
7530
|
-
() => tabsRef.current[
|
|
7531
|
-
[rerenderState,
|
|
7530
|
+
() => tabsRef.current[selectedTabId]?.getBoundingClientRect().width ?? 0,
|
|
7531
|
+
[rerenderState, selectedTabId]
|
|
7532
7532
|
);
|
|
7533
7533
|
const leftSpacing = (0, import_react29.useMemo)(() => {
|
|
7534
|
-
const selectedTabIndex = tabs.findIndex((tab) => tab.id ===
|
|
7534
|
+
const selectedTabIndex = tabs.findIndex((tab) => tab.id === selectedTabId);
|
|
7535
7535
|
let spacing = 0;
|
|
7536
7536
|
Object.values(tabsRef.current).forEach((tab, index) => {
|
|
7537
7537
|
if (index < selectedTabIndex) spacing += (tab?.getBoundingClientRect().width ?? 0) + tabsGap;
|
|
7538
7538
|
});
|
|
7539
7539
|
return spacing;
|
|
7540
|
-
}, [
|
|
7540
|
+
}, [selectedTabId, tabs, tabsGap]);
|
|
7541
7541
|
(0, import_react29.useEffect)(() => {
|
|
7542
7542
|
const timeout = setTimeout(() => {
|
|
7543
7543
|
setRerenderState(Math.random());
|
|
@@ -7554,7 +7554,7 @@ var TabsComponent = (0, import_react29.forwardRef)(function Tabs({ tabs, name, a
|
|
|
7554
7554
|
return oldValue.map(
|
|
7555
7555
|
(item) => item.name === (name ?? defaultTabName) ? {
|
|
7556
7556
|
...item,
|
|
7557
|
-
selectedTab:
|
|
7557
|
+
selectedTab: selectedTabId
|
|
7558
7558
|
} : item
|
|
7559
7559
|
);
|
|
7560
7560
|
} else {
|
|
@@ -7562,18 +7562,18 @@ var TabsComponent = (0, import_react29.forwardRef)(function Tabs({ tabs, name, a
|
|
|
7562
7562
|
...oldValue,
|
|
7563
7563
|
{
|
|
7564
7564
|
name: name ?? defaultTabName,
|
|
7565
|
-
selectedTab:
|
|
7565
|
+
selectedTab: selectedTabId
|
|
7566
7566
|
}
|
|
7567
7567
|
];
|
|
7568
7568
|
}
|
|
7569
7569
|
});
|
|
7570
|
-
}, [
|
|
7570
|
+
}, [selectedTabId, name]);
|
|
7571
7571
|
(0, import_react29.useEffect)(() => {
|
|
7572
|
-
tabsRef.current[
|
|
7572
|
+
tabsRef.current[selectedTabId]?.scrollIntoView({
|
|
7573
7573
|
behavior: firstRenderPassedRef.current ? "smooth" : void 0,
|
|
7574
7574
|
block: "nearest"
|
|
7575
7575
|
});
|
|
7576
|
-
}, [
|
|
7576
|
+
}, [selectedTabId]);
|
|
7577
7577
|
(0, import_react29.useEffect)(() => {
|
|
7578
7578
|
return () => {
|
|
7579
7579
|
componentsState.tabs.setTabGroups(
|
|
@@ -7582,18 +7582,18 @@ var TabsComponent = (0, import_react29.forwardRef)(function Tabs({ tabs, name, a
|
|
|
7582
7582
|
};
|
|
7583
7583
|
}, []);
|
|
7584
7584
|
(0, import_react29.useEffect)(() => {
|
|
7585
|
-
onChange?.(
|
|
7585
|
+
onChange?.(selectedTabId);
|
|
7586
7586
|
}, []);
|
|
7587
7587
|
(0, import_react29.useImperativeHandle)(ref, () => {
|
|
7588
7588
|
return {
|
|
7589
|
-
selectedTab:
|
|
7589
|
+
selectedTab: selectedTabId,
|
|
7590
7590
|
selectTab: onClickTab
|
|
7591
7591
|
};
|
|
7592
|
-
}, [
|
|
7592
|
+
}, [selectedTabId, onClickTab]);
|
|
7593
7593
|
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(Div_default.column, { width: "100%", gap: theme2.styles.space, ...props, children: [
|
|
7594
7594
|
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(Div_default, { position: "relative", className: "react-better-html-no-scrollbar", overflowY: "auto", children: [
|
|
7595
7595
|
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Div_default.row, { position: "relative", width: "fit-content", gap: tabsGap, userSelect: "none", children: tabs.map((tab) => {
|
|
7596
|
-
const selected = tab.id ===
|
|
7596
|
+
const selected = tab.id === selectedTabId;
|
|
7597
7597
|
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
|
|
7598
7598
|
Div_default,
|
|
7599
7599
|
{
|
|
@@ -7608,7 +7608,7 @@ var TabsComponent = (0, import_react29.forwardRef)(function Tabs({ tabs, name, a
|
|
|
7608
7608
|
filterHover: colorTheme === "dark" ? style === "box" ? "brightness(1.2)" : "brightness(2)" : "brightness(0.9)",
|
|
7609
7609
|
paddingInline: theme2.styles.space,
|
|
7610
7610
|
paddingBlock: theme2.styles.gap,
|
|
7611
|
-
value: tab,
|
|
7611
|
+
value: tab.id,
|
|
7612
7612
|
cursor: "pointer",
|
|
7613
7613
|
isTabAccessed: true,
|
|
7614
7614
|
onClickWithValue: onClickTab,
|