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.mjs CHANGED
@@ -5827,7 +5827,7 @@ var DropdownComponent = forwardRef10(function Dropdown({
5827
5827
  filter: isFocused2 ? isDisabled ? "brightness(0.95)" : "brightness(0.9)" : void 0,
5828
5828
  filterHover: focusedOptionIndex === void 0 && !isDisabled ? "brightness(0.9)" : void 0,
5829
5829
  cursor: isDisabled ? "not-allowed" : "pointer",
5830
- padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
5830
+ padding: `${theme2.styles.gap}px ${theme2.styles.space}px`,
5831
5831
  value: option,
5832
5832
  onClickWithValue: onClickOption,
5833
5833
  onMouseMove: () => setFocusedOptionIndex(void 0),
@@ -6743,6 +6743,13 @@ InputFieldComponent.phoneNumber = forwardRef11(function PhoneNumber({ label, val
6743
6743
  ] }),
6744
6744
  []
6745
6745
  );
6746
+ const onChangeDropdown = useCallback9(
6747
+ (value2) => {
6748
+ setDropdownValue(value2);
6749
+ onChangeValue?.(value2 ? `+${value2}${inputFieldValue}` : inputFieldValue);
6750
+ },
6751
+ [onChangeValue, inputFieldValue]
6752
+ );
6746
6753
  const onChangeValueElement = useCallback9(
6747
6754
  (value2) => {
6748
6755
  const readyValue = value2.replace(/\D/g, "");
@@ -6807,7 +6814,7 @@ InputFieldComponent.phoneNumber = forwardRef11(function PhoneNumber({ label, val
6807
6814
  defaultValue,
6808
6815
  value: dropdownValue,
6809
6816
  disabled: props.disabled,
6810
- onChange: setDropdownValue,
6817
+ onChange: onChangeDropdown,
6811
6818
  withoutClearButton: true,
6812
6819
  withoutRenderingOptionsWhenClosed: true
6813
6820
  }
@@ -8679,11 +8686,11 @@ var tooltipPositionStyle = (props) => ({
8679
8686
  }
8680
8687
  });
8681
8688
  var TooltipContainer = styled13.div.withConfig({
8682
- shouldForwardProp: (prop) => !["theme", "position", "align", "withArrow", "arrowSize", "isOpen", "gap"].includes(prop)
8689
+ shouldForwardProp: (prop) => !["theme", "position", "align", "pointerEvents", "withArrow", "arrowSize", "isOpen", "gap"].includes(prop)
8683
8690
  })`
8684
8691
  position: absolute;
8685
8692
  opacity: ${(props) => props.isOpen ? 1 : 0};
8686
- pointer-events: ${(props) => props.isOpen ? "auto" : "none"};
8693
+ pointer-events: ${(props) => props.isOpen ? props.pointerEvents : "none"};
8687
8694
  transition: ${(props) => props.theme.styles.transition};
8688
8695
  z-index: 1000;
8689
8696
 
@@ -8766,8 +8773,10 @@ var TooltipComponent = forwardRef16(function Tooltip({
8766
8773
  content,
8767
8774
  contentWidth,
8768
8775
  contentMinWidth,
8776
+ contentPointerEvents = "auto",
8769
8777
  childrenWrapperWidth = "fit-content",
8770
8778
  childrenWrapperHeight,
8779
+ disabled,
8771
8780
  withArrow,
8772
8781
  isSmall,
8773
8782
  backgroundColor,
@@ -8789,6 +8798,7 @@ var TooltipComponent = forwardRef16(function Tooltip({
8789
8798
  const outsideScreenGap = theme2.styles.gap / 2;
8790
8799
  const totalGap = arrowSize + gap;
8791
8800
  const openTooltip = useCallback13(() => {
8801
+ if (disabled) return;
8792
8802
  if (closeTimerRef.current) clearTimeout(closeTimerRef.current);
8793
8803
  setIsOpen(true);
8794
8804
  setIsOpenLate(true);
@@ -8811,7 +8821,7 @@ var TooltipComponent = forwardRef16(function Tooltip({
8811
8821
  }
8812
8822
  }, 1);
8813
8823
  onOpen?.();
8814
- }, [onOpen, outsideScreenGap, totalGap]);
8824
+ }, [disabled, onOpen, outsideScreenGap, totalGap]);
8815
8825
  const closeTooltip = useCallback13(() => {
8816
8826
  setIsOpen(false);
8817
8827
  closeTimerRef.current = setTimeout(() => setIsOpenLate(false), 300);
@@ -8850,6 +8860,10 @@ var TooltipComponent = forwardRef16(function Tooltip({
8850
8860
  };
8851
8861
  }
8852
8862
  }, [trigger, onClickOutside]);
8863
+ useEffect12(() => {
8864
+ if (!disabled) return;
8865
+ closeTooltip();
8866
+ }, [disabled]);
8853
8867
  useImperativeHandle3(
8854
8868
  ref,
8855
8869
  () => {
@@ -8887,6 +8901,7 @@ var TooltipComponent = forwardRef16(function Tooltip({
8887
8901
  theme: theme2,
8888
8902
  position,
8889
8903
  align,
8904
+ pointerEvents: contentPointerEvents,
8890
8905
  withArrow,
8891
8906
  arrowSize,
8892
8907
  gap,
@@ -9354,8 +9369,17 @@ Foldable2.box = FoldableComponent.box;
9354
9369
  var Foldable_default = Foldable2;
9355
9370
 
9356
9371
  // src/components/SideMenu.tsx
9357
- import { memo as memo27, useCallback as useCallback16, useEffect as useEffect15, useMemo as useMemo12 } from "react";
9372
+ import { createContext as createContext2, memo as memo27, useCallback as useCallback16, useContext as useContext2, useEffect as useEffect15, useMemo as useMemo12, useState as useState14 } from "react";
9358
9373
  import { Fragment as Fragment8, jsx as jsx27, jsxs as jsxs23 } from "react/jsx-runtime";
9374
+ var sideMenuContext = createContext2(void 0);
9375
+ var SideMenuContextProvider = sideMenuContext.Provider;
9376
+ var useSideMenuContext = () => {
9377
+ const context = useContext2(sideMenuContext);
9378
+ if (!context) {
9379
+ throw new Error("`useSideMenuContext` must be used within a `<SideMenuContextProvider>` component");
9380
+ }
9381
+ return context;
9382
+ };
9359
9383
  var MenuItemComponent = memo27(function MenuItemComponent2({ item, backgroundColor, onClick }) {
9360
9384
  const reactRouterDomPlugin2 = usePlugin("react-router-dom");
9361
9385
  if (!reactRouterDomPlugin2) {
@@ -9367,15 +9391,22 @@ var MenuItemComponent = memo27(function MenuItemComponent2({ item, backgroundCol
9367
9391
  const theme2 = useTheme();
9368
9392
  const mediaQuery = useMediaQuery();
9369
9393
  const location = reactRouterDomPluginConfig.useLocation();
9370
- const { colorTheme, components, sideMenuIsCollapsed } = useBetterHtmlContextInternal();
9394
+ const { colorTheme, components, sideMenuIsCollapsed, setSideMenuIsCollapsed } = useBetterHtmlContextInternal();
9395
+ const { activeItem, setActiveItem } = useSideMenuContext();
9371
9396
  const [isOpened, setIsOpened] = useBooleanState();
9397
+ const isCollapsed = sideMenuIsCollapsed && !mediaQuery.size1000;
9372
9398
  const onClickElement = useCallback16(() => {
9373
9399
  if (item.disabled) return;
9374
- if (item.onClickCloseSideMenu !== false) onClick?.();
9375
- item.onClick?.(item);
9376
- }, [onClick, item]);
9377
- const isCollapsed = sideMenuIsCollapsed && !mediaQuery.size1000;
9378
- const isActive = item.href ? location.pathname === "/" ? location.pathname === item.href : location.pathname.startsWith(item.href) && item.href !== "/" : false;
9400
+ if (item.children) {
9401
+ setSideMenuIsCollapsed.setFalse();
9402
+ if (isCollapsed) setTimeout(setIsOpened.setTrue, 0.1 * 1e3);
9403
+ else setIsOpened.toggle();
9404
+ } else {
9405
+ if (item.onClickCloseSideMenu !== false) onClick?.();
9406
+ item.onClick?.(item);
9407
+ }
9408
+ }, [onClick, item, isCollapsed]);
9409
+ const isActive = activeItem && item.href && activeItem.href === item.href;
9379
9410
  const readyBackgroundColor = backgroundColor ?? theme2.colors.backgroundContent;
9380
9411
  const iconSize = 16;
9381
9412
  const paddingBlock = theme2.styles.gap;
@@ -9384,48 +9415,70 @@ var MenuItemComponent = memo27(function MenuItemComponent2({ item, backgroundCol
9384
9415
  const lineHeight = 20;
9385
9416
  const lineWidth = 2;
9386
9417
  const lineEndRadius = iconSize / 2 + iconGap * 2;
9387
- const content = /* @__PURE__ */ jsxs23(
9388
- Div_default.row,
9418
+ const content = /* @__PURE__ */ jsx27(
9419
+ Tooltip_default,
9389
9420
  {
9390
- alignItems: "center",
9391
- gap: iconGap,
9392
- whiteSpace: "nowrap",
9393
- backgroundColor: isActive ? colorTheme === "dark" ? lightenColor(theme2.colors.primary, 0.7) : lightenColor(theme2.colors.primary, 0.85) : readyBackgroundColor,
9394
- borderRadius: theme2.styles.borderRadius,
9395
- paddingBlock,
9396
- paddingLeft: isCollapsed ? theme2.styles.space : paddingLeft,
9397
- paddingRight: theme2.styles.space,
9398
- filterHover: `brightness(${colorTheme === "dark" ? isActive ? 0.8 : 1.3 : isActive ? 0.8 : 0.95})`,
9399
- overflow: isCollapsed ? "hidden" : void 0,
9400
- cursor: item.disabled ? "not-allowed" : "pointer",
9401
- opacity: item.disabled ? 0.6 : void 0,
9402
- onClick: item.children ? setIsOpened.toggle : onClickElement,
9403
- children: [
9404
- /* @__PURE__ */ jsx27(Icon_default, { name: item.iconName, color: theme2.colors.primary, size: iconSize, flexShrink: 0 }),
9405
- /* @__PURE__ */ jsx27(
9406
- Text_default,
9407
- {
9408
- flex: 1,
9409
- lineHeight: `${lineHeight}px`,
9410
- color: isActive ? theme2.colors.primary : theme2.colors.textPrimary,
9411
- opacity: isCollapsed ? 0 : void 0,
9412
- transition: theme2.styles.transition,
9413
- children: item.text
9414
- }
9415
- ),
9416
- item.children && /* @__PURE__ */ jsx27(
9417
- Icon_default,
9418
- {
9419
- name: "chevronDown",
9420
- color: theme2.colors.textSecondary,
9421
- size: 14,
9422
- transform: isOpened ? "rotate(180deg)" : void 0,
9423
- transition: theme2.styles.transition
9424
- }
9425
- )
9426
- ]
9421
+ content: /* @__PURE__ */ jsx27(Text_default, { whiteSpace: "nowrap", children: item.text }),
9422
+ contentPointerEvents: "none",
9423
+ withArrow: true,
9424
+ childrenWrapperWidth: "100%",
9425
+ disabled: !isCollapsed,
9426
+ position: "right",
9427
+ children: /* @__PURE__ */ jsxs23(
9428
+ Div_default.row,
9429
+ {
9430
+ alignItems: "center",
9431
+ gap: iconGap,
9432
+ whiteSpace: "nowrap",
9433
+ backgroundColor: isActive ? colorTheme === "dark" ? lightenColor(theme2.colors.primary, 0.7) : lightenColor(theme2.colors.primary, 0.85) : readyBackgroundColor,
9434
+ borderRadius: theme2.styles.borderRadius,
9435
+ paddingBlock,
9436
+ paddingLeft: isCollapsed ? theme2.styles.space : paddingLeft,
9437
+ paddingRight: theme2.styles.space,
9438
+ filterHover: `brightness(${colorTheme === "dark" ? isActive ? 0.8 : 1.3 : isActive ? 0.8 : 0.95})`,
9439
+ overflow: isCollapsed ? "hidden" : void 0,
9440
+ cursor: item.disabled ? "not-allowed" : "pointer",
9441
+ opacity: item.disabled ? 0.6 : void 0,
9442
+ onClick: onClickElement,
9443
+ children: [
9444
+ /* @__PURE__ */ jsx27(Icon_default, { name: item.iconName, color: theme2.colors.primary, size: iconSize, flexShrink: 0 }),
9445
+ /* @__PURE__ */ jsx27(
9446
+ Text_default,
9447
+ {
9448
+ flex: 1,
9449
+ lineHeight: `${lineHeight}px`,
9450
+ color: isActive ? theme2.colors.primary : theme2.colors.textPrimary,
9451
+ opacity: isCollapsed ? 0 : void 0,
9452
+ transition: theme2.styles.transition,
9453
+ children: item.text
9454
+ }
9455
+ ),
9456
+ item.children && /* @__PURE__ */ jsx27(
9457
+ Icon_default,
9458
+ {
9459
+ name: "chevronDown",
9460
+ color: theme2.colors.textSecondary,
9461
+ size: 14,
9462
+ transform: isOpened ? "rotate(180deg)" : void 0,
9463
+ transition: theme2.styles.transition
9464
+ }
9465
+ )
9466
+ ]
9467
+ }
9468
+ )
9427
9469
  }
9428
9470
  );
9471
+ useEffect15(() => {
9472
+ if (!item.href) return;
9473
+ const isActive2 = location.pathname === "/" ? location.pathname === item.href : location.pathname.startsWith(item.href) && item.href !== "/";
9474
+ if (!isActive2) return;
9475
+ setActiveItem(
9476
+ (oldValue) => item.href ? oldValue && oldValue.length > item.href.length ? oldValue : {
9477
+ href: item.href,
9478
+ length: item.href.length
9479
+ } : void 0
9480
+ );
9481
+ }, [location.pathname]);
9429
9482
  useEffect15(() => {
9430
9483
  if (!item.children) return;
9431
9484
  const toBeOpened = item.children.some(
@@ -9433,6 +9486,10 @@ var MenuItemComponent = memo27(function MenuItemComponent2({ item, backgroundCol
9433
9486
  );
9434
9487
  setIsOpened.setState(toBeOpened);
9435
9488
  }, [item]);
9489
+ useEffect15(() => {
9490
+ if (!isCollapsed) return;
9491
+ setIsOpened.setFalse();
9492
+ }, [isCollapsed]);
9436
9493
  const LinkComponentTag = components.button?.tagReplacement?.linkComponent ?? "a";
9437
9494
  return /* @__PURE__ */ jsxs23(Div_default, { width: "100%", children: [
9438
9495
  item.href ? /* @__PURE__ */ jsx27(LinkComponentTag, { to: item.href, href: item.href, onClick: onClickElement, children: content }) : content,
@@ -9519,11 +9576,19 @@ var SideMenuComponent = function SideMenu({
9519
9576
  const theme2 = useTheme();
9520
9577
  const mediaQuery = useMediaQuery();
9521
9578
  const { components, sideMenuIsCollapsed, setSideMenuIsCollapsed, sideMenuIsOpenMobile, setSideMenuIsOpenMobile } = useBetterHtmlContextInternal();
9579
+ const [activeItem, setActiveItem] = useState14();
9522
9580
  const onClickXButton = useCallback16(() => {
9523
9581
  setSideMenuIsOpenMobile.setFalse();
9524
9582
  }, []);
9525
9583
  const readyItems = useMemo12(() => items.filter((item) => !item.hidden), [items]);
9526
9584
  const readyBottomItems = useMemo12(() => bottomItems?.filter((item) => !item.hidden), [bottomItems]);
9585
+ const contextValue = useMemo12(
9586
+ () => ({
9587
+ activeItem,
9588
+ setActiveItem
9589
+ }),
9590
+ [activeItem]
9591
+ );
9527
9592
  const isCollapsable = collapsable && !mediaQuery.size1000;
9528
9593
  const isCollapsed = sideMenuIsCollapsed && !mediaQuery.size1000;
9529
9594
  const LinkComponentTag = components.button?.tagReplacement?.linkComponent ?? "a";
@@ -9531,7 +9596,7 @@ var SideMenuComponent = function SideMenu({
9531
9596
  const sideMenuCollapsedWidth = theme2.styles.space + theme2.styles.space * 2 + 16 + theme2.styles.space;
9532
9597
  const readyBackgroundColor = backgroundColor ?? theme2.colors.backgroundContent;
9533
9598
  const logoSize = sideMenuCollapsedWidth - theme2.styles.space * 2;
9534
- return /* @__PURE__ */ jsxs23(
9599
+ return /* @__PURE__ */ jsx27(SideMenuContextProvider, { value: contextValue, children: /* @__PURE__ */ jsxs23(
9535
9600
  Div_default.column,
9536
9601
  {
9537
9602
  position: "fixed",
@@ -9591,7 +9656,7 @@ var SideMenuComponent = function SideMenu({
9591
9656
  {
9592
9657
  width: "100%",
9593
9658
  height: "100%",
9594
- overflowY: "auto",
9659
+ overflowY: !isCollapsed ? "auto" : void 0,
9595
9660
  paddingInline: theme2.styles.space,
9596
9661
  paddingBottom: !isCollapsable && !readyBottomItems ? theme2.styles.space : void 0,
9597
9662
  children: /* @__PURE__ */ jsx27(Div_default.column, { gap: theme2.styles.gap / 2, children: readyItems.map((item) => /* @__PURE__ */ jsx27(
@@ -9696,7 +9761,7 @@ var SideMenuComponent = function SideMenu({
9696
9761
  absoluteComponent && /* @__PURE__ */ jsx27(Div_default, { position: "absolute", top: 0, left: 0, pointerEvents: "none", zIndex: 2, children: /* @__PURE__ */ jsx27(Div_default, { pointerEvents: "all", children: absoluteComponent }) })
9697
9762
  ]
9698
9763
  }
9699
- );
9764
+ ) });
9700
9765
  };
9701
9766
  SideMenuComponent.pageHolder = function SideMenuPageHolder({ outsideComponent, ...props }) {
9702
9767
  const theme2 = useTheme();