@sustaina/shared-ui 1.29.0 → 1.29.1

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
@@ -9784,27 +9784,51 @@ var CropperModal = ({
9784
9784
  }
9785
9785
  );
9786
9786
  };
9787
- var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9787
+ var Truncated = ({
9788
+ children,
9789
+ className,
9790
+ ellipsis = true,
9791
+ as = "p",
9792
+ style,
9793
+ tooltipProps,
9794
+ tooltipContentProps
9795
+ }) => {
9788
9796
  const elementRef = useRef(null);
9789
9797
  const [open, setOpen] = useState(false);
9790
9798
  const [isTruncated, setIsTruncated] = useState(false);
9791
9799
  const Comp = as;
9792
9800
  const normalizedChildren = typeof children === "string" ? children.replace(/>/g, ">\u200B") : children;
9801
+ const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis?.lineClamp ?? 3 : null;
9793
9802
  useEffect(() => {
9794
9803
  const el = elementRef.current;
9795
9804
  if (!el) return;
9796
- const checkTruncate = debounce(() => {
9797
- const overflowX = el.scrollWidth > el.clientWidth;
9798
- const overflowY = el.scrollHeight > el.clientHeight;
9799
- setIsTruncated(overflowX || overflowY);
9800
- }, 300);
9801
- const resizeObserver = new ResizeObserver(checkTruncate);
9805
+ const measure = () => {
9806
+ if (!ellipsis) {
9807
+ setIsTruncated(false);
9808
+ return;
9809
+ }
9810
+ const rect = el.getBoundingClientRect();
9811
+ const width = el.clientWidth || el.offsetWidth || rect.width;
9812
+ const height = el.clientHeight || el.offsetHeight || rect.height;
9813
+ if (!width || !height) {
9814
+ setIsTruncated(false);
9815
+ return;
9816
+ }
9817
+ const epsilon = 1;
9818
+ const overflowWidth = el.scrollWidth - width > epsilon;
9819
+ const overflowHeight = el.scrollHeight - height > epsilon;
9820
+ setIsTruncated(overflowWidth || overflowHeight);
9821
+ };
9822
+ const resizeObserver = new ResizeObserver(() => requestAnimationFrame(measure));
9802
9823
  resizeObserver.observe(el);
9824
+ const mutationObserver = new MutationObserver(() => measure());
9825
+ mutationObserver.observe(el, { childList: true, subtree: true, characterData: true });
9826
+ requestAnimationFrame(measure);
9803
9827
  return () => {
9804
9828
  resizeObserver.disconnect();
9829
+ mutationObserver.disconnect();
9805
9830
  };
9806
- }, []);
9807
- const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis.lineClamp ?? 3 : null;
9831
+ }, [children, ellipsis, lineClampLines]);
9808
9832
  const truncationClass = useMemo(() => {
9809
9833
  if (!ellipsis) return "";
9810
9834
  if (typeof ellipsis === "number") return `line-clamp-${ellipsis}`;
@@ -9823,14 +9847,20 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9823
9847
  }, [lineClampLines, style]);
9824
9848
  const baseContent = /* @__PURE__ */ jsx(Comp, { ref: elementRef, className: cn(truncationClass, className), style: clampedStyle, children: normalizedChildren });
9825
9849
  let tooltipContent = normalizedChildren;
9826
- let tooltipSide = "top";
9827
9850
  if (typeof ellipsis === "object") {
9828
9851
  tooltipContent = ellipsis?.content ?? normalizedChildren;
9829
- tooltipSide = ellipsis?.side ?? "top";
9830
9852
  }
9853
+ const {
9854
+ className: tooltipContentClassName,
9855
+ arrowClassName: tooltipArrowClassName,
9856
+ side: tooltipContentSide,
9857
+ ...tooltipContentRest
9858
+ } = tooltipContentProps ?? {};
9859
+ const tooltipSide = (typeof ellipsis === "object" ? ellipsis?.side : void 0) ?? tooltipContentSide ?? "top";
9831
9860
  return /* @__PURE__ */ jsxs(
9832
9861
  Tooltip2,
9833
9862
  {
9863
+ ...tooltipProps,
9834
9864
  open,
9835
9865
  onOpenChange: (open2) => {
9836
9866
  setOpen(isTruncated && open2);
@@ -9841,8 +9871,12 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9841
9871
  TooltipContent2,
9842
9872
  {
9843
9873
  side: tooltipSide,
9844
- className: cn("text-white bg-[#8B8B8B] max-w-md wrap-break-word shadow-lg"),
9845
- arrowClassName: "bg-[#8B8B8B] fill-[#8B8B8B]",
9874
+ className: cn(
9875
+ "text-white bg-[#8B8B8B] max-w-xs sm:max-w-md wrap-break-word shadow-lg",
9876
+ tooltipContentClassName
9877
+ ),
9878
+ arrowClassName: cn("bg-[#8B8B8B] fill-[#8B8B8B]", tooltipArrowClassName),
9879
+ ...tooltipContentRest,
9846
9880
  children: tooltipContent
9847
9881
  }
9848
9882
  )