
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
react-clamp-lines
Advanced tools
Responsive and accessible clamping component with Read more/Read less buttons built for React.
Responsive and accessible clamping component with «Read more»/«Read less» buttons built for React.
npm i react-clamp-lines
React
with no dependenciesdebounced
— and why it's important
If 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 ReactDOM from 'react-dom';
import ClampLines from 'react-clamp-lines';
class App extends Component {
render() {
return (
<ClampLines
text={text_to_clamp}
id="really-unique-id"
lines={4}
ellipsis="..."
moreText="Expand"
lessText="Collapse"
className="custom-class"
innerElement="p"
/>
);
}
}
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">
<p
id="clamped-content-really-unique-id"
aria-hidden="true"
>
clamped text here...
</p>
<button
class="clamp-lines__button"
aria-controls="clamped-content-really-unique-id"
aria-expanded="false"
>
Expand
</button>
</div>
List of all available props with their default values and description.
<ClampLines
text={String}
id={String}
lines={Number}
ellipsis={String}
buttons={Boolean}
moreText={String}
lessText={String}
className={String}
delay={Number}
stopPropagation={Boolean}
innerElement={String}
/>
prop | required | type | default value | description |
---|---|---|---|---|
text | * | {String} | Text you wish to clamp | |
id | * | {String} | Unique id (used for ARIA props) | |
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 | ||
delay | {Number} | 300 | Milliseconds, the function is waiting before being triggered, after it stops being called | |
stopPropagation | {Boolean} | false | Prevents the event from bubbling up the DOM tree when clicked on the «Read more» button | |
innerElement | {String} | div | Custom inner element for clamped text. This MUST be a block level element or styled as one. |
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
See Unlicense for full details.
FAQs
Responsive and accessible clamping component with Read more/Read less buttons built for React.
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
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.