Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
react-clamp-lines
Advanced tools
Responsive clamping component with Read more/Read less buttons built for React.
Responsive clamping component with «Read more»/«Read less» buttons built for React.
npm install --save react-clamp-lines
React
with no dependenciesdebounced
— and why it's importantIf your web app uses JavaScript to accomplish taxing tasks, a debounce function is essential to ensuring a given task doesn't fire so often that it bricks browser performance.
import React, { Component } from 'react';
import React-DOM from 'react-dom';
import ClampLines from 'react-clamp-lines';
class App extends Component {
render() {
return (
<ClampLines
text={text_to_clamp}
lines="4"
ellipsis="..."
moreText="Expand"
lessText="Collapse"
className="custom-class" />
);
}
}
ReactDOM.render(<App />, document.getElementById('clamp'));
The component and the or «Read more» button always have the clamp-lines
and clamp-lines__button
CSS classes respectively. In the example above the custom-class
will be added to clamp-lines
, so the output will be:
<div class="clamp-lines custom-class">
<div>clamped text here...</div>
<button class="clamp-lines__button">Expand</button>
</div>
List of all available props with their default values and description.
<ClampLines
text={String}
lines={Number}
ellipsis={String}
buttons={Boolean}
moreText={String}
lessText={String}
className={String}
debounce={Number} />
prop | type | default value | description |
---|---|---|---|
text | {String} | Text you wish to clamp | |
lines | {Number} | 3 | Number of visible lines |
ellipsis | {String} | ... | Text content for the ellipsis - will appear after the clamped lines |
buttons | {Boolean} | true | The «Read more» and «Read less» buttons |
moreText | {String} | Read more | «Read more» button value |
lessText | {String} | Read less | «Read less» button value |
className | {String} | CSS class names added to component | |
debounce | {Number} | 300 | Milliseconds, the function is waiting before being triggered, after it stops being called |
git clone https://github.com/zoltantothcom/react-clamp-lines.git
cd react-clamp-lines
npm install
npm start
then open http://localhost:3000
FAQs
Responsive and accessible clamping component with Read more/Read less buttons built for React.
The npm package react-clamp-lines receives a total of 9,617 weekly downloads. As such, react-clamp-lines popularity was classified as popular.
We found that react-clamp-lines demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.