@dxos/react-ui-text-tooltip 0.6.7 → 0.6.8-main.3be982f
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/lib/browser/index.mjs +4 -2
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextTooltip.d.ts +10 -8
- package/dist/types/src/components/TextTooltip.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/components/TextTooltip.tsx +29 -5
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
3
3
|
import React, { forwardRef, Fragment, useRef, useState } from "react";
|
|
4
4
|
import { Tooltip } from "@dxos/react-ui";
|
|
5
|
-
var TextTooltip = /* @__PURE__ */ forwardRef(({ text, children, onlyWhenTruncating, asChild = true, portal = true, zIndex = 70, sideOffset, side }, forwardedRef) => {
|
|
5
|
+
var TextTooltip = /* @__PURE__ */ forwardRef(({ text, children, onlyWhenTruncating, asChild = true, portal = true, zIndex = 70, sideOffset, side, truncateQuery, ...props }, forwardedRef) => {
|
|
6
6
|
const ContentRoot = portal ? Tooltip.Portal : Fragment;
|
|
7
7
|
const content = useRef(null);
|
|
8
8
|
const ref = useComposedRefs(content, forwardedRef);
|
|
@@ -11,13 +11,15 @@ var TextTooltip = /* @__PURE__ */ forwardRef(({ text, children, onlyWhenTruncati
|
|
|
11
11
|
open,
|
|
12
12
|
onOpenChange: (nextOpen) => {
|
|
13
13
|
if (onlyWhenTruncating && nextOpen && content.current) {
|
|
14
|
-
|
|
14
|
+
const element = truncateQuery ? content.current.querySelector(truncateQuery) : content.current;
|
|
15
|
+
return setOpen(element ? element.scrollWidth > element.offsetWidth : false);
|
|
15
16
|
} else {
|
|
16
17
|
return setOpen(nextOpen);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
}, /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
20
21
|
asChild,
|
|
22
|
+
...props,
|
|
21
23
|
ref
|
|
22
24
|
}, children), /* @__PURE__ */ React.createElement(ContentRoot, null, /* @__PURE__ */ React.createElement(Tooltip.Content, {
|
|
23
25
|
side,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/TextTooltip.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport React, { type CSSProperties
|
|
5
|
-
"mappings": ";AAIA,SAASA,uBAAuB;AAChC,OAAOC,
|
|
6
|
-
"names": ["useComposedRefs", "React", "forwardRef", "Fragment", "useRef", "useState", "Tooltip", "TextTooltip", "forwardRef", "text", "children", "onlyWhenTruncating", "asChild", "portal", "zIndex", "sideOffset", "side", "forwardedRef", "ContentRoot", "Tooltip", "Portal", "Fragment", "content", "useRef", "ref", "useComposedRefs", "open", "setOpen", "useState", "Root", "onOpenChange", "nextOpen", "current", "scrollWidth", "offsetWidth", "Trigger", "Content", "style", "Arrow"]
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport React, {\n type ComponentPropsWithoutRef,\n type CSSProperties,\n forwardRef,\n Fragment,\n type PropsWithChildren,\n useRef,\n useState,\n} from 'react';\n\nimport { Tooltip, type TooltipContentProps } from '@dxos/react-ui';\n\nexport type TextTooltipProps = PropsWithChildren<\n {\n text: string;\n asChild?: boolean;\n portal?: boolean;\n zIndex?: CSSProperties['zIndex'];\n onlyWhenTruncating?: boolean;\n truncateQuery?: string;\n } & Pick<TooltipContentProps, 'side' | 'sideOffset'> &\n ComponentPropsWithoutRef<'button'>\n>;\n\nexport const TextTooltip = forwardRef<HTMLButtonElement, TextTooltipProps>(\n (\n {\n text,\n children,\n onlyWhenTruncating,\n asChild = true,\n portal = true,\n zIndex = 70,\n sideOffset,\n side,\n truncateQuery,\n ...props\n },\n forwardedRef,\n ) => {\n const ContentRoot = portal ? Tooltip.Portal : Fragment;\n const content = useRef<HTMLButtonElement | null>(null);\n const ref = useComposedRefs(content, forwardedRef);\n const [open, setOpen] = useState(false);\n return (\n <Tooltip.Root\n open={open}\n onOpenChange={(nextOpen) => {\n if (onlyWhenTruncating && nextOpen && content.current) {\n const element: HTMLElement | null = truncateQuery\n ? content.current.querySelector(truncateQuery)\n : content.current;\n return setOpen(element ? element.scrollWidth > element.offsetWidth : false);\n } else {\n return setOpen(nextOpen);\n }\n }}\n >\n <Tooltip.Trigger asChild={asChild} {...props} ref={ref}>\n {children}\n </Tooltip.Trigger>\n <ContentRoot>\n <Tooltip.Content\n {...{\n side,\n sideOffset,\n style: { zIndex },\n }}\n >\n {text}\n <Tooltip.Arrow />\n </Tooltip.Content>\n </ContentRoot>\n </Tooltip.Root>\n );\n },\n);\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,uBAAuB;AAChC,OAAOC,SAGLC,YACAC,UAEAC,QACAC,gBACK;AAEP,SAASC,eAAyC;AAc3C,IAAMC,cAAcC,2BACzB,CACE,EACEC,MACAC,UACAC,oBACAC,UAAU,MACVC,SAAS,MACTC,SAAS,IACTC,YACAC,MACAC,eACA,GAAGC,MAAAA,GAELC,iBAAAA;AAEA,QAAMC,cAAcP,SAASQ,QAAQC,SAASC;AAC9C,QAAMC,UAAUC,OAAiC,IAAA;AACjD,QAAMC,MAAMC,gBAAgBH,SAASL,YAAAA;AACrC,QAAM,CAACS,MAAMC,OAAAA,IAAWC,SAAS,KAAA;AACjC,SACE,sBAAA,cAACT,QAAQU,MAAI;IACXH;IACAI,cAAc,CAACC,aAAAA;AACb,UAAItB,sBAAsBsB,YAAYT,QAAQU,SAAS;AACrD,cAAMC,UAA8BlB,gBAChCO,QAAQU,QAAQE,cAAcnB,aAAAA,IAC9BO,QAAQU;AACZ,eAAOL,QAAQM,UAAUA,QAAQE,cAAcF,QAAQG,cAAc,KAAA;MACvE,OAAO;AACL,eAAOT,QAAQI,QAAAA;MACjB;IACF;KAEA,sBAAA,cAACZ,QAAQkB,SAAO;IAAC3B;IAAmB,GAAGM;IAAOQ;KAC3ChB,QAAAA,GAEH,sBAAA,cAACU,aAAAA,MACC,sBAAA,cAACC,QAAQmB,SACH;IACFxB;IACAD;IACA0B,OAAO;MAAE3B;IAAO;EAClB,GAECL,MACD,sBAAA,cAACY,QAAQqB,OAAK,IAAA,CAAA,CAAA,CAAA;AAKxB,CAAA;",
|
|
6
|
+
"names": ["useComposedRefs", "React", "forwardRef", "Fragment", "useRef", "useState", "Tooltip", "TextTooltip", "forwardRef", "text", "children", "onlyWhenTruncating", "asChild", "portal", "zIndex", "sideOffset", "side", "truncateQuery", "props", "forwardedRef", "ContentRoot", "Tooltip", "Portal", "Fragment", "content", "useRef", "ref", "useComposedRefs", "open", "setOpen", "useState", "Root", "onOpenChange", "nextOpen", "current", "element", "querySelector", "scrollWidth", "offsetWidth", "Trigger", "Content", "style", "Arrow"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/react-ui-text-tooltip/src/components/TextTooltip.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/react-ui-text-tooltip/src/components/TextTooltip.tsx":{"bytes":6535,"imports":[{"path":"@radix-ui/react-compose-refs","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"format":"esm"},"packages/ui/react-ui-text-tooltip/src/components/index.ts":{"bytes":527,"imports":[{"path":"packages/ui/react-ui-text-tooltip/src/components/TextTooltip.tsx","kind":"import-statement","original":"./TextTooltip"}],"format":"esm"},"packages/ui/react-ui-text-tooltip/src/index.ts":{"bytes":511,"imports":[{"path":"packages/ui/react-ui-text-tooltip/src/components/index.ts","kind":"import-statement","original":"./components"}],"format":"esm"}},"outputs":{"packages/ui/react-ui-text-tooltip/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3671},"packages/ui/react-ui-text-tooltip/dist/lib/browser/index.mjs":{"imports":[{"path":"@radix-ui/react-compose-refs","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"exports":["TextTooltip"],"entryPoint":"packages/ui/react-ui-text-tooltip/src/index.ts","inputs":{"packages/ui/react-ui-text-tooltip/src/components/TextTooltip.tsx":{"bytesInOutput":1331},"packages/ui/react-ui-text-tooltip/src/components/index.ts":{"bytesInOutput":0},"packages/ui/react-ui-text-tooltip/src/index.ts":{"bytesInOutput":0}},"bytes":1460}}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { type CSSProperties, type PropsWithChildren } from 'react';
|
|
1
|
+
import React, { type ComponentPropsWithoutRef, type CSSProperties, type PropsWithChildren } from 'react';
|
|
2
2
|
import { type TooltipContentProps } from '@dxos/react-ui';
|
|
3
3
|
export type TextTooltipProps = PropsWithChildren<{
|
|
4
4
|
text: string;
|
|
@@ -6,14 +6,16 @@ export type TextTooltipProps = PropsWithChildren<{
|
|
|
6
6
|
portal?: boolean;
|
|
7
7
|
zIndex?: CSSProperties['zIndex'];
|
|
8
8
|
onlyWhenTruncating?: boolean;
|
|
9
|
-
|
|
9
|
+
truncateQuery?: string;
|
|
10
|
+
} & Pick<TooltipContentProps, 'side' | 'sideOffset'> & ComponentPropsWithoutRef<'button'>>;
|
|
10
11
|
export declare const TextTooltip: React.ForwardRefExoticComponent<{
|
|
11
12
|
text: string;
|
|
12
|
-
asChild?: boolean
|
|
13
|
-
portal?: boolean
|
|
14
|
-
zIndex?: CSSProperties[
|
|
15
|
-
onlyWhenTruncating?: boolean
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
asChild?: boolean;
|
|
14
|
+
portal?: boolean;
|
|
15
|
+
zIndex?: CSSProperties["zIndex"];
|
|
16
|
+
onlyWhenTruncating?: boolean;
|
|
17
|
+
truncateQuery?: string;
|
|
18
|
+
} & Pick<TooltipContentProps, "side" | "sideOffset"> & Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
|
19
|
+
children?: React.ReactNode | undefined;
|
|
18
20
|
} & React.RefAttributes<HTMLButtonElement>>;
|
|
19
21
|
//# sourceMappingURL=TextTooltip.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextTooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/TextTooltip.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"TextTooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/TextTooltip.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EACZ,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAGlB,KAAK,iBAAiB,EAGvB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAW,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAC9C;IACE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,IAAI,CAAC,mBAAmB,EAAE,MAAM,GAAG,YAAY,CAAC,GAClD,wBAAwB,CAAC,QAAQ,CAAC,CACrC,CAAC;AAEF,eAAO,MAAM,WAAW;UAVd,MAAM;cACF,OAAO;aACR,OAAO;aACP,aAAa,CAAC,QAAQ,CAAC;yBACX,OAAO;oBACZ,MAAM;;;2CAyDzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-text-tooltip",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8-main.3be982f",
|
|
4
4
|
"description": "An opinionated card component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@radix-ui/react-compose-refs": "^1.0.0",
|
|
25
|
-
"@dxos/react-ui": "0.6.
|
|
26
|
-
"@dxos/react-ui-theme": "0.6.
|
|
25
|
+
"@dxos/react-ui": "0.6.8-main.3be982f",
|
|
26
|
+
"@dxos/react-ui-theme": "0.6.8-main.3be982f"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@phosphor-icons/react": "^2.1.5",
|
|
30
|
-
"@types/react": "
|
|
31
|
-
"@types/react-dom": "
|
|
30
|
+
"@types/react": "~18.2.0",
|
|
31
|
+
"@types/react-dom": "~18.2.0",
|
|
32
32
|
"react": "~18.2.0",
|
|
33
33
|
"react-dom": "~18.2.0",
|
|
34
34
|
"vite": "^5.3.4"
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { useComposedRefs } from '@radix-ui/react-compose-refs';
|
|
6
|
-
import React, {
|
|
6
|
+
import React, {
|
|
7
|
+
type ComponentPropsWithoutRef,
|
|
8
|
+
type CSSProperties,
|
|
9
|
+
forwardRef,
|
|
10
|
+
Fragment,
|
|
11
|
+
type PropsWithChildren,
|
|
12
|
+
useRef,
|
|
13
|
+
useState,
|
|
14
|
+
} from 'react';
|
|
7
15
|
|
|
8
16
|
import { Tooltip, type TooltipContentProps } from '@dxos/react-ui';
|
|
9
17
|
|
|
@@ -14,12 +22,25 @@ export type TextTooltipProps = PropsWithChildren<
|
|
|
14
22
|
portal?: boolean;
|
|
15
23
|
zIndex?: CSSProperties['zIndex'];
|
|
16
24
|
onlyWhenTruncating?: boolean;
|
|
17
|
-
|
|
25
|
+
truncateQuery?: string;
|
|
26
|
+
} & Pick<TooltipContentProps, 'side' | 'sideOffset'> &
|
|
27
|
+
ComponentPropsWithoutRef<'button'>
|
|
18
28
|
>;
|
|
19
29
|
|
|
20
30
|
export const TextTooltip = forwardRef<HTMLButtonElement, TextTooltipProps>(
|
|
21
31
|
(
|
|
22
|
-
{
|
|
32
|
+
{
|
|
33
|
+
text,
|
|
34
|
+
children,
|
|
35
|
+
onlyWhenTruncating,
|
|
36
|
+
asChild = true,
|
|
37
|
+
portal = true,
|
|
38
|
+
zIndex = 70,
|
|
39
|
+
sideOffset,
|
|
40
|
+
side,
|
|
41
|
+
truncateQuery,
|
|
42
|
+
...props
|
|
43
|
+
},
|
|
23
44
|
forwardedRef,
|
|
24
45
|
) => {
|
|
25
46
|
const ContentRoot = portal ? Tooltip.Portal : Fragment;
|
|
@@ -31,13 +52,16 @@ export const TextTooltip = forwardRef<HTMLButtonElement, TextTooltipProps>(
|
|
|
31
52
|
open={open}
|
|
32
53
|
onOpenChange={(nextOpen) => {
|
|
33
54
|
if (onlyWhenTruncating && nextOpen && content.current) {
|
|
34
|
-
|
|
55
|
+
const element: HTMLElement | null = truncateQuery
|
|
56
|
+
? content.current.querySelector(truncateQuery)
|
|
57
|
+
: content.current;
|
|
58
|
+
return setOpen(element ? element.scrollWidth > element.offsetWidth : false);
|
|
35
59
|
} else {
|
|
36
60
|
return setOpen(nextOpen);
|
|
37
61
|
}
|
|
38
62
|
}}
|
|
39
63
|
>
|
|
40
|
-
<Tooltip.Trigger asChild={asChild} ref={ref}>
|
|
64
|
+
<Tooltip.Trigger asChild={asChild} {...props} ref={ref}>
|
|
41
65
|
{children}
|
|
42
66
|
</Tooltip.Trigger>
|
|
43
67
|
<ContentRoot>
|