import { MouseEvent } from 'react'; import clsx from 'clsx'; import { useAlert } from '@gear-js/react-hooks'; import { buttonStyles } from '@gear-js/ui'; import { Link } from 'react-router-dom'; import { getShortName, copyToClipboard } from '../../helpers'; import CopySVG from '../../assets/images/actions/copyGreen.svg?react'; import IdSVG from '../../assets/images/indicators/id.svg?react'; import styles from './IdBlock.module.scss'; type Props = { id: string; size?: 'small' | 'medium' | 'big' | 'large'; color?: 'light' | 'primary'; withIcon?: boolean; maxCharts?: number; className?: string; to?: string; }; const IdBlock = (props: Props) => { const { id, size = 'medium', color = 'primary', withIcon = false, maxCharts, className, to } = props; const alert = useAlert(); const handleCopy = (event: MouseEvent) => { event.stopPropagation(); copyToClipboard(id, alert); }; const buttonClasses = clsx(buttonStyles.button, buttonStyles.noText, buttonStyles.transparent, styles.copyBtn); const name = getShortName(id, maxCharts); const nameClassName = clsx(styles.value, styles[color]); const linkClassName = clsx(nameClassName, styles.link); return (
{withIcon && } {to ? ( {name} ) : ( {name} )}
); }; export { IdBlock };