@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.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React$1 from 'react';
3
- import React__default, { CSSProperties, ReactNode, SVGProps } from 'react';
3
+ import React__default, { CSSProperties, ReactNode, SVGProps, ComponentProps } from 'react';
4
4
  import * as AccordionPrimitive from '@radix-ui/react-accordion';
5
5
  import { ClassValue } from 'clsx';
6
6
  import * as class_variance_authority_dist_types from 'class-variance-authority/dist/types';
@@ -1283,8 +1283,10 @@ type TruncatedProps = {
1283
1283
  children: ReactNode;
1284
1284
  as?: keyof React__default.JSX.IntrinsicElements;
1285
1285
  style?: CSSProperties;
1286
+ tooltipProps?: Omit<ComponentProps<typeof Tooltip$1>, "open" | "onOpenChange">;
1287
+ tooltipContentProps?: Omit<ComponentProps<typeof TooltipContent$1>, "children">;
1286
1288
  };
1287
- declare const Truncated: ({ children, className, ellipsis, as, style }: TruncatedProps) => react_jsx_runtime.JSX.Element;
1289
+ declare const Truncated: ({ children, className, ellipsis, as, style, tooltipProps, tooltipContentProps }: TruncatedProps) => react_jsx_runtime.JSX.Element;
1288
1290
 
1289
1291
  type InputPrimitiveProps = React$1.InputHTMLAttributes<HTMLInputElement>;
1290
1292
  declare const inputVariants: (props?: ({
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React$1 from 'react';
3
- import React__default, { CSSProperties, ReactNode, SVGProps } from 'react';
3
+ import React__default, { CSSProperties, ReactNode, SVGProps, ComponentProps } from 'react';
4
4
  import * as AccordionPrimitive from '@radix-ui/react-accordion';
5
5
  import { ClassValue } from 'clsx';
6
6
  import * as class_variance_authority_dist_types from 'class-variance-authority/dist/types';
@@ -1283,8 +1283,10 @@ type TruncatedProps = {
1283
1283
  children: ReactNode;
1284
1284
  as?: keyof React__default.JSX.IntrinsicElements;
1285
1285
  style?: CSSProperties;
1286
+ tooltipProps?: Omit<ComponentProps<typeof Tooltip$1>, "open" | "onOpenChange">;
1287
+ tooltipContentProps?: Omit<ComponentProps<typeof TooltipContent$1>, "children">;
1286
1288
  };
1287
- declare const Truncated: ({ children, className, ellipsis, as, style }: TruncatedProps) => react_jsx_runtime.JSX.Element;
1289
+ declare const Truncated: ({ children, className, ellipsis, as, style, tooltipProps, tooltipContentProps }: TruncatedProps) => react_jsx_runtime.JSX.Element;
1288
1290
 
1289
1291
  type InputPrimitiveProps = React$1.InputHTMLAttributes<HTMLInputElement>;
1290
1292
  declare const inputVariants: (props?: ({
package/dist/index.js CHANGED
@@ -9824,27 +9824,51 @@ var CropperModal = ({
9824
9824
  }
9825
9825
  );
9826
9826
  };
9827
- var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9827
+ var Truncated = ({
9828
+ children,
9829
+ className,
9830
+ ellipsis = true,
9831
+ as = "p",
9832
+ style,
9833
+ tooltipProps,
9834
+ tooltipContentProps
9835
+ }) => {
9828
9836
  const elementRef = React4.useRef(null);
9829
9837
  const [open, setOpen] = React4.useState(false);
9830
9838
  const [isTruncated, setIsTruncated] = React4.useState(false);
9831
9839
  const Comp = as;
9832
9840
  const normalizedChildren = typeof children === "string" ? children.replace(/>/g, ">\u200B") : children;
9841
+ const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis?.lineClamp ?? 3 : null;
9833
9842
  React4.useEffect(() => {
9834
9843
  const el = elementRef.current;
9835
9844
  if (!el) return;
9836
- const checkTruncate = debounce(() => {
9837
- const overflowX = el.scrollWidth > el.clientWidth;
9838
- const overflowY = el.scrollHeight > el.clientHeight;
9839
- setIsTruncated(overflowX || overflowY);
9840
- }, 300);
9841
- const resizeObserver = new ResizeObserver(checkTruncate);
9845
+ const measure = () => {
9846
+ if (!ellipsis) {
9847
+ setIsTruncated(false);
9848
+ return;
9849
+ }
9850
+ const rect = el.getBoundingClientRect();
9851
+ const width = el.clientWidth || el.offsetWidth || rect.width;
9852
+ const height = el.clientHeight || el.offsetHeight || rect.height;
9853
+ if (!width || !height) {
9854
+ setIsTruncated(false);
9855
+ return;
9856
+ }
9857
+ const epsilon = 1;
9858
+ const overflowWidth = el.scrollWidth - width > epsilon;
9859
+ const overflowHeight = el.scrollHeight - height > epsilon;
9860
+ setIsTruncated(overflowWidth || overflowHeight);
9861
+ };
9862
+ const resizeObserver = new ResizeObserver(() => requestAnimationFrame(measure));
9842
9863
  resizeObserver.observe(el);
9864
+ const mutationObserver = new MutationObserver(() => measure());
9865
+ mutationObserver.observe(el, { childList: true, subtree: true, characterData: true });
9866
+ requestAnimationFrame(measure);
9843
9867
  return () => {
9844
9868
  resizeObserver.disconnect();
9869
+ mutationObserver.disconnect();
9845
9870
  };
9846
- }, []);
9847
- const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis.lineClamp ?? 3 : null;
9871
+ }, [children, ellipsis, lineClampLines]);
9848
9872
  const truncationClass = React4.useMemo(() => {
9849
9873
  if (!ellipsis) return "";
9850
9874
  if (typeof ellipsis === "number") return `line-clamp-${ellipsis}`;
@@ -9863,14 +9887,20 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9863
9887
  }, [lineClampLines, style]);
9864
9888
  const baseContent = /* @__PURE__ */ jsxRuntime.jsx(Comp, { ref: elementRef, className: cn(truncationClass, className), style: clampedStyle, children: normalizedChildren });
9865
9889
  let tooltipContent = normalizedChildren;
9866
- let tooltipSide = "top";
9867
9890
  if (typeof ellipsis === "object") {
9868
9891
  tooltipContent = ellipsis?.content ?? normalizedChildren;
9869
- tooltipSide = ellipsis?.side ?? "top";
9870
9892
  }
9893
+ const {
9894
+ className: tooltipContentClassName,
9895
+ arrowClassName: tooltipArrowClassName,
9896
+ side: tooltipContentSide,
9897
+ ...tooltipContentRest
9898
+ } = tooltipContentProps ?? {};
9899
+ const tooltipSide = (typeof ellipsis === "object" ? ellipsis?.side : void 0) ?? tooltipContentSide ?? "top";
9871
9900
  return /* @__PURE__ */ jsxRuntime.jsxs(
9872
9901
  Tooltip2,
9873
9902
  {
9903
+ ...tooltipProps,
9874
9904
  open,
9875
9905
  onOpenChange: (open2) => {
9876
9906
  setOpen(isTruncated && open2);
@@ -9881,8 +9911,12 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9881
9911
  TooltipContent2,
9882
9912
  {
9883
9913
  side: tooltipSide,
9884
- className: cn("text-white bg-[#8B8B8B] max-w-md wrap-break-word shadow-lg"),
9885
- arrowClassName: "bg-[#8B8B8B] fill-[#8B8B8B]",
9914
+ className: cn(
9915
+ "text-white bg-[#8B8B8B] max-w-xs sm:max-w-md wrap-break-word shadow-lg",
9916
+ tooltipContentClassName
9917
+ ),
9918
+ arrowClassName: cn("bg-[#8B8B8B] fill-[#8B8B8B]", tooltipArrowClassName),
9919
+ ...tooltipContentRest,
9886
9920
  children: tooltipContent
9887
9921
  }
9888
9922
  )