Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a 'cutoff' prop #42

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

![react-clamp-lines](react-clamp.png 'react-clamp-lines')
![react-clamp-lines](react-clamp.png "react-clamp-lines")

## Demo

Expand All @@ -28,9 +28,9 @@ Responsive and accessible clamping component with _«Read more»_/_&la
## Usage

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

class App extends Component {
render() {
Expand All @@ -40,6 +40,7 @@ class App extends Component {
id="really-unique-id"
lines={4}
ellipsis="..."
cutoff={12a}
moreText="Expand"
lessText="Collapse"
className="custom-class"
Expand All @@ -49,20 +50,17 @@ class App extends Component {
}
}

ReactDOM.render(<App />, document.getElementById('clamp'));
ReactDOM.render(<App />, document.getElementById("clamp"));
```

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"
>
<p id="clamped-content-really-unique-id" aria-hidden="true">
clamped text here...
</p>
<button
<button
class="clamp-lines__button"
aria-controls="clamped-content-really-unique-id"
aria-expanded="false"
Expand All @@ -82,6 +80,7 @@ List of all available props with their default values and description.
id={String}
lines={Number}
ellipsis={String}
cutoff={Number}
buttons={Boolean}
moreText={String}
lessText={String}
Expand All @@ -92,19 +91,20 @@ List of all available props with their default values and description.
/>
```

| prop | required | type | default&#160;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 _&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.**
| prop | required | type | default&#160;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 |
| cutoff | | {Number} | `5` | How many characters are going to be cut off from the last line before the ellipsis |
| 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

Expand Down
Loading