react-better-html 1.1.198 → 1.1.199

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
@@ -8947,6 +8947,10 @@ var TooltipComponent = (0, import_react27.forwardRef)(function Tooltip({
8947
8947
  };
8948
8948
  }
8949
8949
  }, [trigger, onClickOutside]);
8950
+ (0, import_react27.useEffect)(() => {
8951
+ if (!disabled) return;
8952
+ closeTooltip();
8953
+ }, [disabled]);
8950
8954
  (0, import_react27.useImperativeHandle)(
8951
8955
  ref,
8952
8956
  () => {
@@ -9454,6 +9458,15 @@ var Foldable_default = Foldable2;
9454
9458
  // src/components/SideMenu.tsx
9455
9459
  var import_react30 = require("react");
9456
9460
  var import_jsx_runtime28 = require("react/jsx-runtime");
9461
+ var sideMenuContext = (0, import_react30.createContext)(void 0);
9462
+ var SideMenuContextProvider = sideMenuContext.Provider;
9463
+ var useSideMenuContext = () => {
9464
+ const context = (0, import_react30.useContext)(sideMenuContext);
9465
+ if (!context) {
9466
+ throw new Error("`useSideMenuContext` must be used within a `<SideMenuContextProvider>` component");
9467
+ }
9468
+ return context;
9469
+ };
9457
9470
  var MenuItemComponent = (0, import_react30.memo)(function MenuItemComponent2({ item, backgroundColor, onClick }) {
9458
9471
  const reactRouterDomPlugin2 = usePlugin("react-router-dom");
9459
9472
  if (!reactRouterDomPlugin2) {
@@ -9466,6 +9479,7 @@ var MenuItemComponent = (0, import_react30.memo)(function MenuItemComponent2({ i
9466
9479
  const mediaQuery = useMediaQuery();
9467
9480
  const location = reactRouterDomPluginConfig.useLocation();
9468
9481
  const { colorTheme, components, sideMenuIsCollapsed, setSideMenuIsCollapsed } = useBetterHtmlContextInternal();
9482
+ const { activeItem, setActiveItem } = useSideMenuContext();
9469
9483
  const [isOpened, setIsOpened] = useBooleanState();
9470
9484
  const isCollapsed = sideMenuIsCollapsed && !mediaQuery.size1000;
9471
9485
  const onClickElement = (0, import_react30.useCallback)(() => {
@@ -9479,7 +9493,7 @@ var MenuItemComponent = (0, import_react30.memo)(function MenuItemComponent2({ i
9479
9493
  item.onClick?.(item);
9480
9494
  }
9481
9495
  }, [onClick, item, isCollapsed]);
9482
- const isActive = item.href ? location.pathname === "/" ? location.pathname === item.href : location.pathname.startsWith(item.href) && item.href !== "/" : false;
9496
+ const isActive = activeItem && item.href && activeItem.href === item.href;
9483
9497
  const readyBackgroundColor = backgroundColor ?? theme2.colors.backgroundContent;
9484
9498
  const iconSize = 16;
9485
9499
  const paddingBlock = theme2.styles.gap;
@@ -9541,6 +9555,17 @@ var MenuItemComponent = (0, import_react30.memo)(function MenuItemComponent2({ i
9541
9555
  )
9542
9556
  }
9543
9557
  );
9558
+ (0, import_react30.useEffect)(() => {
9559
+ if (!item.href) return;
9560
+ const isActive2 = location.pathname === "/" ? location.pathname === item.href : location.pathname.startsWith(item.href) && item.href !== "/";
9561
+ if (!isActive2) return;
9562
+ setActiveItem(
9563
+ (oldValue) => item.href ? oldValue && oldValue.length > item.href.length ? oldValue : {
9564
+ href: item.href,
9565
+ length: item.href.length
9566
+ } : void 0
9567
+ );
9568
+ }, [location.pathname]);
9544
9569
  (0, import_react30.useEffect)(() => {
9545
9570
  if (!item.children) return;
9546
9571
  const toBeOpened = item.children.some(
@@ -9548,6 +9573,10 @@ var MenuItemComponent = (0, import_react30.memo)(function MenuItemComponent2({ i
9548
9573
  );
9549
9574
  setIsOpened.setState(toBeOpened);
9550
9575
  }, [item]);
9576
+ (0, import_react30.useEffect)(() => {
9577
+ if (!isCollapsed) return;
9578
+ setIsOpened.setFalse();
9579
+ }, [isCollapsed]);
9551
9580
  const LinkComponentTag = components.button?.tagReplacement?.linkComponent ?? "a";
9552
9581
  return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(Div_default, { width: "100%", children: [
9553
9582
  item.href ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(LinkComponentTag, { to: item.href, href: item.href, onClick: onClickElement, children: content }) : content,
@@ -9634,11 +9663,19 @@ var SideMenuComponent = function SideMenu({
9634
9663
  const theme2 = useTheme();
9635
9664
  const mediaQuery = useMediaQuery();
9636
9665
  const { components, sideMenuIsCollapsed, setSideMenuIsCollapsed, sideMenuIsOpenMobile, setSideMenuIsOpenMobile } = useBetterHtmlContextInternal();
9666
+ const [activeItem, setActiveItem] = (0, import_react30.useState)();
9637
9667
  const onClickXButton = (0, import_react30.useCallback)(() => {
9638
9668
  setSideMenuIsOpenMobile.setFalse();
9639
9669
  }, []);
9640
9670
  const readyItems = (0, import_react30.useMemo)(() => items.filter((item) => !item.hidden), [items]);
9641
9671
  const readyBottomItems = (0, import_react30.useMemo)(() => bottomItems?.filter((item) => !item.hidden), [bottomItems]);
9672
+ const contextValue = (0, import_react30.useMemo)(
9673
+ () => ({
9674
+ activeItem,
9675
+ setActiveItem
9676
+ }),
9677
+ [activeItem]
9678
+ );
9642
9679
  const isCollapsable = collapsable && !mediaQuery.size1000;
9643
9680
  const isCollapsed = sideMenuIsCollapsed && !mediaQuery.size1000;
9644
9681
  const LinkComponentTag = components.button?.tagReplacement?.linkComponent ?? "a";
@@ -9646,7 +9683,7 @@ var SideMenuComponent = function SideMenu({
9646
9683
  const sideMenuCollapsedWidth = theme2.styles.space + theme2.styles.space * 2 + 16 + theme2.styles.space;
9647
9684
  const readyBackgroundColor = backgroundColor ?? theme2.colors.backgroundContent;
9648
9685
  const logoSize = sideMenuCollapsedWidth - theme2.styles.space * 2;
9649
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
9686
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(SideMenuContextProvider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
9650
9687
  Div_default.column,
9651
9688
  {
9652
9689
  position: "fixed",
@@ -9811,7 +9848,7 @@ var SideMenuComponent = function SideMenu({
9811
9848
  absoluteComponent && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Div_default, { position: "absolute", top: 0, left: 0, pointerEvents: "none", zIndex: 2, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Div_default, { pointerEvents: "all", children: absoluteComponent }) })
9812
9849
  ]
9813
9850
  }
9814
- );
9851
+ ) });
9815
9852
  };
9816
9853
  SideMenuComponent.pageHolder = function SideMenuPageHolder({ outsideComponent, ...props }) {
9817
9854
  const theme2 = useTheme();