From aac4d8a6f6b60be5922e7de88a868e6133840a8d Mon Sep 17 00:00:00 2001 From: Severiano Badajoz Date: Mon, 1 Jun 2020 13:52:18 -0700 Subject: [PATCH] attempt css solution --- client/src/components/util/truncate.js | 100 +++++++++++++++++-------- 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/client/src/components/util/truncate.js b/client/src/components/util/truncate.js index c9708e54..be8a91bb 100644 --- a/client/src/components/util/truncate.js +++ b/client/src/components/util/truncate.js @@ -118,48 +118,82 @@ export default class Truncate extends Component { }; render() { - const { children, size, fontSize, bold, italic } = this.props; + const { children } = this.props; // Truncate only support a single child with a text child - if ( React.Children.count(children) === 1 && React.Children.count(children.props?.children) === 1 ) { - const originalString = children.props.children; - const truncatedString = this.maybeTruncateString( - originalString, - size, - fontSize, - bold, - italic - ); + const originalStr = children.props.children; + const firstHalf = originalStr.slice(0, originalStr.length / 2); + const secondHalf = originalStr.slice(originalStr.length / 2); - // Only make tooltip if string has to be truncated - if (truncatedString) { - // clone children, changing the children(text) to the truncated string - const newChildren = React.Children.map(children, (child) => - cloneElement(child, { - children: truncatedString, - "data-truncated": true, - }) - ); - return ( - + - {newChildren} - - ); - } - return children; + {firstHalf} + + + {secondHalf} + + + ); + + const newChildren = React.Children.map(children, (child) => + cloneElement(child, { + "data-truncated": true, + children: truncatedChildren, + style: { + ...child.props.style, + whiteSpace: "nowrap", + overflow: "hidden", + }, + }) + ); + return ( + + {newChildren} + + ); } + throw Error("Only pass a single child with inner text to Truncate"); } }