@versini/ui-truncate 6.3.11 → 7.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/README.md +10 -6
- package/dist/index.d.ts +1 -7
- package/dist/index.js +2 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -9,10 +9,15 @@ The Truncate component provides intelligent text truncation with toggle function
|
|
|
9
9
|
|
|
10
10
|
## Table of Contents
|
|
11
11
|
|
|
12
|
+
- [Table of Contents](#table-of-contents)
|
|
12
13
|
- [Features](#features)
|
|
13
14
|
- [Installation](#installation)
|
|
14
15
|
- [Usage](#usage)
|
|
16
|
+
- [Props](#props)
|
|
17
|
+
- [Example](#example)
|
|
18
|
+
- [Behavior](#behavior)
|
|
15
19
|
- [Rich Content Truncation](#rich-content-truncation)
|
|
20
|
+
- [License](#license)
|
|
16
21
|
|
|
17
22
|
## Features
|
|
18
23
|
|
|
@@ -38,7 +43,7 @@ import { Truncate } from "@versini/ui-truncate";
|
|
|
38
43
|
|
|
39
44
|
function App() {
|
|
40
45
|
return (
|
|
41
|
-
<Truncate length={100} mode="dark"
|
|
46
|
+
<Truncate length={100} mode="dark">
|
|
42
47
|
This is a very long text that needs to be truncated.
|
|
43
48
|
</Truncate>
|
|
44
49
|
);
|
|
@@ -52,7 +57,6 @@ function App() {
|
|
|
52
57
|
| `children` | `React.ReactNode` | `null` | The content to render. If not a string, it will be rendered as-is. |
|
|
53
58
|
| `length` | `number` | `200` | The maximum number of characters to display before truncating. |
|
|
54
59
|
| `mode` | `"dark" \| "light" \| "system" \| "alt-system"` | `"system"` | The mode of the button used for toggling truncated text. |
|
|
55
|
-
| `focusMode` | `"dark" \| "light" \| "system" \| "alt-system"` | `"system"` | The focus mode of the button, affecting the focus ring's appearance. |
|
|
56
60
|
| `enableRichTruncation` | `boolean` | `false` | When `true`, measures nested React content text and truncates it. Collapsed view is plain text (styling removed); expanded view restores full formatting. |
|
|
57
61
|
|
|
58
62
|
## Example
|
|
@@ -63,9 +67,9 @@ import { Truncate } from "@versini/ui-truncate";
|
|
|
63
67
|
function App() {
|
|
64
68
|
return (
|
|
65
69
|
<div>
|
|
66
|
-
<Truncate length={50} mode="light"
|
|
67
|
-
Lorem ipsum dolor sit amet. Sed do ut labore et dolore magna
|
|
68
|
-
|
|
70
|
+
<Truncate length={50} mode="light">
|
|
71
|
+
Lorem ipsum dolor sit amet. Sed do ut labore et dolore magna. Sed do ut
|
|
72
|
+
labore et dolore magna. Lorem ipsum dolor sit amet.
|
|
69
73
|
</Truncate>
|
|
70
74
|
</div>
|
|
71
75
|
);
|
|
@@ -76,7 +80,7 @@ function App() {
|
|
|
76
80
|
|
|
77
81
|
- If the `children` prop is not a string, the component will render the `children` as-is without truncation.
|
|
78
82
|
- If the text exceeds the specified `length`, it will be truncated, and a button will appear to toggle between the truncated and full text.
|
|
79
|
-
- The button's appearance
|
|
83
|
+
- The button's appearance can be customized using the `mode` prop.
|
|
80
84
|
- When `enableRichTruncation` is `true`, the component traverses nested React nodes, measures their combined textual content, and in the collapsed state renders a flattened plain text slice (no markup) so the toggle button appears immediately after the text. Expanding restores the original rich markup.
|
|
81
85
|
|
|
82
86
|
## Rich Content Truncation
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSX } from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
export declare const Truncate: ({ children, length, mode,
|
|
3
|
+
export declare const Truncate: ({ children, length, mode, enableRichTruncation, noBorder, }: TruncateProps) => JSX.Element;
|
|
4
4
|
|
|
5
5
|
declare type TruncateProps = {
|
|
6
6
|
/**
|
|
@@ -26,12 +26,6 @@ declare type TruncateProps = {
|
|
|
26
26
|
* @default "system"
|
|
27
27
|
*/
|
|
28
28
|
mode?: "dark" | "light" | "system" | "alt-system";
|
|
29
|
-
/**
|
|
30
|
-
* The type of focus for the Button. This will change the color
|
|
31
|
-
* of the focus ring around the Button.
|
|
32
|
-
* @default "system"
|
|
33
|
-
*/
|
|
34
|
-
focusMode?: "dark" | "light" | "system" | "alt-system";
|
|
35
29
|
/**
|
|
36
30
|
* Whether or not to render the Button with a border.
|
|
37
31
|
* @default false
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-truncate
|
|
2
|
+
@versini/ui-truncate v7.0.1
|
|
3
3
|
© 2026 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -119,7 +119,7 @@ const DEFAULT_LENGTH = 200;
|
|
|
119
119
|
}
|
|
120
120
|
/* c8 ignore next 1 */ return false; // Unsupported node types treated as non-block for spacing
|
|
121
121
|
};
|
|
122
|
-
const Truncate = ({ children, length = 200, mode = "system",
|
|
122
|
+
const Truncate = ({ children, length = 200, mode = "system", enableRichTruncation = false, noBorder = false })=>{
|
|
123
123
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
124
124
|
const nonStringBypass = typeof children !== "string" && !enableRichTruncation;
|
|
125
125
|
const fullText = useMemo(()=>{
|
|
@@ -178,7 +178,6 @@ const Truncate = ({ children, length = 200, mode = "system", focusMode = "system
|
|
|
178
178
|
displayContent,
|
|
179
179
|
isTruncated && /*#__PURE__*/ jsx(Button, {
|
|
180
180
|
mode: mode,
|
|
181
|
-
focusMode: focusMode,
|
|
182
181
|
noBorder: noBorder,
|
|
183
182
|
className: needsInlineSpacing ? "ml-2" : undefined,
|
|
184
183
|
size: "small",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/ui-truncate",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"@testing-library/jest-dom": "6.9.1"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@versini/ui-button": "
|
|
43
|
+
"@versini/ui-button": "13.1.0",
|
|
44
44
|
"tailwindcss": "4.2.1"
|
|
45
45
|
},
|
|
46
46
|
"sideEffects": [
|
|
47
47
|
"**/*.css"
|
|
48
48
|
],
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "e1d07ef9f8c39af8e1cf471a2d1688f4bca1771c"
|
|
50
50
|
}
|