periplo-ui 3.37.0 → 3.38.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.
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useRef, useState, useEffect } from 'react';
|
|
3
3
|
import { cn } from '../../lib/utils.js';
|
|
4
|
+
import { Popover } from '../Popover/Popover.js';
|
|
4
5
|
import { TooltipProvider, TooltipRoot, TooltipTrigger, TooltipContent } from '../Tooltip/Tooltip.js';
|
|
5
6
|
import { Typography } from '../Typography/Typography.js';
|
|
7
|
+
import { useIsMobile } from '../../lib/useMobile.js';
|
|
6
8
|
|
|
7
9
|
const TruncatedTypographyWithTooltip = ({ label, ...props }) => {
|
|
8
10
|
const textRef = useRef(null);
|
|
11
|
+
const isMobile = useIsMobile();
|
|
9
12
|
const [isTruncated, setIsTruncated] = useState(false);
|
|
10
13
|
useEffect(() => {
|
|
11
14
|
const checkTruncation = () => {
|
|
@@ -20,7 +23,15 @@ const TruncatedTypographyWithTooltip = ({ label, ...props }) => {
|
|
|
20
23
|
window.removeEventListener("resize", checkTruncation);
|
|
21
24
|
};
|
|
22
25
|
}, [label]);
|
|
23
|
-
return
|
|
26
|
+
return isMobile && isTruncated ? /* @__PURE__ */ jsx(
|
|
27
|
+
Popover,
|
|
28
|
+
{
|
|
29
|
+
side: "top",
|
|
30
|
+
triggerElement: /* @__PURE__ */ jsx(Typography, { ...props, ref: textRef, className: cn(props.className, "truncate"), children: label }),
|
|
31
|
+
...props,
|
|
32
|
+
children: label
|
|
33
|
+
}
|
|
34
|
+
) : /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(TooltipRoot, { delayDuration: 500, children: [
|
|
24
35
|
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Typography, { ...props, ref: textRef, className: cn(props.className, "truncate"), children: label }) }),
|
|
25
36
|
isTruncated && /* @__PURE__ */ jsx(TooltipContent, { children: label })
|
|
26
37
|
] }) });
|
package/dist/components/TruncatedTypographyWithTooltip/TruncatedTypographyWithTooltip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TruncatedTypographyWithTooltip.js","sources":["../../../src/components/TruncatedTypographyWithTooltip/TruncatedTypographyWithTooltip.tsx"],"sourcesContent":["import { ComponentProps, useEffect, useRef, useState } from 'react'\n\nimport { cn } from '../../lib/utils'\nimport { TooltipContent, TooltipProvider, TooltipRoot, TooltipTrigger } from '../Tooltip'\nimport { Typography } from '../Typography'\n\ntype TruncatedTypographyWithTooltipProps = {\n label: string\n} & Omit<ComponentProps<typeof Typography>, 'children'>\n\nexport const TruncatedTypographyWithTooltip = ({ label, ...props }: TruncatedTypographyWithTooltipProps) => {\n const textRef = useRef<HTMLParagraphElement>(null)\n const [isTruncated, setIsTruncated] = useState(false)\n\n useEffect(() => {\n const checkTruncation = () => {\n if (textRef.current) {\n setIsTruncated(textRef.current.scrollWidth > textRef.current.clientWidth)\n }\n }\n\n const frame = requestAnimationFrame(checkTruncation)\n window.addEventListener('resize', checkTruncation)\n\n return () => {\n cancelAnimationFrame(frame)\n window.removeEventListener('resize', checkTruncation)\n }\n }, [label])\n\n return (\n <TooltipProvider>\n <TooltipRoot delayDuration={500}>\n <TooltipTrigger asChild>\n <Typography {...props} ref={textRef} className={cn(props.className, 'truncate')}>\n {label}\n </Typography>\n </TooltipTrigger>\n {isTruncated && <TooltipContent>{label}</TooltipContent>}\n </TooltipRoot>\n </TooltipProvider>\n )\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TruncatedTypographyWithTooltip.js","sources":["../../../src/components/TruncatedTypographyWithTooltip/TruncatedTypographyWithTooltip.tsx"],"sourcesContent":["import { ComponentProps, useEffect, useRef, useState } from 'react'\n\nimport { cn } from '../../lib/utils'\nimport { Popover } from '../Popover'\nimport { TooltipContent, TooltipProvider, TooltipRoot, TooltipTrigger } from '../Tooltip'\nimport { Typography } from '../Typography'\n\nimport { useIsMobile } from '@/lib/useMobile'\n\ntype TruncatedTypographyWithTooltipProps = {\n label: string\n} & Omit<ComponentProps<typeof Typography>, 'children'>\n\nexport const TruncatedTypographyWithTooltip = ({ label, ...props }: TruncatedTypographyWithTooltipProps) => {\n const textRef = useRef<HTMLParagraphElement>(null)\n const isMobile = useIsMobile()\n const [isTruncated, setIsTruncated] = useState(false)\n\n useEffect(() => {\n const checkTruncation = () => {\n if (textRef.current) {\n setIsTruncated(textRef.current.scrollWidth > textRef.current.clientWidth)\n }\n }\n\n const frame = requestAnimationFrame(checkTruncation)\n window.addEventListener('resize', checkTruncation)\n\n return () => {\n cancelAnimationFrame(frame)\n window.removeEventListener('resize', checkTruncation)\n }\n }, [label])\n\n return isMobile && isTruncated ? (\n <Popover\n side=\"top\"\n triggerElement={\n <Typography {...props} ref={textRef} className={cn(props.className, 'truncate')}>\n {label}\n </Typography>\n }\n {...props}\n >\n {label}\n </Popover>\n ) : (\n <TooltipProvider>\n <TooltipRoot delayDuration={500}>\n <TooltipTrigger asChild>\n <Typography {...props} ref={textRef} className={cn(props.className, 'truncate')}>\n {label}\n </Typography>\n </TooltipTrigger>\n {isTruncated && <TooltipContent>{label}</TooltipContent>}\n </TooltipRoot>\n </TooltipProvider>\n )\n}\n"],"names":[],"mappings":";;;;;;;;AAaO,MAAM,iCAAiC,CAAC,EAAE,KAAA,EAAO,GAAG,OAAM,KAA2C;AAC1G,EAAA,MAAM,OAAA,GAAU,OAA6B,IAAI,CAAA;AACjD,EAAA,MAAM,WAAW,WAAA,EAAY;AAC7B,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,SAAS,KAAK,CAAA;AAEpD,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAM,kBAAkB,MAAM;AAC5B,MAAA,IAAI,QAAQ,OAAA,EAAS;AACnB,QAAA,cAAA,CAAe,OAAA,CAAQ,OAAA,CAAQ,W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