Skip to content

Commit 225a9e8

Browse files
vntwpablosichert
authored andcommitted
Add optional anchorClass prop
1 parent 6dd024b commit 225a9e8

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Foo extends Component {
2727
lines={3}
2828
more='Show more'
2929
less='Show less'
30+
anchorClass=''
3031
>
3132
{longText}
3233
</ShowMore>
@@ -42,6 +43,7 @@ class Foo extends Component {
4243
| children | string, React node | | The text to be truncated. Anything that can be evaluated as text. | `'Some text'`, `<p>Some paragraph <a/>with other text-based inline elements<a></p>`, `<span>Some</span><span>siblings</span>` |
4344
| more | string, React node | '…' | An ellipsis that is added to the end of the text in case it is truncated. | `'Show more'`, `<span>Show more</span>`
4445
| less | string, React node | '…' | A node that appended to the last line in case the user clicked "show more". | `'Show less'`, `<span>Show less</span>`
46+
| anchorClass | string | '' | Class name(s) to add to the anchor elements. | `'my-anchor-class'`, `'class-1 class-2'`
4547

4648
## Developing
4749
Install development dependencies

src/ShowMore.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ class ShowMore extends Component {
55
static defaultProps = {
66
lines: 3,
77
more: 'Show more',
8-
less: 'Show less'
8+
less: 'Show less',
9+
anchorClass: ''
910
}
1011

1112
static propTypes = {
1213
children: PropTypes.node.isRequired,
1314
lines: PropTypes.number,
1415
more: PropTypes.node,
15-
less: PropTypes.node
16+
less: PropTypes.node,
17+
anchorClass: PropTypes.string
1618
}
1719

1820
state = {
@@ -41,7 +43,8 @@ class ShowMore extends Component {
4143
children,
4244
more,
4345
less,
44-
lines
46+
lines,
47+
anchorClass
4548
} = this.props;
4649

4750
const {
@@ -54,14 +57,14 @@ class ShowMore extends Component {
5457
<Truncate
5558
lines={!expanded && lines}
5659
ellipsis={(
57-
<span>... <a href='#' onClick={this.toggleLines}>{more}</a></span>
60+
<span>... <a href='#' className={anchorClass} onClick={this.toggleLines}>{more}</a></span>
5861
)}
5962
onTruncate={this.handleTruncate}
6063
>
6164
{children}
6265
</Truncate>
6366
{!truncated && expanded && (
64-
<span> <a href='#' onClick={this.toggleLines}>{less}</a></span>
67+
<span> <a href='#' className={anchorClass} onClick={this.toggleLines}>{less}</a></span>
6568
)}
6669
</div>
6770
);

0 commit comments

Comments
 (0)