From 98f28381f40bdc57f34d5f43c36840a99312505a Mon Sep 17 00:00:00 2001 From: thykos Date: Tue, 17 Oct 2017 15:59:50 +0300 Subject: [PATCH] add `renderLastLine` method to overriding if it need --- src/Truncate.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Truncate.js b/src/Truncate.js index e4c63111..301184c3 100644 --- a/src/Truncate.js +++ b/src/Truncate.js @@ -31,6 +31,7 @@ export default class Truncate extends Component { this.measureWidth = this.measureWidth.bind(this); this.getLines = this.getLines.bind(this); this.renderLine = this.renderLine.bind(this); + this.renderLastLine = this.renderLastLine.bind(this); } componentDidMount() { @@ -171,14 +172,14 @@ export default class Truncate extends Component { const { elements, props: { - lines: numLines, - ellipsis + lines: numLines }, state: { targetWidth }, innerText, measureWidth, + renderLastLine, onTruncate } = this; @@ -230,7 +231,7 @@ export default class Truncate extends Component { } } - resultLine = {textRest.slice(0, lower)}{ellipsis}; + resultLine = renderLastLine(textRest.slice(0, lower), textWords); } else { // Binary search determining when the line breaks let lower = 0; @@ -284,6 +285,11 @@ export default class Truncate extends Component { } } + renderLastLine(splicedText, originalArray) { + const { ellipsis } = this.props; + return ({splicedText}{ellipsis}); + } + render() { const { elements: {