Created
June 3, 2024 05:45
-
-
Save fuxingloh/e8c65e1cb014070e792cc296151a464b to your computer and use it in GitHub Desktop.
This file contains 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 { clsx } from 'clsx'; | |
import { ReactElement } from 'react'; | |
export function TruncateMiddle(props: { | |
children: string; | |
className?: string; | |
prefixLength?: number; | |
suffixLength?: number; | |
}): ReactElement { | |
const text = props.children; | |
return ( | |
<div className={clsx('relative inline-block select-none break-keep', props.className)}> | |
{text.substring(0, props.prefixLength ?? 6)}…{text.substring(text.length - (props.suffixLength ?? 6))} | |
<div className="absolute inset-0 select-all overflow-clip whitespace-nowrap text-transparent">{text}</div> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment