@sustaina/shared-ui 1.29.0 → 1.30.0

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
@@ -2726,6 +2726,16 @@ var LookupSelect = ({
2726
2726
  }
2727
2727
  };
2728
2728
  }, [inputValue, fetchSuggestions, suggestionDebounce, upsertOptionLabels]);
2729
+ React4.useEffect(() => {
2730
+ if (!fetchSuggestions) return;
2731
+ if (value.length === 0) return;
2732
+ const unresolvedValues = value.filter((v) => !optionLabels[v]);
2733
+ if (unresolvedValues.length === 0) return;
2734
+ fetchSuggestions("").then((options) => {
2735
+ upsertOptionLabels(options);
2736
+ }).catch(() => {
2737
+ });
2738
+ }, [value, fetchSuggestions, optionLabels, upsertOptionLabels]);
2729
2739
  React4.useEffect(() => {
2730
2740
  const handleDocumentClick = (event) => {
2731
2741
  const target = event.target;
@@ -9824,27 +9834,51 @@ var CropperModal = ({
9824
9834
  }
9825
9835
  );
9826
9836
  };
9827
- var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9837
+ var Truncated = ({
9838
+ children,
9839
+ className,
9840
+ ellipsis = true,
9841
+ as = "p",
9842
+ style,
9843
+ tooltipProps,
9844
+ tooltipContentProps
9845
+ }) => {
9828
9846
  const elementRef = React4.useRef(null);
9829
9847
  const [open, setOpen] = React4.useState(false);
9830
9848
  const [isTruncated, setIsTruncated] = React4.useState(false);
9831
9849
  const Comp = as;
9832
9850
  const normalizedChildren = typeof children === "string" ? children.replace(/>/g, ">\u200B") : children;
9851
+ const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis?.lineClamp ?? 3 : null;
9833
9852
  React4.useEffect(() => {
9834
9853
  const el = elementRef.current;
9835
9854
  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);
9855
+ const measure = () => {
9856
+ if (!ellipsis) {
9857
+ setIsTruncated(false);
9858
+ return;
9859
+ }
9860
+ const rect = el.getBoundingClientRect();
9861
+ const width = el.clientWidth || el.offsetWidth || rect.width;
9862
+ const height = el.clientHeight || el.offsetHeight || rect.height;
9863
+ if (!width || !height) {
9864
+ setIsTruncated(false);
9865
+ return;
9866
+ }
9867
+ const epsilon = 1;
9868
+ const overflowWidth = el.scrollWidth - width > epsilon;
9869
+ const overflowHeight = el.scrollHeight - height > epsilon;
9870
+ setIsTruncated(overflowWidth || overflowHeight);
9871
+ };
9872
+ const resizeObserver = new ResizeObserver(() => requestAnimationFrame(measure));
9842
9873
  resizeObserver.observe(el);
9874
+ const mutationObserver = new MutationObserver(() => measure());
9875
+ mutationObserver.observe(el, { childList: true, subtree: true, characterData: true });
9876
+ requestAnimationFrame(measure);
9843
9877
  return () => {
9844
9878
  resizeObserver.disconnect();
9879
+ mutationObserver.disconnect();
9845
9880
  };
9846
- }, []);
9847
- const lineClampLines = typeof ellipsis === "number" ? ellipsis : typeof ellipsis === "object" ? ellipsis.lineClamp ?? 3 : null;
9881
+ }, [children, ellipsis, lineClampLines]);
9848
9882
  const truncationClass = React4.useMemo(() => {
9849
9883
  if (!ellipsis) return "";
9850
9884
  if (typeof ellipsis === "number") return `line-clamp-${ellipsis}`;
@@ -9863,14 +9897,20 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9863
9897
  }, [lineClampLines, style]);
9864
9898
  const baseContent = /* @__PURE__ */ jsxRuntime.jsx(Comp, { ref: elementRef, className: cn(truncationClass, className), style: clampedStyle, children: normalizedChildren });
9865
9899
  let tooltipContent = normalizedChildren;
9866
- let tooltipSide = "top";
9867
9900
  if (typeof ellipsis === "object") {
9868
9901
  tooltipContent = ellipsis?.content ?? normalizedChildren;
9869
- tooltipSide = ellipsis?.side ?? "top";
9870
9902
  }
9903
+ const {
9904
+ className: tooltipContentClassName,
9905
+ arrowClassName: tooltipArrowClassName,
9906
+ side: tooltipContentSide,
9907
+ ...tooltipContentRest
9908
+ } = tooltipContentProps ?? {};
9909
+ const tooltipSide = (typeof ellipsis === "object" ? ellipsis?.side : void 0) ?? tooltipContentSide ?? "top";
9871
9910
  return /* @__PURE__ */ jsxRuntime.jsxs(
9872
9911
  Tooltip2,
9873
9912
  {
9913
+ ...tooltipProps,
9874
9914
  open,
9875
9915
  onOpenChange: (open2) => {
9876
9916
  setOpen(isTruncated && open2);
@@ -9881,8 +9921,12 @@ var Truncated = ({ children, className, ellipsis = true, as = "p", style }) => {
9881
9921
  TooltipContent2,
9882
9922
  {
9883
9923
  side: tooltipSide,
9884
- className: cn("text-white bg-[#8B8B8B] max-w-md wrap-break-word shadow-lg"),
9885
- arrowClassName: "bg-[#8B8B8B] fill-[#8B8B8B]",
9924
+ className: cn(
9925
+ "text-white bg-[#8B8B8B] max-w-xs sm:max-w-md wrap-break-word shadow-lg",
9926
+ tooltipContentClassName
9927
+ ),
9928
+ arrowClassName: cn("bg-[#8B8B8B] fill-[#8B8B8B]", tooltipArrowClassName),
9929
+ ...tooltipContentRest,
9886
9930
  children: tooltipContent
9887
9931
  }
9888
9932
  )