Gathering detailed insights and metrics for @yukimoto/use-clamp-text
Gathering detailed insights and metrics for @yukimoto/use-clamp-text
Gathering detailed insights and metrics for @yukimoto/use-clamp-text
Gathering detailed insights and metrics for @yukimoto/use-clamp-text
npm install @yukimoto/use-clamp-text
Typescript
Module System
Node Version
NPM Version
65.1
Supply Chain
89.9
Quality
75.7
Maintenance
100
Vulnerability
99.6
License
TypeScript (100%)
Total Downloads
1,077
Last Day
1
Last Week
1
Last Month
6
Last Year
176
1 Stars
17 Commits
1 Watching
1 Branches
1 Contributors
Latest Version
2.0.5
Package Id
@yukimoto/use-clamp-text@2.0.5
Unpacked Size
18.60 kB
Size
4.93 kB
File Count
8
NPM Version
8.19.3
Node Version
18.13.0
Publised On
13 Mar 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-66.7%
1
Compared to previous week
Last month
-45.5%
6
Compared to previous month
Last year
-80.5%
176
Compared to previous year
1
Custom react hook that clamp multiline text to a specified line number. Can optionally specify trailing spaces. Fix some bugs and use cleaner implementation. Modified from:
1npm i @yukimoto/use-clamp-text
1const component = () => { 2 const { 3 longEnoughToClamp, 4 textContainerRef, 5 addOnsContainerRef, 6 wrapperContainerRef, 7 clamped, 8 clampedText, 9 toggleClamp, 10 } = useClampText<{ 11 WrapperContainer: HTMLDivElement; 12 TextContainer: HTMLSpanElement; 13 AddonsContainer: HTMLButtonElement; 14 }>({ 15 originalText: 'some potentially really long text...', 16 lines: 2, // At most how many lines 17 endSpaceNumber: 4, // how many trailing space, 18 unitSpaceChar: '*', // single trailing space should be the width of this char 19 debounceTime: 100, // in miliseconds 20 }); 21 return ( 22 <div ref={wrapperContainerRef}> 23 <span ref={textContainerRef}>{clampedText}</span> 24 {longEnoughToClamp ? ( 25 <button ref={addOnsContainerRef} onClick={toggleClamp}> 26 {clamped ? '...show more' : '...show less'} 27 </button> 28 ) : null} 29 </div> 30 ); 31};
property | type | required | default | description |
---|---|---|---|---|
originalText | string | false | '' | Text you wish to clamp. |
lines | number | false | 2 | Number of visible lines when collapsed. |
debounceTime | number | false | 300 | How many time in miliseconds before the clamp action will be triggered when window resizes. |
minSpaceCharNum | number | false | 0 | The minium trailing space number, will make the process of adding space to the end of the addons component more efficient. |
unitSpaceChar | string | false | '.' | The width of single trailing space, pass a char for the measurement of width. |
endSpaceNumber | number | false | 0 | How many trailing spaces. Each of them will be the width of unitSpaceChar . |
property | type | description |
---|---|---|
longEnoughtToClamp | boolean | Whether the originalText is longer enough to exceeds the given line number by it self. |
clampedText | string | The string to be rendered. |
clamped | boolean | A state indicating whether the text should be clamped if long enough. |
toggleClamp | () => void | A callback which togger the clamped state. |
wrapperContainerRef, textContainerRef, addOnsContainerRef | React.RefObject<E extends HTMLElement> | Ref for corresponding containers. |
No vulnerabilities found.
No security vulnerabilities found.