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.mjs CHANGED
@@ -1471,6 +1471,10 @@ var appConfig = {
1471
1471
  // src/components/BetterHtmlProvider.tsx
1472
1472
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
1473
1473
  var GlobalStyle = createGlobalStyle`
1474
+ html {
1475
+ background-color: ${(props) => props.backgroundColor};
1476
+ }
1477
+
1474
1478
  body {
1475
1479
  font-family: ${(props) => props.fontFamily};
1476
1480
  color: ${(props) => props.color};
@@ -1501,7 +1505,7 @@ var useBetterHtmlContext = () => {
1501
1505
  throw new Error(
1502
1506
  "`useBetterHtmlContext()` must be used within a `<BetterHtmlProvider>`. Make sure to add one at the root of your component tree."
1503
1507
  );
1504
- const { setLoaders, plugins, tabsComponentState, ...rest } = context;
1508
+ const { setLoaders, plugins, componentsState, ...rest } = context;
1505
1509
  return rest;
1506
1510
  };
1507
1511
  var useBetterHtmlContextInternal = () => {
@@ -1622,11 +1626,13 @@ function BetterHtmlProvider({ value, plugins: pluginsToUse, children }) {
1622
1626
  ...value?.components
1623
1627
  },
1624
1628
  plugins,
1625
- tabsComponentState: {
1626
- tabGroups,
1627
- setTabGroups,
1628
- tabsWithDots,
1629
- setTabsWithDots
1629
+ componentsState: {
1630
+ tabs: {
1631
+ tabGroups,
1632
+ setTabGroups,
1633
+ tabsWithDots,
1634
+ setTabsWithDots
1635
+ }
1630
1636
  }
1631
1637
  }),
1632
1638
  [value, colorTheme, loaders, plugins, tabGroups, tabsWithDots]
@@ -6530,7 +6536,8 @@ var TabsComponent = function Tabs({
6530
6536
  const reactRouterDomPlugin2 = usePlugin("react-router-dom");
6531
6537
  const theme2 = useTheme();
6532
6538
  const urlQuery = reactRouterDomPlugin2 ? useUrlQuery() : void 0;
6533
- const { colorTheme, tabsComponentState } = useBetterHtmlContextInternal();
6539
+ const { colorTheme, componentsState } = useBetterHtmlContextInternal();
6540
+ const firstRenderPassedRef = useRef5(false);
6534
6541
  const tabsRef = useRef5({});
6535
6542
  const [selectedTab, setSelectedTab] = useState9(() => {
6536
6543
  const selectedTabValue = tabs[0] ?? "";
@@ -6560,20 +6567,23 @@ var TabsComponent = function Tabs({
6560
6567
  );
6561
6568
  const leftSpacing = useMemo8(() => {
6562
6569
  const selectedTabIndex = tabs.findIndex((tab) => tab === selectedTab);
6563
- let totalWidth = 0;
6570
+ let spacing = 0;
6564
6571
  Object.values(tabsRef.current).forEach((tab, index) => {
6565
- if (index < selectedTabIndex) totalWidth += (tab?.getBoundingClientRect().width ?? 0) + tabsGap;
6572
+ if (index < selectedTabIndex) spacing += (tab?.getBoundingClientRect().width ?? 0) + tabsGap;
6566
6573
  });
6567
- return totalWidth;
6574
+ return spacing;
6568
6575
  }, [selectedTab, tabs, tabsGap]);
6569
6576
  useEffect9(() => {
6570
- const timeout = setTimeout(() => setRerenderState(Math.random()), 0.01 * 1e3);
6577
+ const timeout = setTimeout(() => {
6578
+ setRerenderState(Math.random());
6579
+ firstRenderPassedRef.current = true;
6580
+ }, 0.01 * 1e3);
6571
6581
  return () => {
6572
6582
  clearTimeout(timeout);
6573
6583
  };
6574
6584
  }, []);
6575
6585
  useEffect9(() => {
6576
- tabsComponentState.setTabGroups((oldValue) => {
6586
+ componentsState.tabs.setTabGroups((oldValue) => {
6577
6587
  const thisTabGroup = oldValue.find((item) => item.name === (name ?? defaultTabName));
6578
6588
  if (thisTabGroup) {
6579
6589
  return oldValue.map(
@@ -6593,6 +6603,12 @@ var TabsComponent = function Tabs({
6593
6603
  }
6594
6604
  });
6595
6605
  }, [selectedTab, name]);
6606
+ useEffect9(() => {
6607
+ tabsRef.current[selectedTab]?.scrollIntoView({
6608
+ behavior: firstRenderPassedRef.current ? "smooth" : void 0,
6609
+ block: "nearest"
6610
+ });
6611
+ }, [selectedTab]);
6596
6612
  return /* @__PURE__ */ jsxs16(Div_default.column, { width: "100%", gap: theme2.styles.space, ...props, children: [
6597
6613
  /* @__PURE__ */ jsxs16(Div_default, { position: "relative", className: "react-better-html-no-scrollbar", overflowY: "auto", children: [
6598
6614
  /* @__PURE__ */ jsx21(Div_default.row, { position: "relative", width: "fit-content", gap: tabsGap, userSelect: "none", children: tabs.map((tab) => {
@@ -6618,7 +6634,7 @@ var TabsComponent = function Tabs({
6618
6634
  tabsRef.current[tab] = ref;
6619
6635
  },
6620
6636
  children: [
6621
- tabsComponentState.tabsWithDots.includes(tab) && /* @__PURE__ */ jsx21(
6637
+ componentsState.tabs.tabsWithDots.includes(tab) && /* @__PURE__ */ jsx21(
6622
6638
  Div_default,
6623
6639
  {
6624
6640
  position: "absolute",
@@ -6655,29 +6671,29 @@ var TabsComponent = function Tabs({
6655
6671
  bottom: 0,
6656
6672
  left: leftSpacing,
6657
6673
  backgroundColor: accentColor ?? theme2.colors.primary,
6658
- transition: theme2.styles.transition
6674
+ transition: firstRenderPassedRef.current ? theme2.styles.transition : "none"
6659
6675
  }
6660
6676
  )
6661
6677
  ] }),
6662
6678
  /* @__PURE__ */ jsx21(Div_default, { width: "100%", children })
6663
6679
  ] });
6664
6680
  };
6665
- TabsComponent.content = function Content({ tab, tabWithDot, tabsGroupName, children }) {
6666
- const { tabsComponentState } = useBetterHtmlContextInternal();
6681
+ TabsComponent.content = function Content({ tab, tabWithDot, tabsGroupName, isInitialTab, children }) {
6682
+ const { componentsState } = useBetterHtmlContextInternal();
6667
6683
  const thisTabGroupData = useMemo8(
6668
- () => tabsComponentState.tabGroups.find((item) => item.name === (tabsGroupName ?? defaultTabName)),
6669
- [tabsComponentState, tabsGroupName]
6684
+ () => componentsState.tabs.tabGroups.find((item) => item.name === (tabsGroupName ?? defaultTabName)),
6685
+ [componentsState.tabs, tabsGroupName]
6670
6686
  );
6671
6687
  useEffect9(() => {
6672
6688
  if (tabWithDot) {
6673
- tabsComponentState.setTabsWithDots?.((oldValue) => oldValue.includes(tab) ? oldValue : [...oldValue, tab]);
6689
+ componentsState.tabs.setTabsWithDots?.((oldValue) => oldValue.includes(tab) ? oldValue : [...oldValue, tab]);
6674
6690
  } else {
6675
- tabsComponentState.setTabsWithDots?.(
6691
+ componentsState.tabs.setTabsWithDots?.(
6676
6692
  (oldValue) => oldValue.includes(tab) ? oldValue.filter((tab2) => tab2 !== tab2) : oldValue
6677
6693
  );
6678
6694
  }
6679
6695
  }, [tabWithDot]);
6680
- return thisTabGroupData?.selectedTab === tab ? /* @__PURE__ */ jsx21(Div_default, { width: "100%", children }) : void 0;
6696
+ return (thisTabGroupData ? thisTabGroupData.selectedTab === tab : isInitialTab) ? /* @__PURE__ */ jsx21(Div_default, { width: "100%", children }) : void 0;
6681
6697
  };
6682
6698
  var Tabs2 = memo21(TabsComponent);
6683
6699
  Tabs2.content = TabsComponent.content;
@@ -6686,7 +6702,8 @@ var Tabs_default = Tabs2;
6686
6702
  // src/components/Foldable.tsx
6687
6703
  import { forwardRef as forwardRef12, memo as memo22, useCallback as useCallback12, useEffect as useEffect10, useImperativeHandle as useImperativeHandle2, useRef as useRef6, useState as useState10 } from "react";
6688
6704
  import { jsx as jsx22, jsxs as jsxs17 } from "react/jsx-runtime";
6689
- var animationDuration = 0.2;
6705
+ var animationDurationClose = 0.15;
6706
+ var animationDurationOpen = animationDurationClose * 2;
6690
6707
  var FoldableComponent = forwardRef12(function Foldable({
6691
6708
  isOpen: controlledIsOpen,
6692
6709
  defaultOpen = false,
@@ -6694,6 +6711,7 @@ var FoldableComponent = forwardRef12(function Foldable({
6694
6711
  description,
6695
6712
  icon,
6696
6713
  image,
6714
+ headerPaddingBlock,
6697
6715
  headerPaddingInline,
6698
6716
  renderHeader,
6699
6717
  onOpenChange,
@@ -6703,7 +6721,7 @@ var FoldableComponent = forwardRef12(function Foldable({
6703
6721
  const theme2 = useTheme();
6704
6722
  const bodyRef = useRef6(null);
6705
6723
  const [internalIsOpen, setInternalIsOpen] = useBooleanState(defaultOpen);
6706
- const [bodyHeight, setBodyHeight] = useState10(defaultOpen ? void 0 : 0);
6724
+ const [bodyVirtualHeight, setBodyVirtualHeight] = useState10(500);
6707
6725
  const isOpen = controlledIsOpen !== void 0 ? controlledIsOpen : internalIsOpen;
6708
6726
  const open = useCallback12(() => {
6709
6727
  if (controlledIsOpen === void 0) setInternalIsOpen.setTrue();
@@ -6719,29 +6737,8 @@ var FoldableComponent = forwardRef12(function Foldable({
6719
6737
  }, [controlledIsOpen, isOpen, onOpenChange]);
6720
6738
  useEffect10(() => {
6721
6739
  if (!bodyRef.current) return;
6722
- if (isOpen) {
6723
- const height = bodyRef.current.scrollHeight;
6724
- setBodyHeight(height);
6725
- const timeout = setTimeout(() => {
6726
- setBodyHeight(void 0);
6727
- }, animationDuration * 1e3);
6728
- return () => {
6729
- clearTimeout(timeout);
6730
- };
6731
- } else {
6732
- if (bodyHeight === void 0) {
6733
- const height = bodyRef.current.scrollHeight;
6734
- setBodyHeight(height);
6735
- bodyRef.current.offsetHeight;
6736
- }
6737
- const timeout = setTimeout(() => {
6738
- setBodyHeight(0);
6739
- }, 0.01 * 1e3);
6740
- return () => {
6741
- clearTimeout(timeout);
6742
- };
6743
- }
6744
- }, [isOpen, animationDuration, bodyHeight]);
6740
+ setBodyVirtualHeight(Math.min(500, bodyRef.current.scrollHeight * 2));
6741
+ }, [isOpen]);
6745
6742
  useImperativeHandle2(
6746
6743
  ref,
6747
6744
  () => {
@@ -6754,14 +6751,14 @@ var FoldableComponent = forwardRef12(function Foldable({
6754
6751
  },
6755
6752
  [open, close, toggleOpen, isOpen]
6756
6753
  );
6757
- return /* @__PURE__ */ jsxs17(Div_default.column, { width: "100%", overflow: "hidden", ...props, children: [
6754
+ return /* @__PURE__ */ jsxs17(Div_default.column, { width: "100%", ...props, children: [
6758
6755
  renderHeader ? renderHeader(isOpen, toggleOpen) : /* @__PURE__ */ jsxs17(
6759
6756
  Div_default.row,
6760
6757
  {
6761
6758
  width: "100%",
6762
6759
  alignItems: "center",
6763
6760
  gap: theme2.styles.gap,
6764
- paddingBlock: theme2.styles.gap,
6761
+ paddingBlock: headerPaddingBlock ?? theme2.styles.gap,
6765
6762
  paddingInline: headerPaddingInline,
6766
6763
  cursor: "pointer",
6767
6764
  onClick: toggleOpen,
@@ -6771,7 +6768,7 @@ var FoldableComponent = forwardRef12(function Foldable({
6771
6768
  icon && /* @__PURE__ */ jsx22(Icon_default, { name: icon, size: 20, flexShrink: 0 }),
6772
6769
  image && /* @__PURE__ */ jsx22(Image_default.profileImage, { name: image, size: 24, flexShrink: 0 }),
6773
6770
  /* @__PURE__ */ jsxs17(Div_default.column, { gap: theme2.styles.gap / 2, children: [
6774
- title && /* @__PURE__ */ jsx22(Text_default, { as: "h3", fontWeight: 700, children: title }),
6771
+ title && /* @__PURE__ */ jsx22(Text_default, { as: "h3", fontWeight: 700, lineHeight: "20px", children: title }),
6775
6772
  description && /* @__PURE__ */ jsx22(Text_default, { color: theme2.colors.textSecondary, children: description })
6776
6773
  ] })
6777
6774
  ] }),
@@ -6787,7 +6784,18 @@ var FoldableComponent = forwardRef12(function Foldable({
6787
6784
  }
6788
6785
  ),
6789
6786
  /* @__PURE__ */ jsx22(Div_default, { height: isOpen ? 1 : 0, opacity: isOpen ? 1 : 0, transition: theme2.styles.transition, children: /* @__PURE__ */ jsx22(Divider_default.horizontal, {}) }),
6790
- /* @__PURE__ */ jsx22(Div_default, { height: bodyHeight, transition: `height ${animationDuration}s ease`, ref: bodyRef, children: /* @__PURE__ */ jsx22(Div_default, { paddingBlock: theme2.styles.gap, paddingInline: headerPaddingInline, children }) })
6787
+ /* @__PURE__ */ jsx22(
6788
+ Div_default,
6789
+ {
6790
+ maxHeight: isOpen ? bodyVirtualHeight : 0,
6791
+ opacity: !isOpen ? 0 : void 0,
6792
+ transition: `max-height ${isOpen ? animationDurationOpen : animationDurationClose}s ease, opacity ${theme2.styles.transition}`,
6793
+ overflow: !isOpen ? "hidden" : void 0,
6794
+ pointerEvents: !isOpen ? "none" : void 0,
6795
+ ref: bodyRef,
6796
+ children: /* @__PURE__ */ jsx22(Div_default, { paddingBlock: theme2.styles.gap, paddingInline: headerPaddingInline, children })
6797
+ }
6798
+ )
6791
6799
  ] });
6792
6800
  });
6793
6801
  FoldableComponent.box = forwardRef12(function Box3({ ...props }, ref) {
@@ -6798,6 +6806,7 @@ FoldableComponent.box = forwardRef12(function Box3({ ...props }, ref) {
6798
6806
  backgroundColor: theme2.colors.backgroundContent,
6799
6807
  border: `1px solid ${theme2.colors.border}`,
6800
6808
  borderRadius: theme2.styles.borderRadius,
6809
+ headerPaddingBlock: (theme2.styles.gap + theme2.styles.space) / 2,
6801
6810
  headerPaddingInline: theme2.styles.space,
6802
6811
  ...props,
6803
6812
  ref