react-better-html 1.1.80 → 1.1.82
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 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +59 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -649,6 +649,7 @@ type TabsContentProps = {
|
|
|
649
649
|
tab: string;
|
|
650
650
|
tabWithDot?: boolean;
|
|
651
651
|
tabsGroupName?: string;
|
|
652
|
+
isInitialTab?: boolean;
|
|
652
653
|
children?: React.ReactNode;
|
|
653
654
|
};
|
|
654
655
|
declare const Tabs: typeof TabsComponent & {
|
|
@@ -662,6 +663,7 @@ type FoldableProps = {
|
|
|
662
663
|
description?: string;
|
|
663
664
|
icon?: IconName | AnyOtherString;
|
|
664
665
|
image?: AssetName | AnyOtherString;
|
|
666
|
+
headerPaddingBlock?: React.CSSProperties["paddingBlock"];
|
|
665
667
|
headerPaddingInline?: React.CSSProperties["paddingInline"];
|
|
666
668
|
renderHeader?: (isOpen: boolean, toggleOpen: () => void) => React.ReactNode;
|
|
667
669
|
onOpenChange?: (isOpen: boolean) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -649,6 +649,7 @@ type TabsContentProps = {
|
|
|
649
649
|
tab: string;
|
|
650
650
|
tabWithDot?: boolean;
|
|
651
651
|
tabsGroupName?: string;
|
|
652
|
+
isInitialTab?: boolean;
|
|
652
653
|
children?: React.ReactNode;
|
|
653
654
|
};
|
|
654
655
|
declare const Tabs: typeof TabsComponent & {
|
|
@@ -662,6 +663,7 @@ type FoldableProps = {
|
|
|
662
663
|
description?: string;
|
|
663
664
|
icon?: IconName | AnyOtherString;
|
|
664
665
|
image?: AssetName | AnyOtherString;
|
|
666
|
+
headerPaddingBlock?: React.CSSProperties["paddingBlock"];
|
|
665
667
|
headerPaddingInline?: React.CSSProperties["paddingInline"];
|
|
666
668
|
renderHeader?: (isOpen: boolean, toggleOpen: () => void) => React.ReactNode;
|
|
667
669
|
onOpenChange?: (isOpen: boolean) => void;
|
package/dist/index.js
CHANGED
|
@@ -1546,6 +1546,10 @@ var appConfig = {
|
|
|
1546
1546
|
// src/components/BetterHtmlProvider.tsx
|
|
1547
1547
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1548
1548
|
var GlobalStyle = import_styled_components.createGlobalStyle`
|
|
1549
|
+
html {
|
|
1550
|
+
background-color: ${(props) => props.backgroundColor};
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1549
1553
|
body {
|
|
1550
1554
|
font-family: ${(props) => props.fontFamily};
|
|
1551
1555
|
color: ${(props) => props.color};
|
|
@@ -1576,7 +1580,7 @@ var useBetterHtmlContext = () => {
|
|
|
1576
1580
|
throw new Error(
|
|
1577
1581
|
"`useBetterHtmlContext()` must be used within a `<BetterHtmlProvider>`. Make sure to add one at the root of your component tree."
|
|
1578
1582
|
);
|
|
1579
|
-
const { setLoaders, plugins,
|
|
1583
|
+
const { setLoaders, plugins, componentsState, ...rest } = context;
|
|
1580
1584
|
return rest;
|
|
1581
1585
|
};
|
|
1582
1586
|
var useBetterHtmlContextInternal = () => {
|
|
@@ -1697,11 +1701,13 @@ function BetterHtmlProvider({ value, plugins: pluginsToUse, children }) {
|
|
|
1697
1701
|
...value?.components
|
|
1698
1702
|
},
|
|
1699
1703
|
plugins,
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1704
|
+
componentsState: {
|
|
1705
|
+
tabs: {
|
|
1706
|
+
tabGroups,
|
|
1707
|
+
setTabGroups,
|
|
1708
|
+
tabsWithDots,
|
|
1709
|
+
setTabsWithDots
|
|
1710
|
+
}
|
|
1705
1711
|
}
|
|
1706
1712
|
}),
|
|
1707
1713
|
[value, colorTheme, loaders, plugins, tabGroups, tabsWithDots]
|
|
@@ -6605,7 +6611,8 @@ var TabsComponent = function Tabs({
|
|
|
6605
6611
|
const reactRouterDomPlugin2 = usePlugin("react-router-dom");
|
|
6606
6612
|
const theme2 = useTheme();
|
|
6607
6613
|
const urlQuery = reactRouterDomPlugin2 ? useUrlQuery() : void 0;
|
|
6608
|
-
const { colorTheme,
|
|
6614
|
+
const { colorTheme, componentsState } = useBetterHtmlContextInternal();
|
|
6615
|
+
const firstRenderPassedRef = (0, import_react24.useRef)(false);
|
|
6609
6616
|
const tabsRef = (0, import_react24.useRef)({});
|
|
6610
6617
|
const [selectedTab, setSelectedTab] = (0, import_react24.useState)(() => {
|
|
6611
6618
|
const selectedTabValue = tabs[0] ?? "";
|
|
@@ -6635,20 +6642,23 @@ var TabsComponent = function Tabs({
|
|
|
6635
6642
|
);
|
|
6636
6643
|
const leftSpacing = (0, import_react24.useMemo)(() => {
|
|
6637
6644
|
const selectedTabIndex = tabs.findIndex((tab) => tab === selectedTab);
|
|
6638
|
-
let
|
|
6645
|
+
let spacing = 0;
|
|
6639
6646
|
Object.values(tabsRef.current).forEach((tab, index) => {
|
|
6640
|
-
if (index < selectedTabIndex)
|
|
6647
|
+
if (index < selectedTabIndex) spacing += (tab?.getBoundingClientRect().width ?? 0) + tabsGap;
|
|
6641
6648
|
});
|
|
6642
|
-
return
|
|
6649
|
+
return spacing;
|
|
6643
6650
|
}, [selectedTab, tabs, tabsGap]);
|
|
6644
6651
|
(0, import_react24.useEffect)(() => {
|
|
6645
|
-
const timeout = setTimeout(() =>
|
|
6652
|
+
const timeout = setTimeout(() => {
|
|
6653
|
+
setRerenderState(Math.random());
|
|
6654
|
+
firstRenderPassedRef.current = true;
|
|
6655
|
+
}, 0.01 * 1e3);
|
|
6646
6656
|
return () => {
|
|
6647
6657
|
clearTimeout(timeout);
|
|
6648
6658
|
};
|
|
6649
6659
|
}, []);
|
|
6650
6660
|
(0, import_react24.useEffect)(() => {
|
|
6651
|
-
|
|
6661
|
+
componentsState.tabs.setTabGroups((oldValue) => {
|
|
6652
6662
|
const thisTabGroup = oldValue.find((item) => item.name === (name ?? defaultTabName));
|
|
6653
6663
|
if (thisTabGroup) {
|
|
6654
6664
|
return oldValue.map(
|
|
@@ -6668,6 +6678,12 @@ var TabsComponent = function Tabs({
|
|
|
6668
6678
|
}
|
|
6669
6679
|
});
|
|
6670
6680
|
}, [selectedTab, name]);
|
|
6681
|
+
(0, import_react24.useEffect)(() => {
|
|
6682
|
+
tabsRef.current[selectedTab]?.scrollIntoView({
|
|
6683
|
+
behavior: firstRenderPassedRef.current ? "smooth" : void 0,
|
|
6684
|
+
block: "nearest"
|
|
6685
|
+
});
|
|
6686
|
+
}, [selectedTab]);
|
|
6671
6687
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(Div_default.column, { width: "100%", gap: theme2.styles.space, ...props, children: [
|
|
6672
6688
|
/* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(Div_default, { position: "relative", className: "react-better-html-no-scrollbar", overflowY: "auto", children: [
|
|
6673
6689
|
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Div_default.row, { position: "relative", width: "fit-content", gap: tabsGap, userSelect: "none", children: tabs.map((tab) => {
|
|
@@ -6693,7 +6709,7 @@ var TabsComponent = function Tabs({
|
|
|
6693
6709
|
tabsRef.current[tab] = ref;
|
|
6694
6710
|
},
|
|
6695
6711
|
children: [
|
|
6696
|
-
|
|
6712
|
+
componentsState.tabs.tabsWithDots.includes(tab) && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
6697
6713
|
Div_default,
|
|
6698
6714
|
{
|
|
6699
6715
|
position: "absolute",
|
|
@@ -6730,29 +6746,29 @@ var TabsComponent = function Tabs({
|
|
|
6730
6746
|
bottom: 0,
|
|
6731
6747
|
left: leftSpacing,
|
|
6732
6748
|
backgroundColor: accentColor ?? theme2.colors.primary,
|
|
6733
|
-
transition: theme2.styles.transition
|
|
6749
|
+
transition: firstRenderPassedRef.current ? theme2.styles.transition : "none"
|
|
6734
6750
|
}
|
|
6735
6751
|
)
|
|
6736
6752
|
] }),
|
|
6737
6753
|
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Div_default, { width: "100%", children })
|
|
6738
6754
|
] });
|
|
6739
6755
|
};
|
|
6740
|
-
TabsComponent.content = function Content({ tab, tabWithDot, tabsGroupName, children }) {
|
|
6741
|
-
const {
|
|
6756
|
+
TabsComponent.content = function Content({ tab, tabWithDot, tabsGroupName, isInitialTab, children }) {
|
|
6757
|
+
const { componentsState } = useBetterHtmlContextInternal();
|
|
6742
6758
|
const thisTabGroupData = (0, import_react24.useMemo)(
|
|
6743
|
-
() =>
|
|
6744
|
-
[
|
|
6759
|
+
() => componentsState.tabs.tabGroups.find((item) => item.name === (tabsGroupName ?? defaultTabName)),
|
|
6760
|
+
[componentsState.tabs, tabsGroupName]
|
|
6745
6761
|
);
|
|
6746
6762
|
(0, import_react24.useEffect)(() => {
|
|
6747
6763
|
if (tabWithDot) {
|
|
6748
|
-
|
|
6764
|
+
componentsState.tabs.setTabsWithDots?.((oldValue) => oldValue.includes(tab) ? oldValue : [...oldValue, tab]);
|
|
6749
6765
|
} else {
|
|
6750
|
-
|
|
6766
|
+
componentsState.tabs.setTabsWithDots?.(
|
|
6751
6767
|
(oldValue) => oldValue.includes(tab) ? oldValue.filter((tab2) => tab2 !== tab2) : oldValue
|
|
6752
6768
|
);
|
|
6753
6769
|
}
|
|
6754
6770
|
}, [tabWithDot]);
|
|
6755
|
-
return thisTabGroupData
|
|
6771
|
+
return (thisTabGroupData ? thisTabGroupData.selectedTab === tab : isInitialTab) ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Div_default, { width: "100%", children }) : void 0;
|
|
6756
6772
|
};
|
|
6757
6773
|
var Tabs2 = (0, import_react24.memo)(TabsComponent);
|
|
6758
6774
|
Tabs2.content = TabsComponent.content;
|
|
@@ -6761,7 +6777,8 @@ var Tabs_default = Tabs2;
|
|
|
6761
6777
|
// src/components/Foldable.tsx
|
|
6762
6778
|
var import_react25 = require("react");
|
|
6763
6779
|
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
6764
|
-
var
|
|
6780
|
+
var animationDurationClose = 0.15;
|
|
6781
|
+
var animationDurationOpen = animationDurationClose * 2;
|
|
6765
6782
|
var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
|
|
6766
6783
|
isOpen: controlledIsOpen,
|
|
6767
6784
|
defaultOpen = false,
|
|
@@ -6769,6 +6786,7 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
|
|
|
6769
6786
|
description,
|
|
6770
6787
|
icon,
|
|
6771
6788
|
image,
|
|
6789
|
+
headerPaddingBlock,
|
|
6772
6790
|
headerPaddingInline,
|
|
6773
6791
|
renderHeader,
|
|
6774
6792
|
onOpenChange,
|
|
@@ -6778,7 +6796,7 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
|
|
|
6778
6796
|
const theme2 = useTheme();
|
|
6779
6797
|
const bodyRef = (0, import_react25.useRef)(null);
|
|
6780
6798
|
const [internalIsOpen, setInternalIsOpen] = useBooleanState(defaultOpen);
|
|
6781
|
-
const [
|
|
6799
|
+
const [bodyVirtualHeight, setBodyVirtualHeight] = (0, import_react25.useState)(500);
|
|
6782
6800
|
const isOpen = controlledIsOpen !== void 0 ? controlledIsOpen : internalIsOpen;
|
|
6783
6801
|
const open = (0, import_react25.useCallback)(() => {
|
|
6784
6802
|
if (controlledIsOpen === void 0) setInternalIsOpen.setTrue();
|
|
@@ -6794,29 +6812,8 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
|
|
|
6794
6812
|
}, [controlledIsOpen, isOpen, onOpenChange]);
|
|
6795
6813
|
(0, import_react25.useEffect)(() => {
|
|
6796
6814
|
if (!bodyRef.current) return;
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
setBodyHeight(height);
|
|
6800
|
-
const timeout = setTimeout(() => {
|
|
6801
|
-
setBodyHeight(void 0);
|
|
6802
|
-
}, animationDuration * 1e3);
|
|
6803
|
-
return () => {
|
|
6804
|
-
clearTimeout(timeout);
|
|
6805
|
-
};
|
|
6806
|
-
} else {
|
|
6807
|
-
if (bodyHeight === void 0) {
|
|
6808
|
-
const height = bodyRef.current.scrollHeight;
|
|
6809
|
-
setBodyHeight(height);
|
|
6810
|
-
bodyRef.current.offsetHeight;
|
|
6811
|
-
}
|
|
6812
|
-
const timeout = setTimeout(() => {
|
|
6813
|
-
setBodyHeight(0);
|
|
6814
|
-
}, 0.01 * 1e3);
|
|
6815
|
-
return () => {
|
|
6816
|
-
clearTimeout(timeout);
|
|
6817
|
-
};
|
|
6818
|
-
}
|
|
6819
|
-
}, [isOpen, animationDuration, bodyHeight]);
|
|
6815
|
+
setBodyVirtualHeight(Math.min(500, bodyRef.current.scrollHeight * 2));
|
|
6816
|
+
}, [isOpen]);
|
|
6820
6817
|
(0, import_react25.useImperativeHandle)(
|
|
6821
6818
|
ref,
|
|
6822
6819
|
() => {
|
|
@@ -6829,14 +6826,14 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
|
|
|
6829
6826
|
},
|
|
6830
6827
|
[open, close, toggleOpen, isOpen]
|
|
6831
6828
|
);
|
|
6832
|
-
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Div_default.column, { width: "100%",
|
|
6829
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Div_default.column, { width: "100%", ...props, children: [
|
|
6833
6830
|
renderHeader ? renderHeader(isOpen, toggleOpen) : /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
|
|
6834
6831
|
Div_default.row,
|
|
6835
6832
|
{
|
|
6836
6833
|
width: "100%",
|
|
6837
6834
|
alignItems: "center",
|
|
6838
6835
|
gap: theme2.styles.gap,
|
|
6839
|
-
paddingBlock: theme2.styles.gap,
|
|
6836
|
+
paddingBlock: headerPaddingBlock ?? theme2.styles.gap,
|
|
6840
6837
|
paddingInline: headerPaddingInline,
|
|
6841
6838
|
cursor: "pointer",
|
|
6842
6839
|
onClick: toggleOpen,
|
|
@@ -6846,7 +6843,7 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
|
|
|
6846
6843
|
icon && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Icon_default, { name: icon, size: 20, flexShrink: 0 }),
|
|
6847
6844
|
image && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Image_default.profileImage, { name: image, size: 24, flexShrink: 0 }),
|
|
6848
6845
|
/* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Div_default.column, { gap: theme2.styles.gap / 2, children: [
|
|
6849
|
-
title && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Text_default, { as: "h3", fontWeight: 700, children: title }),
|
|
6846
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Text_default, { as: "h3", fontWeight: 700, lineHeight: "20px", children: title }),
|
|
6850
6847
|
description && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Text_default, { color: theme2.colors.textSecondary, children: description })
|
|
6851
6848
|
] })
|
|
6852
6849
|
] }),
|
|
@@ -6862,7 +6859,18 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
|
|
|
6862
6859
|
}
|
|
6863
6860
|
),
|
|
6864
6861
|
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Div_default, { height: isOpen ? 1 : 0, opacity: isOpen ? 1 : 0, transition: theme2.styles.transition, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Divider_default.horizontal, {}) }),
|
|
6865
|
-
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
6862
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
6863
|
+
Div_default,
|
|
6864
|
+
{
|
|
6865
|
+
maxHeight: isOpen ? bodyVirtualHeight : 0,
|
|
6866
|
+
opacity: !isOpen ? 0 : void 0,
|
|
6867
|
+
transition: `max-height ${isOpen ? animationDurationOpen : animationDurationClose}s ease, opacity ${theme2.styles.transition}`,
|
|
6868
|
+
overflow: !isOpen ? "hidden" : void 0,
|
|
6869
|
+
pointerEvents: !isOpen ? "none" : void 0,
|
|
6870
|
+
ref: bodyRef,
|
|
6871
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Div_default, { paddingBlock: theme2.styles.gap, paddingInline: headerPaddingInline, children })
|
|
6872
|
+
}
|
|
6873
|
+
)
|
|
6866
6874
|
] });
|
|
6867
6875
|
});
|
|
6868
6876
|
FoldableComponent.box = (0, import_react25.forwardRef)(function Box3({ ...props }, ref) {
|
|
@@ -6873,6 +6881,7 @@ FoldableComponent.box = (0, import_react25.forwardRef)(function Box3({ ...props
|
|
|
6873
6881
|
backgroundColor: theme2.colors.backgroundContent,
|
|
6874
6882
|
border: `1px solid ${theme2.colors.border}`,
|
|
6875
6883
|
borderRadius: theme2.styles.borderRadius,
|
|
6884
|
+
headerPaddingBlock: (theme2.styles.gap + theme2.styles.space) / 2,
|
|
6876
6885
|
headerPaddingInline: theme2.styles.space,
|
|
6877
6886
|
...props,
|
|
6878
6887
|
ref
|