# react-clamp-line

> Responsive and accessible clamping component with Read more/Read less buttons built for React.

Latest version **1.0.1** (published 2023-06-22) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install react-clamp-line
pnpm add react-clamp-line
yarn add react-clamp-line
bun add react-clamp-line
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-06-22 |
| First published | 2023-06-22 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | T4F.ir |
| Maintainers | t4f.ir |
| Keywords | clamp, clamping, react clamp, clamp lines, react clamp lines, react clamping component, react ellipsis, readmore, showmore |

## Links

- npm: https://www.npmjs.com/package/react-clamp-line
- npm.io page: https://npm.io/package/react-clamp-line

## Dependencies (1)

- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2

## Recent versions

- 1.0.1 (latest) — 2023-06-22
- 1.0.0 — 2023-06-22

## README

# react-clamp-lines

Responsive and accessible clamping component with _&laquo;Read more&raquo;_/_&laquo;Read less&raquo;_ buttons built for [React](http://facebook.github.io/react/).

## Usage

```js
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import ClampLines from 'react-clamp-lines';

const ClampLinesSection = () => {
	return (
		<ClampLines
			text={text_to_clamp}
			id='really-unique-id'
			type='html'
			lines={4}
			ellipsis='...'
			moreText='Expand'
			lessText='Collapse'
			className='custom-class'
			innerElement='p'
		/>
	);
};
```

The component and the or _&laquo;Read more&raquo;_ 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:

```html
<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>
```

## API

List of all available props with their default values and description.

```javascript
<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&#160;value | description                                                                                                                                                                        |
| --------------- | -------- | ---------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| text            | **\***   | {String}         |                    | Text you wish to clamp                                                                                                                                                             |
| id              | **\***   | {String}         |                    | Unique id (used for ARIA props)                                                                                                                                                    |
| type            |          | 'html' \| 'text' |                    | Type of string that you need 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 _&laquo;Read more&raquo;_ and _&laquo;Read less&raquo;_ buttons                                                                                                                |
| moreText        |          | {String}         | `Read more`        | _&laquo;Read more&raquo;_ button value                                                                                                                                             |
| lessText        |          | {String}         | `Read less`        | _&laquo;Read less&raquo;_ 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 _&laquo;Read more&raquo;_ button                                                                              |
| innerElement    |          | {String}         | `div`              | Custom inner element for clamped text. **This MUST be a [block level element](https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements#Elements) or styled as one.** |

## License

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](http://unlicense.org) for full details.

---
_Source: https://npm.io/package/react-clamp-line · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
