mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
35 lines
848 B
TypeScript
35 lines
848 B
TypeScript
import { chakra } from '@chakra-ui/react';
|
|
import React from 'react';
|
|
|
|
import shortenString from 'lib/shortenString';
|
|
import { Tooltip } from 'toolkit/chakra/tooltip';
|
|
|
|
interface Props {
|
|
hash: string;
|
|
noTooltip?: boolean;
|
|
tooltipInteractive?: boolean;
|
|
type?: 'long' | 'short';
|
|
as?: React.ElementType;
|
|
}
|
|
|
|
const HashStringShorten = ({ hash, noTooltip, as = 'span', type, tooltipInteractive }: Props) => {
|
|
const charNumber = type === 'long' ? 16 : 8;
|
|
if (hash.length <= charNumber) {
|
|
return <chakra.span as={ as }>{ hash }</chakra.span>;
|
|
}
|
|
|
|
const content = <chakra.span as={ as }>{ shortenString(hash, charNumber) }</chakra.span>;
|
|
|
|
if (noTooltip) {
|
|
return content;
|
|
}
|
|
|
|
return (
|
|
<Tooltip content={ hash } interactive={ tooltipInteractive }>
|
|
{ content }
|
|
</Tooltip>
|
|
);
|
|
};
|
|
|
|
export default HashStringShorten;
|