@telegraph/truncate 0.0.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/CHANGELOG.md +10 -0
- package/README.md +85 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.mjs +57 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/TooltipIfTruncated/TooltipIfTruncated.d.ts +7 -0
- package/dist/types/TooltipIfTruncated/TooltipIfTruncated.d.ts.map +1 -0
- package/dist/types/TooltipIfTruncated/index.d.ts +2 -0
- package/dist/types/TooltipIfTruncated/index.d.ts.map +1 -0
- package/dist/types/TruncatedText/TruncatedText.d.ts +10 -0
- package/dist/types/TruncatedText/TruncatedText.d.ts.map +1 -0
- package/dist/types/TruncatedText/index.d.ts +2 -0
- package/dist/types/TruncatedText/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/useTruncate/index.d.ts +2 -0
- package/dist/types/useTruncate/index.d.ts.map +1 -0
- package/dist/types/useTruncate/useTruncate.d.ts +10 -0
- package/dist/types/useTruncate/useTruncate.d.ts.map +1 -0
- package/package.json +56 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @telegraph/truncate
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#446](https://github.com/knocklabs/telegraph/pull/446) [`5c0784e`](https://github.com/knocklabs/telegraph/commit/5c0784e3fc5198ae4a83ef5c09b7b8c57c8d264d) Thanks [@kylemcd](https://github.com/kylemcd)! - add truncate component and integrate into combobox
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`5c0784e`](https://github.com/knocklabs/telegraph/commit/5c0784e3fc5198ae4a83ef5c09b7b8c57c8d264d)]:
|
|
10
|
+
- @telegraph/tooltip@0.0.46
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@telegraph/truncate)
|
|
4
|
+
|
|
5
|
+
# @telegraph/truncate
|
|
6
|
+
|
|
7
|
+
> Utility components for detecting and responding to content overflow, truncation, and visibility states in the UI.
|
|
8
|
+
|
|
9
|
+
## Installation Instructions
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install @telegraph/truncate
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Components
|
|
16
|
+
|
|
17
|
+
### `<TruncatedText/>`
|
|
18
|
+
|
|
19
|
+
A text component that automatically truncates content with an ellipsis and shows a tooltip when truncated.
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { TruncatedText } from "@telegraph/truncate";
|
|
23
|
+
|
|
24
|
+
<TruncatedText maxWidth="40">
|
|
25
|
+
This text will be truncated if it exceeds the container width
|
|
26
|
+
</TruncatedText>;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### Props
|
|
30
|
+
|
|
31
|
+
| Name | Type | Default | Description |
|
|
32
|
+
| ------------ | ------------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------ |
|
|
33
|
+
| tooltipProps | Partial<TgphComponentProps<typeof TooltipIfTruncated>> | `{}` | Props to pass to the underlying TooltipIfTruncated component |
|
|
34
|
+
| ...TextProps | TgphComponentProps<typeof Text> | - | All props from [@telegraph/typography](https://github.com/knocklabs/telegraph/tree/main/packages/typography) |
|
|
35
|
+
|
|
36
|
+
### `<TooltipIfTruncated/>`
|
|
37
|
+
|
|
38
|
+
A component that conditionally shows a tooltip only when its content is truncated.
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { TooltipIfTruncated } from "@telegraph/truncate";
|
|
42
|
+
|
|
43
|
+
<TooltipIfTruncated>
|
|
44
|
+
<span>This text will show a tooltip only when truncated</span>
|
|
45
|
+
</TooltipIfTruncated>;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### Props
|
|
49
|
+
|
|
50
|
+
| Name | Type | Default | Description |
|
|
51
|
+
| --------------- | ---------------------------------- | ------- | ------------------------------------------------------------------------------------------------------ |
|
|
52
|
+
| label | string | - | The text to show in the tooltip. If not provided, will use the content's text |
|
|
53
|
+
| ...TooltipProps | TgphComponentProps<typeof Tooltip> | - | All props from [@telegraph/tooltip](https://github.com/knocklabs/telegraph/tree/main/packages/tooltip) |
|
|
54
|
+
|
|
55
|
+
## Hooks
|
|
56
|
+
|
|
57
|
+
### `useTruncate`
|
|
58
|
+
|
|
59
|
+
A hook that detects whether an element's content is truncated.
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { useTruncate } from "@telegraph/truncate";
|
|
63
|
+
|
|
64
|
+
const MyComponent = () => {
|
|
65
|
+
const ref = React.useRef<HTMLDivElement>(null);
|
|
66
|
+
const { truncated } = useTruncate({ tgphRef: ref });
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div ref={ref}>{truncated ? "Content is truncated" : "Content fits"}</div>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Parameters
|
|
75
|
+
|
|
76
|
+
| Name | Type | Description |
|
|
77
|
+
| ------ | ------------------------------------------- | --------------------------------------------------------------------- |
|
|
78
|
+
| params | `{ tgphRef: React.RefObject<HTMLElement> }` | A ref to the element to check for truncation |
|
|
79
|
+
| deps | `React.DependencyList` | Optional dependencies to re-run the truncation check when they change |
|
|
80
|
+
|
|
81
|
+
#### Returns
|
|
82
|
+
|
|
83
|
+
| Name | Type | Description |
|
|
84
|
+
| --------- | --------- | ------------------------------------------ |
|
|
85
|
+
| truncated | `boolean` | Whether the element's content is truncated |
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),p=require("@telegraph/helpers"),f=require("@telegraph/tooltip"),a=require("@telegraph/typography"),c=require("react"),l=({tgphRef:t},e=[])=>{const[r,n]=c.useState(!1);return c.useEffect(()=>{if(!t.current)return n(!1);const s=t.current,u=()=>{n(s.scrollWidth>s.clientWidth)};u();const i=new ResizeObserver(u);return i.observe(s),()=>{i.disconnect()}},[t,...e]),{truncated:r}},T=({label:t,children:e,...r})=>{const n=c.useRef(null),{truncated:s}=l({tgphRef:n},[e]),u=c.useMemo(()=>typeof e=="string"?e:c.isValidElement(e)?e.props.children:t,[e,t]);return o.jsx(f.Tooltip,{label:o.jsx(a.Text,{as:"span",size:"1",children:u}),enabled:s,triggerRef:n,...r,children:o.jsx(p.RefToTgphRef,{children:e})})},d=({tooltipProps:t,style:e,...r})=>o.jsx(T,{...t,children:o.jsx(a.Text,{textOverflow:"ellipsis",overflow:"hidden",style:{display:"block",whiteSpace:"nowrap",...e},...r})});exports.TooltipIfTruncated=T;exports.TruncatedText=d;exports.useTruncate=l;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useTruncate/useTruncate.ts","../../src/TooltipIfTruncated/TooltipIfTruncated.tsx","../../src/TruncatedText/TruncatedText.tsx"],"sourcesContent":["import React from \"react\";\n\ntype UseTruncateParams = {\n tgphRef: React.RefObject<HTMLElement>;\n};\n\nconst useTruncate = (\n { tgphRef }: UseTruncateParams,\n deps: React.DependencyList = [],\n) => {\n const [truncated, setTruncated] = React.useState(false);\n\n React.useEffect(() => {\n if (!tgphRef.current) return setTruncated(false);\n\n const tgphRefElement = tgphRef.current;\n\n const checkTruncation = () => {\n setTruncated(tgphRefElement.scrollWidth > tgphRefElement.clientWidth);\n };\n\n // Initial check\n checkTruncation();\n\n // Add a resize observer to check for truncation when the element is resized\n const resizeObserver = new ResizeObserver(checkTruncation);\n resizeObserver.observe(tgphRefElement);\n\n // Clean up\n return () => {\n resizeObserver.disconnect();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tgphRef, ...deps]);\n\n return { truncated };\n};\n\nexport { useTruncate };\n","import {\n type Optional,\n RefToTgphRef,\n type TgphComponentProps,\n} from \"@telegraph/helpers\";\nimport { Tooltip } from \"@telegraph/tooltip\";\nimport { Text } from \"@telegraph/typography\";\nimport React from \"react\";\n\nimport { useTruncate } from \"../useTruncate\";\n\ntype TooltipIfTruncatedProps = Optional<\n TgphComponentProps<typeof Tooltip>,\n \"label\"\n>;\n\nconst TooltipIfTruncated = ({\n label,\n children,\n ...props\n}: TooltipIfTruncatedProps) => {\n const truncateRef = React.useRef<HTMLButtonElement>(null);\n const { truncated } = useTruncate({ tgphRef: truncateRef }, [children]);\n\n // We extract the text so that we can properly wrap it in the Text component\n const textToDisplayInTooltip = React.useMemo(() => {\n if (typeof children === \"string\") return children;\n if (React.isValidElement(children)) return children.props.children;\n return label;\n }, [children, label]);\n\n return (\n <Tooltip\n label={\n <Text as=\"span\" size=\"1\">\n {textToDisplayInTooltip}\n </Text>\n }\n enabled={truncated}\n triggerRef={truncateRef}\n {...props}\n >\n <RefToTgphRef>{children}</RefToTgphRef>\n </Tooltip>\n );\n};\n\nexport { TooltipIfTruncated };\n","import type { TgphComponentProps, TgphElement } from \"@telegraph/helpers\";\nimport { Text } from \"@telegraph/typography\";\n\nimport { TooltipIfTruncated } from \"../TooltipIfTruncated\";\n\ntype TruncatedTextProps<T extends TgphElement> = {\n tooltipProps?: Partial<TgphComponentProps<typeof TooltipIfTruncated>>;\n} & TgphComponentProps<typeof Text<T>>;\n\nconst TruncatedText = <T extends TgphElement>({\n tooltipProps,\n style,\n ...props\n}: TruncatedTextProps<T>) => {\n return (\n <TooltipIfTruncated {...tooltipProps}>\n <Text\n textOverflow=\"ellipsis\"\n overflow=\"hidden\"\n style={{\n display: \"block\",\n whiteSpace: \"nowrap\",\n ...style,\n }}\n {...props}\n />\n </TooltipIfTruncated>\n );\n};\n\nexport { TruncatedText };\n"],"names":["useTruncate","tgphRef","deps","truncated","setTruncated","React","tgphRefElement","checkTruncation","resizeObserver","TooltipIfTruncated","label","children","props","truncateRef","textToDisplayInTooltip","jsx","Tooltip","Text","RefToTgphRef","TruncatedText","tooltipProps","style"],"mappings":"2OAMMA,EAAc,CAClB,CAAE,QAAAC,GACFC,EAA6B,CAAA,IAC1B,CACH,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAM,SAAS,EAAK,EAEtD,OAAAA,EAAM,UAAU,IAAM,CACpB,GAAI,CAACJ,EAAQ,QAAS,OAAOG,EAAa,EAAK,EAE/C,MAAME,EAAiBL,EAAQ,QAEzBM,EAAkB,IAAM,CACfH,EAAAE,EAAe,YAAcA,EAAe,WAAW,CACtE,EAGgBC,EAAA,EAGV,MAAAC,EAAiB,IAAI,eAAeD,CAAe,EACzD,OAAAC,EAAe,QAAQF,CAAc,EAG9B,IAAM,CACXE,EAAe,WAAW,CAC5B,CAAA,EAEC,CAACP,EAAS,GAAGC,CAAI,CAAC,EAEd,CAAE,UAAAC,CAAU,CACrB,ECpBMM,EAAqB,CAAC,CAC1B,MAAAC,EACA,SAAAC,EACA,GAAGC,CACL,IAA+B,CACvB,MAAAC,EAAcR,EAAM,OAA0B,IAAI,EAClD,CAAE,UAAAF,CAAU,EAAIH,EAAY,CAAE,QAASa,CAAY,EAAG,CAACF,CAAQ,CAAC,EAGhEG,EAAyBT,EAAM,QAAQ,IACvC,OAAOM,GAAa,SAAiBA,EACrCN,EAAM,eAAeM,CAAQ,EAAUA,EAAS,MAAM,SACnDD,EACN,CAACC,EAAUD,CAAK,CAAC,EAGlB,OAAAK,EAAA,IAACC,EAAA,QAAA,CACC,MACGD,EAAAA,IAAAE,EAAA,KAAA,CAAK,GAAG,OAAO,KAAK,IAClB,SACHH,EAAA,EAEF,QAASX,EACT,WAAYU,EACX,GAAGD,EAEJ,SAAAG,EAAA,IAACG,gBAAc,SAAAP,CAAS,CAAA,CAAA,CAC1B,CAEJ,ECpCMQ,EAAgB,CAAwB,CAC5C,aAAAC,EACA,MAAAC,EACA,GAAGT,CACL,IAEIG,EAAA,IAACN,EAAoB,CAAA,GAAGW,EACtB,SAAAL,EAAA,IAACE,EAAA,KAAA,CACC,aAAa,WACb,SAAS,SACT,MAAO,CACL,QAAS,QACT,WAAY,SACZ,GAAGI,CACL,EACC,GAAGT,CAAA,CAAA,EAER"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as s } from "react/jsx-runtime";
|
|
2
|
+
import { RefToTgphRef as a } from "@telegraph/helpers";
|
|
3
|
+
import { Tooltip as l } from "@telegraph/tooltip";
|
|
4
|
+
import { Text as f } from "@telegraph/typography";
|
|
5
|
+
import c from "react";
|
|
6
|
+
const p = ({ tgphRef: t }, e = []) => {
|
|
7
|
+
const [r, o] = c.useState(!1);
|
|
8
|
+
return c.useEffect(() => {
|
|
9
|
+
if (!t.current) return o(!1);
|
|
10
|
+
const n = t.current, i = () => {
|
|
11
|
+
o(n.scrollWidth > n.clientWidth);
|
|
12
|
+
};
|
|
13
|
+
i();
|
|
14
|
+
const u = new ResizeObserver(i);
|
|
15
|
+
return u.observe(n), () => {
|
|
16
|
+
u.disconnect();
|
|
17
|
+
};
|
|
18
|
+
}, [t, ...e]), { truncated: r };
|
|
19
|
+
}, m = ({
|
|
20
|
+
label: t,
|
|
21
|
+
children: e,
|
|
22
|
+
...r
|
|
23
|
+
}) => {
|
|
24
|
+
const o = c.useRef(null), { truncated: n } = p({ tgphRef: o }, [e]), i = c.useMemo(() => typeof e == "string" ? e : c.isValidElement(e) ? e.props.children : t, [e, t]);
|
|
25
|
+
return /* @__PURE__ */ s(
|
|
26
|
+
l,
|
|
27
|
+
{
|
|
28
|
+
label: /* @__PURE__ */ s(f, { as: "span", size: "1", children: i }),
|
|
29
|
+
enabled: n,
|
|
30
|
+
triggerRef: o,
|
|
31
|
+
...r,
|
|
32
|
+
children: /* @__PURE__ */ s(a, { children: e })
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}, v = ({
|
|
36
|
+
tooltipProps: t,
|
|
37
|
+
style: e,
|
|
38
|
+
...r
|
|
39
|
+
}) => /* @__PURE__ */ s(m, { ...t, children: /* @__PURE__ */ s(
|
|
40
|
+
f,
|
|
41
|
+
{
|
|
42
|
+
textOverflow: "ellipsis",
|
|
43
|
+
overflow: "hidden",
|
|
44
|
+
style: {
|
|
45
|
+
display: "block",
|
|
46
|
+
whiteSpace: "nowrap",
|
|
47
|
+
...e
|
|
48
|
+
},
|
|
49
|
+
...r
|
|
50
|
+
}
|
|
51
|
+
) });
|
|
52
|
+
export {
|
|
53
|
+
m as TooltipIfTruncated,
|
|
54
|
+
v as TruncatedText,
|
|
55
|
+
p as useTruncate
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/useTruncate/useTruncate.ts","../../src/TooltipIfTruncated/TooltipIfTruncated.tsx","../../src/TruncatedText/TruncatedText.tsx"],"sourcesContent":["import React from \"react\";\n\ntype UseTruncateParams = {\n tgphRef: React.RefObject<HTMLElement>;\n};\n\nconst useTruncate = (\n { tgphRef }: UseTruncateParams,\n deps: React.DependencyList = [],\n) => {\n const [truncated, setTruncated] = React.useState(false);\n\n React.useEffect(() => {\n if (!tgphRef.current) return setTruncated(false);\n\n const tgphRefElement = tgphRef.current;\n\n const checkTruncation = () => {\n setTruncated(tgphRefElement.scrollWidth > tgphRefElement.clientWidth);\n };\n\n // Initial check\n checkTruncation();\n\n // Add a resize observer to check for truncation when the element is resized\n const resizeObserver = new ResizeObserver(checkTruncation);\n resizeObserver.observe(tgphRefElement);\n\n // Clean up\n return () => {\n resizeObserver.disconnect();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tgphRef, ...deps]);\n\n return { truncated };\n};\n\nexport { useTruncate };\n","import {\n type Optional,\n RefToTgphRef,\n type TgphComponentProps,\n} from \"@telegraph/helpers\";\nimport { Tooltip } from \"@telegraph/tooltip\";\nimport { Text } from \"@telegraph/typography\";\nimport React from \"react\";\n\nimport { useTruncate } from \"../useTruncate\";\n\ntype TooltipIfTruncatedProps = Optional<\n TgphComponentProps<typeof Tooltip>,\n \"label\"\n>;\n\nconst TooltipIfTruncated = ({\n label,\n children,\n ...props\n}: TooltipIfTruncatedProps) => {\n const truncateRef = React.useRef<HTMLButtonElement>(null);\n const { truncated } = useTruncate({ tgphRef: truncateRef }, [children]);\n\n // We extract the text so that we can properly wrap it in the Text component\n const textToDisplayInTooltip = React.useMemo(() => {\n if (typeof children === \"string\") return children;\n if (React.isValidElement(children)) return children.props.children;\n return label;\n }, [children, label]);\n\n return (\n <Tooltip\n label={\n <Text as=\"span\" size=\"1\">\n {textToDisplayInTooltip}\n </Text>\n }\n enabled={truncated}\n triggerRef={truncateRef}\n {...props}\n >\n <RefToTgphRef>{children}</RefToTgphRef>\n </Tooltip>\n );\n};\n\nexport { TooltipIfTruncated };\n","import type { TgphComponentProps, TgphElement } from \"@telegraph/helpers\";\nimport { Text } from \"@telegraph/typography\";\n\nimport { TooltipIfTruncated } from \"../TooltipIfTruncated\";\n\ntype TruncatedTextProps<T extends TgphElement> = {\n tooltipProps?: Partial<TgphComponentProps<typeof TooltipIfTruncated>>;\n} & TgphComponentProps<typeof Text<T>>;\n\nconst TruncatedText = <T extends TgphElement>({\n tooltipProps,\n style,\n ...props\n}: TruncatedTextProps<T>) => {\n return (\n <TooltipIfTruncated {...tooltipProps}>\n <Text\n textOverflow=\"ellipsis\"\n overflow=\"hidden\"\n style={{\n display: \"block\",\n whiteSpace: \"nowrap\",\n ...style,\n }}\n {...props}\n />\n </TooltipIfTruncated>\n );\n};\n\nexport { TruncatedText };\n"],"names":["useTruncate","tgphRef","deps","truncated","setTruncated","React","tgphRefElement","checkTruncation","resizeObserver","TooltipIfTruncated","label","children","props","truncateRef","textToDisplayInTooltip","jsx","Tooltip","Text","RefToTgphRef","TruncatedText","tooltipProps","style"],"mappings":";;;;;AAMA,MAAMA,IAAc,CAClB,EAAE,SAAAC,KACFC,IAA6B,CAAA,MAC1B;AACH,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAM,SAAS,EAAK;AAEtD,SAAAA,EAAM,UAAU,MAAM;AACpB,QAAI,CAACJ,EAAQ,QAAS,QAAOG,EAAa,EAAK;AAE/C,UAAME,IAAiBL,EAAQ,SAEzBM,IAAkB,MAAM;AACf,MAAAH,EAAAE,EAAe,cAAcA,EAAe,WAAW;AAAA,IACtE;AAGgB,IAAAC,EAAA;AAGV,UAAAC,IAAiB,IAAI,eAAeD,CAAe;AACzD,WAAAC,EAAe,QAAQF,CAAc,GAG9B,MAAM;AACX,MAAAE,EAAe,WAAW;AAAA,IAC5B;AAAA,EAAA,GAEC,CAACP,GAAS,GAAGC,CAAI,CAAC,GAEd,EAAE,WAAAC,EAAU;AACrB,GCpBMM,IAAqB,CAAC;AAAA,EAC1B,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,GAAGC;AACL,MAA+B;AACvB,QAAAC,IAAcR,EAAM,OAA0B,IAAI,GAClD,EAAE,WAAAF,EAAU,IAAIH,EAAY,EAAE,SAASa,EAAY,GAAG,CAACF,CAAQ,CAAC,GAGhEG,IAAyBT,EAAM,QAAQ,MACvC,OAAOM,KAAa,WAAiBA,IACrCN,EAAM,eAAeM,CAAQ,IAAUA,EAAS,MAAM,WACnDD,GACN,CAACC,GAAUD,CAAK,CAAC;AAGlB,SAAA,gBAAAK;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,OACG,gBAAAD,EAAAE,GAAA,EAAK,IAAG,QAAO,MAAK,KAClB,UACHH,GAAA;AAAA,MAEF,SAASX;AAAA,MACT,YAAYU;AAAA,MACX,GAAGD;AAAA,MAEJ,UAAA,gBAAAG,EAACG,KAAc,UAAAP,EAAS,CAAA;AAAA,IAAA;AAAA,EAC1B;AAEJ,GCpCMQ,IAAgB,CAAwB;AAAA,EAC5C,cAAAC;AAAA,EACA,OAAAC;AAAA,EACA,GAAGT;AACL,MAEI,gBAAAG,EAACN,GAAoB,EAAA,GAAGW,GACtB,UAAA,gBAAAL;AAAA,EAACE;AAAA,EAAA;AAAA,IACC,cAAa;AAAA,IACb,UAAS;AAAA,IACT,OAAO;AAAA,MACL,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,GAAGI;AAAA,IACL;AAAA,IACC,GAAGT;AAAA,EAAA;AAAA,GAER;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Optional, TgphComponentProps } from '@telegraph/helpers';
|
|
2
|
+
import { Tooltip } from '@telegraph/tooltip';
|
|
3
|
+
|
|
4
|
+
type TooltipIfTruncatedProps = Optional<TgphComponentProps<typeof Tooltip>, "label">;
|
|
5
|
+
declare const TooltipIfTruncated: ({ label, children, ...props }: TooltipIfTruncatedProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export { TooltipIfTruncated };
|
|
7
|
+
//# sourceMappingURL=TooltipIfTruncated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TooltipIfTruncated.d.ts","sourceRoot":"","sources":["../../../src/TooltipIfTruncated/TooltipIfTruncated.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EAEb,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAM7C,KAAK,uBAAuB,GAAG,QAAQ,CACrC,kBAAkB,CAAC,OAAO,OAAO,CAAC,EAClC,OAAO,CACR,CAAC;AAEF,QAAA,MAAM,kBAAkB,kCAIrB,uBAAuB,4CAyBzB,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/TooltipIfTruncated/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TgphComponentProps, TgphElement } from '@telegraph/helpers';
|
|
2
|
+
import { Text } from '@telegraph/typography';
|
|
3
|
+
import { TooltipIfTruncated } from '../TooltipIfTruncated';
|
|
4
|
+
|
|
5
|
+
type TruncatedTextProps<T extends TgphElement> = {
|
|
6
|
+
tooltipProps?: Partial<TgphComponentProps<typeof TooltipIfTruncated>>;
|
|
7
|
+
} & TgphComponentProps<typeof Text<T>>;
|
|
8
|
+
declare const TruncatedText: <T extends TgphElement>({ tooltipProps, style, ...props }: TruncatedTextProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export { TruncatedText };
|
|
10
|
+
//# sourceMappingURL=TruncatedText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TruncatedText.d.ts","sourceRoot":"","sources":["../../../src/TruncatedText/TruncatedText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,KAAK,kBAAkB,CAAC,CAAC,SAAS,WAAW,IAAI;IAC/C,YAAY,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC;CACvE,GAAG,kBAAkB,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvC,QAAA,MAAM,aAAa,GAAI,CAAC,SAAS,WAAW,qCAIzC,kBAAkB,CAAC,CAAC,CAAC,4CAevB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/TruncatedText/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/useTruncate/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
type UseTruncateParams = {
|
|
4
|
+
tgphRef: React.RefObject<HTMLElement>;
|
|
5
|
+
};
|
|
6
|
+
declare const useTruncate: ({ tgphRef }: UseTruncateParams, deps?: React.DependencyList) => {
|
|
7
|
+
truncated: boolean;
|
|
8
|
+
};
|
|
9
|
+
export { useTruncate };
|
|
10
|
+
//# sourceMappingURL=useTruncate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTruncate.d.ts","sourceRoot":"","sources":["../../../src/useTruncate/useTruncate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;CACvC,CAAC;AAEF,QAAA,MAAM,WAAW,gBACF,iBAAiB,SACxB,KAAK,CAAC,cAAc;;CA4B3B,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@telegraph/truncate",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Utility components for detecting and responding to content overflow, truncation, and visibility states in the UI.",
|
|
5
|
+
"repository": "https://github.com/knocklabs/telegraph/tree/main/packages/truncate",
|
|
6
|
+
"author": "@knocklabs",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "./dist/cjs/index.js",
|
|
9
|
+
"module": "./dist/esm/index.mjs",
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/esm/index.mjs",
|
|
14
|
+
"require": "./dist/cjs/index.js",
|
|
15
|
+
"types": "./dist/types/index.d.ts",
|
|
16
|
+
"default": "./dist/css/default.css"
|
|
17
|
+
},
|
|
18
|
+
"./default.css": "./dist/css/default.css"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"prettier": "@telegraph/prettier-config",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"clean": "rm -rf dist",
|
|
27
|
+
"dev": "vite build --watch --emptyOutDir false",
|
|
28
|
+
"build": "yarn clean && vite build",
|
|
29
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
30
|
+
"format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
|
|
31
|
+
"format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check",
|
|
32
|
+
"preview": "vite preview"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@telegraph/helpers": "^0.0.12",
|
|
36
|
+
"@telegraph/tooltip": "^0.0.46",
|
|
37
|
+
"@telegraph/typography": "^0.1.16"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@knocklabs/eslint-config": "^0.0.3",
|
|
41
|
+
"@knocklabs/typescript-config": "^0.0.2",
|
|
42
|
+
"@telegraph/postcss-config": "^0.0.24",
|
|
43
|
+
"@telegraph/prettier-config": "^0.0.7",
|
|
44
|
+
"@telegraph/vite-config": "^0.0.14",
|
|
45
|
+
"@types/react": "^18.3.18",
|
|
46
|
+
"eslint": "^8.56.0",
|
|
47
|
+
"react": "^18.3.1",
|
|
48
|
+
"react-dom": "^18.3.1",
|
|
49
|
+
"typescript": "^5.7.3",
|
|
50
|
+
"vite": "^6.0.11"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
54
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
55
|
+
}
|
|
56
|
+
}
|