react-better-html 1.1.284 → 1.1.286

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
@@ -1614,6 +1614,8 @@ var PageHeaderComponent = forwardRef5(function PageHeader({
1614
1614
  description,
1615
1615
  descriptionFontSize,
1616
1616
  descriptionColor,
1617
+ imageGap,
1618
+ titleGap,
1617
1619
  textAlign,
1618
1620
  rightElement,
1619
1621
  lightMode,
@@ -1628,7 +1630,7 @@ var PageHeaderComponent = forwardRef5(function PageHeader({
1628
1630
  Div_default.row,
1629
1631
  {
1630
1632
  alignItems: "center",
1631
- gap: theme2.styles.space,
1633
+ gap: imageGap ?? theme2.styles.space,
1632
1634
  marginBottom: marginBottom ?? theme2.styles.space * 2,
1633
1635
  ref,
1634
1636
  children: [
@@ -1649,7 +1651,7 @@ var PageHeaderComponent = forwardRef5(function PageHeader({
1649
1651
  {
1650
1652
  alignItems: textAlign === "center" ? "center" : textAlign === "right" ? "flex-end" : void 0,
1651
1653
  flex: 1,
1652
- gap: theme2.styles.gap / 2,
1654
+ gap: titleGap ?? theme2.styles.gap / 2,
1653
1655
  children: [
1654
1656
  /* @__PURE__ */ jsxs2(
1655
1657
  Div_default.row,
@@ -1796,6 +1798,7 @@ DivComponent.box = forwardRef6(function Box({
1796
1798
  titleRightElement,
1797
1799
  description,
1798
1800
  descriptionColor,
1801
+ titleGap,
1799
1802
  textAlign,
1800
1803
  rightElement,
1801
1804
  lightMode,
@@ -1849,6 +1852,7 @@ DivComponent.box = forwardRef6(function Box({
1849
1852
  titleRightElement,
1850
1853
  description,
1851
1854
  descriptionColor,
1855
+ titleGap,
1852
1856
  textAlign,
1853
1857
  rightElement,
1854
1858
  lightMode,
@@ -7248,7 +7252,17 @@ var Table2 = memo23(TableComponent);
7248
7252
  var Table_default = Table2;
7249
7253
 
7250
7254
  // src/components/Tooltip.tsx
7251
- import { memo as memo24, useCallback as useCallback16, useRef as useRef7, useState as useState12, useEffect as useEffect13, forwardRef as forwardRef16, useImperativeHandle as useImperativeHandle3, useMemo as useMemo10 } from "react";
7255
+ import {
7256
+ memo as memo24,
7257
+ useCallback as useCallback16,
7258
+ useRef as useRef7,
7259
+ useState as useState12,
7260
+ useEffect as useEffect13,
7261
+ useLayoutEffect,
7262
+ forwardRef as forwardRef16,
7263
+ useImperativeHandle as useImperativeHandle3,
7264
+ useMemo as useMemo10
7265
+ } from "react";
7252
7266
  import { useTheme as useTheme26 } from "react-better-core";
7253
7267
  import styled13, { css as css6 } from "styled-components";
7254
7268
  import { jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
@@ -7408,9 +7422,9 @@ var TooltipComponent = forwardRef16(function Tooltip({
7408
7422
  children
7409
7423
  }, ref) {
7410
7424
  const theme2 = useTheme26();
7425
+ const wrapperRef = useRef7(null);
7411
7426
  const triggerHolderRef = useRef7(null);
7412
7427
  const contentRef = useRef7(null);
7413
- const tooltipContainerRef = useRef7(null);
7414
7428
  const closeTimerRef = useRef7(void 0);
7415
7429
  const [isOpen, setIsOpen] = useState12(false);
7416
7430
  const [isOpenLate, setIsOpenLate] = useState12(false);
@@ -7423,26 +7437,8 @@ var TooltipComponent = forwardRef16(function Tooltip({
7423
7437
  if (closeTimerRef.current) clearTimeout(closeTimerRef.current);
7424
7438
  setIsOpen(true);
7425
7439
  setIsOpenLate(true);
7426
- setTimeout(() => {
7427
- if (!tooltipContainerRef.current) return;
7428
- if (!contentRef.current) return;
7429
- const clientRects = tooltipContainerRef.current.getBoundingClientRect();
7430
- if (clientRects) {
7431
- const { width, height, x, y } = clientRects;
7432
- const topOutside = y < 0;
7433
- const bottomOutside = y + height > window.innerHeight;
7434
- const leftOutside = x < 0;
7435
- const rightOutside = x + width > window.innerWidth;
7436
- if (topOutside) contentRef.current.style.transform = `translateY(${y * -1 + outsideScreenGap}px)`;
7437
- if (bottomOutside)
7438
- contentRef.current.style.transform = `translateY(${window.innerHeight - (y + height) - totalGap}px)`;
7439
- if (leftOutside) contentRef.current.style.transform = `translateX(${x * -1 + outsideScreenGap}px)`;
7440
- if (rightOutside)
7441
- contentRef.current.style.transform = `translateX(${window.innerWidth - (x + width) - totalGap}px)`;
7442
- }
7443
- }, 1);
7444
7440
  onOpen?.();
7445
- }, [disabled, onOpen, outsideScreenGap, totalGap]);
7441
+ }, [disabled, onOpen]);
7446
7442
  const closeTooltip = useCallback16(() => {
7447
7443
  setIsOpen(false);
7448
7444
  closeTimerRef.current = setTimeout(() => setIsOpenLate(false), 300);
@@ -7473,6 +7469,29 @@ var TooltipComponent = forwardRef16(function Tooltip({
7473
7469
  },
7474
7470
  [trigger, isOpen, closeTooltip]
7475
7471
  );
7472
+ const clampContentInsideViewport = useCallback16(() => {
7473
+ if (!wrapperRef.current || !contentRef.current) return;
7474
+ const wrapperRect = wrapperRef.current.getBoundingClientRect();
7475
+ const contentWidth2 = contentRef.current.offsetWidth;
7476
+ const contentHeight = contentRef.current.offsetHeight;
7477
+ let expectedLeft;
7478
+ let expectedTop;
7479
+ if (position === "top" || position === "bottom") {
7480
+ expectedTop = position === "top" ? wrapperRect.top - totalGap - contentHeight : wrapperRect.bottom + totalGap;
7481
+ expectedLeft = align === "left" ? wrapperRect.left : align === "right" ? wrapperRect.right - contentWidth2 : wrapperRect.left + wrapperRect.width / 2 - contentWidth2 / 2;
7482
+ } else {
7483
+ expectedLeft = position === "left" ? wrapperRect.left - totalGap - contentWidth2 : wrapperRect.right + totalGap;
7484
+ expectedTop = align === "top" ? wrapperRect.top : align === "bottom" ? wrapperRect.bottom - contentHeight : wrapperRect.top + wrapperRect.height / 2 - contentHeight / 2;
7485
+ }
7486
+ const getShift = (start, size, viewportSize) => {
7487
+ if (start < outsideScreenGap) return outsideScreenGap - start;
7488
+ if (start + size > viewportSize - outsideScreenGap) return viewportSize - outsideScreenGap - (start + size);
7489
+ return 0;
7490
+ };
7491
+ const shiftX = getShift(expectedLeft, contentWidth2, window.innerWidth);
7492
+ const shiftY = getShift(expectedTop, contentHeight, window.innerHeight);
7493
+ contentRef.current.style.transform = shiftX || shiftY ? `translate(${shiftX}px, ${shiftY}px)` : "";
7494
+ }, [position, align, totalGap, outsideScreenGap]);
7476
7495
  useEffect13(() => {
7477
7496
  if (trigger === "click") {
7478
7497
  document.addEventListener("mousedown", onClickOutside);
@@ -7485,6 +7504,9 @@ var TooltipComponent = forwardRef16(function Tooltip({
7485
7504
  if (!disabled) return;
7486
7505
  closeTooltip();
7487
7506
  }, [disabled]);
7507
+ useLayoutEffect(() => {
7508
+ if (isOpen) clampContentInsideViewport();
7509
+ }, [isOpen, clampContentInsideViewport]);
7488
7510
  useImperativeHandle3(ref, () => {
7489
7511
  return {
7490
7512
  isOpen,
@@ -7501,6 +7523,7 @@ var TooltipComponent = forwardRef16(function Tooltip({
7501
7523
  onClick: onClickHolder,
7502
7524
  onMouseEnter,
7503
7525
  onMouseLeave,
7526
+ ref: wrapperRef,
7504
7527
  children: [
7505
7528
  /* @__PURE__ */ jsx25(
7506
7529
  Div_default,
@@ -7524,7 +7547,6 @@ var TooltipComponent = forwardRef16(function Tooltip({
7524
7547
  gap,
7525
7548
  isOpen,
7526
7549
  role: "tooltip",
7527
- ref: tooltipContainerRef,
7528
7550
  children: (isOpen || isOpenLate) && /* @__PURE__ */ jsxs21(Div_default, { position: "relative", ref: contentRef, children: [
7529
7551
  /* @__PURE__ */ jsx25(
7530
7552
  Div_default.box,
@@ -7900,6 +7922,7 @@ var FoldableComponent = forwardRef18(function Foldable({
7900
7922
  description,
7901
7923
  descriptionFontSize,
7902
7924
  descriptionColor,
7925
+ titleGap,
7903
7926
  textAlign,
7904
7927
  rightElement,
7905
7928
  lightMode,
@@ -7992,6 +8015,7 @@ var FoldableComponent = forwardRef18(function Foldable({
7992
8015
  description,
7993
8016
  descriptionFontSize,
7994
8017
  descriptionColor,
8018
+ titleGap,
7995
8019
  textAlign,
7996
8020
  rightElement,
7997
8021
  lightMode,
@@ -8604,7 +8628,7 @@ SideMenuComponent.pageHolder = function SideMenuPageHolder({
8604
8628
  }
8605
8629
  );
8606
8630
  };
8607
- SideMenuComponent.burgerButton = function BurgerButton({ position = "left", onClick }) {
8631
+ SideMenuComponent.burgerButton = function BurgerButton({ position = "left", color, onClick }) {
8608
8632
  const theme2 = useTheme29();
8609
8633
  const { sideMenuIsOpenMobile, setSideMenuIsOpenMobile } = useBetterHtmlContextInternal();
8610
8634
  const [isHovered, setIsHovered] = useBooleanState8();
@@ -8613,6 +8637,7 @@ SideMenuComponent.burgerButton = function BurgerButton({ position = "left", onCl
8613
8637
  onClick?.(!sideMenuIsOpenMobile);
8614
8638
  }, [onClick, sideMenuIsOpenMobile]);
8615
8639
  const width = 2;
8640
+ const backgroundColor = color ?? theme2.colors.border;
8616
8641
  return /* @__PURE__ */ jsxs24(
8617
8642
  Div_default,
8618
8643
  {
@@ -8634,7 +8659,7 @@ SideMenuComponent.burgerButton = function BurgerButton({ position = "left", onCl
8634
8659
  top: sideMenuIsOpenMobile ? `calc(50% - ${width / 2}px)` : 0,
8635
8660
  left: position === "left" ? 0 : position === "center" ? sideMenuIsOpenMobile ? 0 : "50%" : "auto",
8636
8661
  right: position === "right" ? 0 : void 0,
8637
- backgroundColor: theme2.colors.border,
8662
+ backgroundColor,
8638
8663
  borderRadius: 999,
8639
8664
  transform: sideMenuIsOpenMobile ? "rotate(45deg)" : position === "center" ? "translateX(-50%)" : void 0,
8640
8665
  transition: theme2.styles.transition
@@ -8649,7 +8674,7 @@ SideMenuComponent.burgerButton = function BurgerButton({ position = "left", onCl
8649
8674
  top: "50%",
8650
8675
  left: position === "left" ? 0 : position === "center" ? "50%" : "auto",
8651
8676
  right: position === "right" ? 0 : void 0,
8652
- backgroundColor: theme2.colors.border,
8677
+ backgroundColor,
8653
8678
  borderRadius: 999,
8654
8679
  transform: `translateY(-50%)${position === "center" ? " translateX(-50%)" : ""}`,
8655
8680
  opacity: sideMenuIsOpenMobile ? 0 : void 0,
@@ -8665,7 +8690,7 @@ SideMenuComponent.burgerButton = function BurgerButton({ position = "left", onCl
8665
8690
  bottom: sideMenuIsOpenMobile ? `calc(50% - ${width / 2}px)` : 0,
8666
8691
  left: position === "left" ? 0 : position === "center" ? sideMenuIsOpenMobile ? 0 : "50%" : "auto",
8667
8692
  right: position === "right" ? 0 : void 0,
8668
- backgroundColor: theme2.colors.border,
8693
+ backgroundColor,
8669
8694
  borderRadius: 999,
8670
8695
  transform: sideMenuIsOpenMobile ? "rotate(-45deg)" : position === "center" ? "translateX(-50%)" : void 0,
8671
8696
  transition: theme2.styles.transition