Created
October 20, 2021 15:40
-
-
Save freddi301/084c097c90b6647b810cae4f04594cb4 to your computer and use it in GitHub Desktop.
truncates single line to parent width
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
export function TruncatedLine({ text }: { text: string }) { | |
return ( | |
<span style={{ position: "relative", display: "block" }}> | |
<span style={{ color: "transparent" }}>X</span> | |
<span | |
style={{ | |
display: "block", | |
position: "absolute", | |
overflow: "hidden", | |
textOverflow: "ellipsis", | |
whiteSpace: "nowrap", | |
width: "100%", | |
top: 0, | |
}} | |
> | |
{text} | |
</span> | |
</span> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment