react-better-html 1.1.80 → 1.1.81

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.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, tabsComponentState, ...rest } = context;
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
- tabsComponentState: {
1701
- tabGroups,
1702
- setTabGroups,
1703
- tabsWithDots,
1704
- setTabsWithDots
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, tabsComponentState } = useBetterHtmlContextInternal();
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 totalWidth = 0;
6645
+ let spacing = 0;
6639
6646
  Object.values(tabsRef.current).forEach((tab, index) => {
6640
- if (index < selectedTabIndex) totalWidth += (tab?.getBoundingClientRect().width ?? 0) + tabsGap;
6647
+ if (index < selectedTabIndex) spacing += (tab?.getBoundingClientRect().width ?? 0) + tabsGap;
6641
6648
  });
6642
- return totalWidth;
6649
+ return spacing;
6643
6650
  }, [selectedTab, tabs, tabsGap]);
6644
6651
  (0, import_react24.useEffect)(() => {
6645
- const timeout = setTimeout(() => setRerenderState(Math.random()), 0.01 * 1e3);
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
- tabsComponentState.setTabGroups((oldValue) => {
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
- tabsComponentState.tabsWithDots.includes(tab) && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
6712
+ componentsState.tabs.tabsWithDots.includes(tab) && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
6697
6713
  Div_default,
6698
6714
  {
6699
6715
  position: "absolute",
@@ -6730,7 +6746,7 @@ 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
  ] }),
@@ -6738,16 +6754,16 @@ var TabsComponent = function Tabs({
6738
6754
  ] });
6739
6755
  };
6740
6756
  TabsComponent.content = function Content({ tab, tabWithDot, tabsGroupName, children }) {
6741
- const { tabsComponentState } = useBetterHtmlContextInternal();
6757
+ const { componentsState } = useBetterHtmlContextInternal();
6742
6758
  const thisTabGroupData = (0, import_react24.useMemo)(
6743
- () => tabsComponentState.tabGroups.find((item) => item.name === (tabsGroupName ?? defaultTabName)),
6744
- [tabsComponentState, tabsGroupName]
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
- tabsComponentState.setTabsWithDots?.((oldValue) => oldValue.includes(tab) ? oldValue : [...oldValue, tab]);
6764
+ componentsState.tabs.setTabsWithDots?.((oldValue) => oldValue.includes(tab) ? oldValue : [...oldValue, tab]);
6749
6765
  } else {
6750
- tabsComponentState.setTabsWithDots?.(
6766
+ componentsState.tabs.setTabsWithDots?.(
6751
6767
  (oldValue) => oldValue.includes(tab) ? oldValue.filter((tab2) => tab2 !== tab2) : oldValue
6752
6768
  );
6753
6769
  }
@@ -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 animationDuration = 0.2;
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,
@@ -6778,7 +6795,7 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
6778
6795
  const theme2 = useTheme();
6779
6796
  const bodyRef = (0, import_react25.useRef)(null);
6780
6797
  const [internalIsOpen, setInternalIsOpen] = useBooleanState(defaultOpen);
6781
- const [bodyHeight, setBodyHeight] = (0, import_react25.useState)(defaultOpen ? void 0 : 0);
6798
+ const [bodyVirtualHeight, setBodyVirtualHeight] = (0, import_react25.useState)(500);
6782
6799
  const isOpen = controlledIsOpen !== void 0 ? controlledIsOpen : internalIsOpen;
6783
6800
  const open = (0, import_react25.useCallback)(() => {
6784
6801
  if (controlledIsOpen === void 0) setInternalIsOpen.setTrue();
@@ -6794,29 +6811,8 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
6794
6811
  }, [controlledIsOpen, isOpen, onOpenChange]);
6795
6812
  (0, import_react25.useEffect)(() => {
6796
6813
  if (!bodyRef.current) return;
6797
- if (isOpen) {
6798
- const height = bodyRef.current.scrollHeight;
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]);
6814
+ setBodyVirtualHeight(Math.min(500, bodyRef.current.scrollHeight * 2));
6815
+ }, [isOpen]);
6820
6816
  (0, import_react25.useImperativeHandle)(
6821
6817
  ref,
6822
6818
  () => {
@@ -6829,7 +6825,7 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
6829
6825
  },
6830
6826
  [open, close, toggleOpen, isOpen]
6831
6827
  );
6832
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Div_default.column, { width: "100%", overflow: "hidden", ...props, children: [
6828
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Div_default.column, { width: "100%", ...props, children: [
6833
6829
  renderHeader ? renderHeader(isOpen, toggleOpen) : /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
6834
6830
  Div_default.row,
6835
6831
  {
@@ -6862,7 +6858,18 @@ var FoldableComponent = (0, import_react25.forwardRef)(function Foldable({
6862
6858
  }
6863
6859
  ),
6864
6860
  /* @__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)(Div_default, { height: bodyHeight, transition: `height ${animationDuration}s ease`, ref: bodyRef, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Div_default, { paddingBlock: theme2.styles.gap, paddingInline: headerPaddingInline, children }) })
6861
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
6862
+ Div_default,
6863
+ {
6864
+ maxHeight: isOpen ? bodyVirtualHeight : 0,
6865
+ opacity: !isOpen ? 0 : void 0,
6866
+ transition: `max-height ${isOpen ? animationDurationOpen : animationDurationClose}s ease, opacity ${theme2.styles.transition}`,
6867
+ overflow: !isOpen ? "hidden" : void 0,
6868
+ pointerEvents: !isOpen ? "none" : void 0,
6869
+ ref: bodyRef,
6870
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Div_default, { paddingBlock: theme2.styles.gap, paddingInline: headerPaddingInline, children })
6871
+ }
6872
+ )
6866
6873
  ] });
6867
6874
  });
6868
6875
  FoldableComponent.box = (0, import_react25.forwardRef)(function Box3({ ...props }, ref) {