Skip to content

Commit

Permalink
Fix StyledLineClamp styled component performance issue
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Jun 14, 2021
1 parent 7e7582a commit c0599fb
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ const ExpandedContent = styled.div`
overflow-y: auto;
`;

const StyledLineClamp = styled.div<{ lineClampHeight: number }>`
display: -webkit-box;
-webkit-line-clamp: ${LINE_CLAMP};
-webkit-box-orient: vertical;
overflow: hidden;
max-height: ${({ lineClampHeight }) => lineClampHeight}em;
height: ${({ lineClampHeight }) => lineClampHeight}em;
`;

const LineClampComponent: React.FC<{
content?: string | null;
lineClampHeight?: number;
Expand Down Expand Up @@ -58,23 +67,18 @@ const LineClampComponent: React.FC<{
return null;
}

const StyledLineClamp = styled.div`
display: -webkit-box;
-webkit-line-clamp: ${LINE_CLAMP};
-webkit-box-orient: vertical;
overflow: hidden;
max-height: ${`${lineClampHeight}em`};
height: ${`${lineClampHeight}em`};
`;

return (
<>
{isExpanded ? (
<ExpandedContent data-test-subj="expanded-line-clamp">
<p>{content}</p>
</ExpandedContent>
) : isOverflow == null || isOverflow === true ? (
<StyledLineClamp data-test-subj="styled-line-clamp" ref={descriptionRef}>
<StyledLineClamp
data-test-subj="styled-line-clamp"
ref={descriptionRef}
lineClampHeight={lineClampHeight}
>
{content}
</StyledLineClamp>
) : (
Expand Down

0 comments on commit c0599fb

Please sign in to comment.