Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Foo extends Component {
| more | string, React node | 'Show more' | The text to display in the anchor element to show more. | `'Show more'`, `<span>Show more</span>`
| less | string, React node | 'Show less' | The text to display in the anchor element to show less. | `'Show less'`, `<span>Show less</span>`
| anchorClass | string | '' | Class name(s) to add to the anchor elements. | `'my-anchor-class'`, `'class-1 class-2'`
| width | number | 0 | If not 0, the calculation of the content will be based on this number. | ``

## Developing
Install development dependencies
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
"prop-types": "^15.5.10"
},
"dependencies": {
"react-truncate": "^2.3.0"
"react-truncate": "^2.4.0"
}
}
10 changes: 7 additions & 3 deletions src/ShowMore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ class ShowMore extends Component {
lines: 3,
more: 'Show more',
less: 'Show less',
anchorClass: ''
anchorClass: '',
width: 0
}

static propTypes = {
children: PropTypes.node,
lines: PropTypes.number,
more: PropTypes.node,
less: PropTypes.node,
anchorClass: PropTypes.string
anchorClass: PropTypes.string,
width: PropTypes.number
}

state = {
Expand Down Expand Up @@ -45,7 +47,8 @@ class ShowMore extends Component {
more,
less,
lines,
anchorClass
anchorClass,
width
} = this.props;

const {
Expand All @@ -56,6 +59,7 @@ class ShowMore extends Component {
return (
<div>
<Truncate
width={width}
lines={!expanded && lines}
ellipsis={(
<span>... <a href='#' className={anchorClass} onClick={this.toggleLines}>{more}</a></span>
Expand Down