Skip to content

Commit 1e20424

Browse files
committed
feat: add component to display strings truncated in the middle
1 parent 24d84c2 commit 1e20424

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@use "@pythnetwork/component-library/theme";
2+
3+
.truncateToMiddle {
4+
&::before, &::after {
5+
display: inline-block;
6+
overflow: hidden;
7+
white-space: pre;
8+
max-width: 50%;
9+
}
10+
11+
&::before {
12+
content: attr(data-text-start);
13+
text-overflow: ellipsis;
14+
}
15+
16+
&::after {
17+
content: attr(data-text-end);
18+
text-overflow: clip;
19+
direction: rtl;
20+
}
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import styles from "./index.module.scss";
2+
3+
export type Props = {
4+
text: string
5+
}
6+
7+
const TruncateToMiddle = ({text}: Props) => {
8+
return <span className={styles.truncateToMiddle} data-text-start={text.slice(0, Math.floor(text.length/2))} data-text-end={text.slice(Math.floor(text.length/2) * -1)} />
9+
}
10+
11+
export default TruncateToMiddle

0 commit comments

Comments
 (0)