react-better-html 1.1.197 → 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.d.mts CHANGED
@@ -829,9 +829,11 @@ type TooltipProps = {
829
829
  content: React.ReactNode;
830
830
  contentWidth?: React.CSSProperties["width"];
831
831
  contentMinWidth?: React.CSSProperties["minWidth"];
832
+ contentPointerEvents?: React.CSSProperties["pointerEvents"];
832
833
  /** @default "fit-content" */
833
834
  childrenWrapperWidth?: React.CSSProperties["width"];
834
835
  childrenWrapperHeight?: React.CSSProperties["height"];
836
+ disabled?: boolean;
835
837
  withArrow?: boolean;
836
838
  isSmall?: boolean;
837
839
  backgroundColor?: string;
package/dist/index.d.ts CHANGED
@@ -829,9 +829,11 @@ type TooltipProps = {
829
829
  content: React.ReactNode;
830
830
  contentWidth?: React.CSSProperties["width"];
831
831
  contentMinWidth?: React.CSSProperties["minWidth"];
832
+ contentPointerEvents?: React.CSSProperties["pointerEvents"];
832
833
  /** @default "fit-content" */
833
834
  childrenWrapperWidth?: React.CSSProperties["width"];
834
835
  childrenWrapperHeight?: React.CSSProperties["height"];
836
+ disabled?: boolean;
835
837
  withArrow?: boolean;
836
838
  isSmall?: boolean;
837
839
  backgroundColor?: string;
package/dist/index.js CHANGED
@@ -5924,7 +5924,7 @@ var DropdownComponent = (0, import_react18.forwardRef)(function Dropdown({
5924
5924
  filter: isFocused2 ? isDisabled ? "brightness(0.95)" : "brightness(0.9)" : void 0,
5925
5925
  filterHover: focusedOptionIndex === void 0 && !isDisabled ? "brightness(0.9)" : void 0,
5926
5926
  cursor: isDisabled ? "not-allowed" : "pointer",
5927
- padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
5927
+ padding: `${theme2.styles.gap}px ${theme2.styles.space}px`,
5928
5928
  value: option,
5929
5929
  onClickWithValue: onClickOption,
5930
5930
  onMouseMove: () => setFocusedOptionIndex(void 0),
@@ -6840,6 +6840,13 @@ InputFieldComponent.phoneNumber = (0, import_react20.forwardRef)(function PhoneN
6840
6840
  ] }),
6841
6841
  []
6842
6842
  );
6843
+ const onChangeDropdown = (0, import_react20.useCallback)(
6844
+ (value2) => {
6845
+ setDropdownValue(value2);
6846
+ onChangeValue?.(value2 ? `+${value2}${inputFieldValue}` : inputFieldValue);
6847
+ },
6848
+ [onChangeValue, inputFieldValue]
6849
+ );
6843
6850
  const onChangeValueElement = (0, import_react20.useCallback)(
6844
6851
  (value2) => {
6845
6852
  const readyValue = value2.replace(/\D/g, "");
@@ -6904,7 +6911,7 @@ InputFieldComponent.phoneNumber = (0, import_react20.forwardRef)(function PhoneN
6904
6911
  defaultValue,
6905
6912
  value: dropdownValue,
6906
6913
  disabled: props.disabled,
6907
- onChange: setDropdownValue,
6914
+ onChange: onChangeDropdown,
6908
6915
  withoutClearButton: true,
6909
6916
  withoutRenderingOptionsWhenClosed: true
6910
6917
  }
@@ -8766,11 +8773,11 @@ var tooltipPositionStyle = (props) => ({
8766
8773
  }
8767
8774
  });
8768
8775
  var TooltipContainer = import_styled_components14.default.div.withConfig({
8769
- shouldForwardProp: (prop) => !["theme", "position", "align", "withArrow", "arrowSize", "isOpen", "gap"].includes(prop)
8776
+ shouldForwardProp: (prop) => !["theme", "position", "align", "pointerEvents", "withArrow", "arrowSize", "isOpen", "gap"].includes(prop)
8770
8777
  })`
8771
8778
  position: absolute;
8772
8779
  opacity: ${(props) => props.isOpen ? 1 : 0};
8773
- pointer-events: ${(props) => props.isOpen ? "auto" : "none"};
8780
+ pointer-events: ${(props) => props.isOpen ? props.pointerEvents : "none"};
8774
8781
  transition: ${(props) => props.theme.styles.transition};
8775
8782
  z-index: 1000;
8776
8783
 
@@ -8853,8 +8860,10 @@ var TooltipComponent = (0, import_react27.forwardRef)(function Tooltip({
8853
8860
  content,
8854
8861
  contentWidth,
8855
8862
  contentMinWidth,
8863
+ contentPointerEvents = "auto",
8856
8864
  childrenWrapperWidth = "fit-content",
8857
8865
  childrenWrapperHeight,
8866
+ disabled,
8858
8867
  withArrow,
8859
8868
  isSmall,
8860
8869
  backgroundColor,
@@ -8876,6 +8885,7 @@ var TooltipComponent = (0, import_react27.forwardRef)(function Tooltip({
8876
8885
  const outsideScreenGap = theme2.styles.gap / 2;
8877
8886
  const totalGap = arrowSize + gap;
8878
8887
  const openTooltip = (0, import_react27.useCallback)(() => {
8888
+ if (disabled) return;
8879
8889
  if (closeTimerRef.current) clearTimeout(closeTimerRef.current);
8880
8890
  setIsOpen(true);
8881
8891
  setIsOpenLate(true);
@@ -8898,7 +8908,7 @@ var TooltipComponent = (0, import_react27.forwardRef)(function Tooltip({
8898
8908
  }
8899
8909
  }, 1);
8900
8910
  onOpen?.();
8901
- }, [onOpen, outsideScreenGap, totalGap]);
8911
+ }, [disabled, onOpen, outsideScreenGap, totalGap]);
8902
8912
  const closeTooltip = (0, import_react27.useCallback)(() => {
8903
8913
  setIsOpen(false);
8904
8914
  closeTimerRef.current = setTimeout(() => setIsOpenLate(false), 300);
@@ -8937,6 +8947,10 @@ var TooltipComponent = (0, import_react27.forwardRef)(function Tooltip({
8937
8947
  };
8938
8948
  }
8939
8949
  }, [trigger, onClickOutside]);
8950
+ (0, import_react27.useEffect)(() => {
8951
+ if (!disabled) return;
8952
+ closeTooltip();
8953
+ }, [disabled]);
8940
8954
  (0, import_react27.useImperativeHandle)(
8941
8955
  ref,
8942
8956
  () => {
@@ -8974,6 +8988,7 @@ var TooltipComponent = (0, import_react27.forwardRef)(function Tooltip({
8974
8988
  theme: theme2,
8975
8989
  position,
8976
8990
  align,
8991
+ pointerEvents: contentPointerEvents,
8977
8992
  withArrow,
8978
8993
  arrowSize,
8979
8994
  gap,
@@ -9443,6 +9458,15 @@ var Foldable_default = Foldable2;
9443
9458
  // src/components/SideMenu.tsx
9444
9459
  var import_react30 = require("react");
9445
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
+ };
9446
9470
  var MenuItemComponent = (0, import_react30.memo)(function MenuItemComponent2({ item, backgroundColor, onClick }) {
9447
9471
  const reactRouterDomPlugin2 = usePlugin("react-router-dom");
9448
9472
  if (!reactRouterDomPlugin2) {
@@ -9454,15 +9478,22 @@ var MenuItemComponent = (0, import_react30.memo)(function MenuItemComponent2({ i
9454
9478
  const theme2 = useTheme();
9455
9479
  const mediaQuery = useMediaQuery();
9456
9480
  const location = reactRouterDomPluginConfig.useLocation();
9457
- const { colorTheme, components, sideMenuIsCollapsed } = useBetterHtmlContextInternal();
9481
+ const { colorTheme, components, sideMenuIsCollapsed, setSideMenuIsCollapsed } = useBetterHtmlContextInternal();
9482
+ const { activeItem, setActiveItem } = useSideMenuContext();
9458
9483
  const [isOpened, setIsOpened] = useBooleanState();
9484
+ const isCollapsed = sideMenuIsCollapsed && !mediaQuery.size1000;
9459
9485
  const onClickElement = (0, import_react30.useCallback)(() => {
9460
9486
  if (item.disabled) return;
9461
- if (item.onClickCloseSideMenu !== false) onClick?.();
9462
- item.onClick?.(item);
9463
- }, [onClick, item]);
9464
- const isCollapsed = sideMenuIsCollapsed && !mediaQuery.size1000;
9465
- const isActive = item.href ? location.pathname === "/" ? location.pathname === item.href : location.pathname.startsWith(item.href) && item.href !== "/" : false;
9487
+ if (item.children) {
9488
+ setSideMenuIsCollapsed.setFalse();
9489
+ if (isCollapsed) setTimeout(setIsOpened.setTrue, 0.1 * 1e3);
9490
+ else setIsOpened.toggle();
9491
+ } else {
9492
+ if (item.onClickCloseSideMenu !== false) onClick?.();
9493
+ item.onClick?.(item);
9494
+ }
9495
+ }, [onClick, item, isCollapsed]);
9496
+ const isActive = activeItem && item.href && activeItem.href === item.href;
9466
9497
  const readyBackgroundColor = backgroundColor ?? theme2.colors.backgroundContent;
9467
9498
  const iconSize = 16;
9468
9499
  const paddingBlock = theme2.styles.gap;
@@ -9471,48 +9502,70 @@ var MenuItemComponent = (0, import_react30.memo)(function MenuItemComponent2({ i
9471
9502
  const lineHeight = 20;
9472
9503
  const lineWidth = 2;
9473
9504
  const lineEndRadius = iconSize / 2 + iconGap * 2;
9474
- const content = /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
9475
- Div_default.row,
9505
+ const content = /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
9506
+ Tooltip_default,
9476
9507
  {
9477
- alignItems: "center",
9478
- gap: iconGap,
9479
- whiteSpace: "nowrap",
9480
- backgroundColor: isActive ? colorTheme === "dark" ? lightenColor(theme2.colors.primary, 0.7) : lightenColor(theme2.colors.primary, 0.85) : readyBackgroundColor,
9481
- borderRadius: theme2.styles.borderRadius,
9482
- paddingBlock,
9483
- paddingLeft: isCollapsed ? theme2.styles.space : paddingLeft,
9484
- paddingRight: theme2.styles.space,
9485
- filterHover: `brightness(${colorTheme === "dark" ? isActive ? 0.8 : 1.3 : isActive ? 0.8 : 0.95})`,
9486
- overflow: isCollapsed ? "hidden" : void 0,
9487
- cursor: item.disabled ? "not-allowed" : "pointer",
9488
- opacity: item.disabled ? 0.6 : void 0,
9489
- onClick: item.children ? setIsOpened.toggle : onClickElement,
9490
- children: [
9491
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Icon_default, { name: item.iconName, color: theme2.colors.primary, size: iconSize, flexShrink: 0 }),
9492
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
9493
- Text_default,
9494
- {
9495
- flex: 1,
9496
- lineHeight: `${lineHeight}px`,
9497
- color: isActive ? theme2.colors.primary : theme2.colors.textPrimary,
9498
- opacity: isCollapsed ? 0 : void 0,
9499
- transition: theme2.styles.transition,
9500
- children: item.text
9501
- }
9502
- ),
9503
- item.children && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
9504
- Icon_default,
9505
- {
9506
- name: "chevronDown",
9507
- color: theme2.colors.textSecondary,
9508
- size: 14,
9509
- transform: isOpened ? "rotate(180deg)" : void 0,
9510
- transition: theme2.styles.transition
9511
- }
9512
- )
9513
- ]
9508
+ content: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Text_default, { whiteSpace: "nowrap", children: item.text }),
9509
+ contentPointerEvents: "none",
9510
+ withArrow: true,
9511
+ childrenWrapperWidth: "100%",
9512
+ disabled: !isCollapsed,
9513
+ position: "right",
9514
+ children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
9515
+ Div_default.row,
9516
+ {
9517
+ alignItems: "center",
9518
+ gap: iconGap,
9519
+ whiteSpace: "nowrap",
9520
+ backgroundColor: isActive ? colorTheme === "dark" ? lightenColor(theme2.colors.primary, 0.7) : lightenColor(theme2.colors.primary, 0.85) : readyBackgroundColor,
9521
+ borderRadius: theme2.styles.borderRadius,
9522
+ paddingBlock,
9523
+ paddingLeft: isCollapsed ? theme2.styles.space : paddingLeft,
9524
+ paddingRight: theme2.styles.space,
9525
+ filterHover: `brightness(${colorTheme === "dark" ? isActive ? 0.8 : 1.3 : isActive ? 0.8 : 0.95})`,
9526
+ overflow: isCollapsed ? "hidden" : void 0,
9527
+ cursor: item.disabled ? "not-allowed" : "pointer",
9528
+ opacity: item.disabled ? 0.6 : void 0,
9529
+ onClick: onClickElement,
9530
+ children: [
9531
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Icon_default, { name: item.iconName, color: theme2.colors.primary, size: iconSize, flexShrink: 0 }),
9532
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
9533
+ Text_default,
9534
+ {
9535
+ flex: 1,
9536
+ lineHeight: `${lineHeight}px`,
9537
+ color: isActive ? theme2.colors.primary : theme2.colors.textPrimary,
9538
+ opacity: isCollapsed ? 0 : void 0,
9539
+ transition: theme2.styles.transition,
9540
+ children: item.text
9541
+ }
9542
+ ),
9543
+ item.children && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
9544
+ Icon_default,
9545
+ {
9546
+ name: "chevronDown",
9547
+ color: theme2.colors.textSecondary,
9548
+ size: 14,
9549
+ transform: isOpened ? "rotate(180deg)" : void 0,
9550
+ transition: theme2.styles.transition
9551
+ }
9552
+ )
9553
+ ]
9554
+ }
9555
+ )
9514
9556
  }
9515
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]);
9516
9569
  (0, import_react30.useEffect)(() => {
9517
9570
  if (!item.children) return;
9518
9571
  const toBeOpened = item.children.some(
@@ -9520,6 +9573,10 @@ var MenuItemComponent = (0, import_react30.memo)(function MenuItemComponent2({ i
9520
9573
  );
9521
9574
  setIsOpened.setState(toBeOpened);
9522
9575
  }, [item]);
9576
+ (0, import_react30.useEffect)(() => {
9577
+ if (!isCollapsed) return;
9578
+ setIsOpened.setFalse();
9579
+ }, [isCollapsed]);
9523
9580
  const LinkComponentTag = components.button?.tagReplacement?.linkComponent ?? "a";
9524
9581
  return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(Div_default, { width: "100%", children: [
9525
9582
  item.href ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(LinkComponentTag, { to: item.href, href: item.href, onClick: onClickElement, children: content }) : content,
@@ -9606,11 +9663,19 @@ var SideMenuComponent = function SideMenu({
9606
9663
  const theme2 = useTheme();
9607
9664
  const mediaQuery = useMediaQuery();
9608
9665
  const { components, sideMenuIsCollapsed, setSideMenuIsCollapsed, sideMenuIsOpenMobile, setSideMenuIsOpenMobile } = useBetterHtmlContextInternal();
9666
+ const [activeItem, setActiveItem] = (0, import_react30.useState)();
9609
9667
  const onClickXButton = (0, import_react30.useCallback)(() => {
9610
9668
  setSideMenuIsOpenMobile.setFalse();
9611
9669
  }, []);
9612
9670
  const readyItems = (0, import_react30.useMemo)(() => items.filter((item) => !item.hidden), [items]);
9613
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
+ );
9614
9679
  const isCollapsable = collapsable && !mediaQuery.size1000;
9615
9680
  const isCollapsed = sideMenuIsCollapsed && !mediaQuery.size1000;
9616
9681
  const LinkComponentTag = components.button?.tagReplacement?.linkComponent ?? "a";
@@ -9618,7 +9683,7 @@ var SideMenuComponent = function SideMenu({
9618
9683
  const sideMenuCollapsedWidth = theme2.styles.space + theme2.styles.space * 2 + 16 + theme2.styles.space;
9619
9684
  const readyBackgroundColor = backgroundColor ?? theme2.colors.backgroundContent;
9620
9685
  const logoSize = sideMenuCollapsedWidth - theme2.styles.space * 2;
9621
- 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)(
9622
9687
  Div_default.column,
9623
9688
  {
9624
9689
  position: "fixed",
@@ -9678,7 +9743,7 @@ var SideMenuComponent = function SideMenu({
9678
9743
  {
9679
9744
  width: "100%",
9680
9745
  height: "100%",
9681
- overflowY: "auto",
9746
+ overflowY: !isCollapsed ? "auto" : void 0,
9682
9747
  paddingInline: theme2.styles.space,
9683
9748
  paddingBottom: !isCollapsable && !readyBottomItems ? theme2.styles.space : void 0,
9684
9749
  children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Div_default.column, { gap: theme2.styles.gap / 2, children: readyItems.map((item) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
@@ -9783,7 +9848,7 @@ var SideMenuComponent = function SideMenu({
9783
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 }) })
9784
9849
  ]
9785
9850
  }
9786
- );
9851
+ ) });
9787
9852
  };
9788
9853
  SideMenuComponent.pageHolder = function SideMenuPageHolder({ outsideComponent, ...props }) {
9789
9854
  const theme2 = useTheme();