File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { Box , Tooltip , Typography } from '@mui/material' ;
2+ import _ from 'lodash' ;
3+ import React , { useState } from 'react' ;
4+ import { CopyIcon } from '../../icons' ;
5+ import { useTheme } from '../../theme' ;
6+
7+ interface FormatIdProps {
8+ id : string ;
9+ }
10+
11+ export const FormatId : React . FC < FormatIdProps > = ( { id } ) => {
12+ const [ copied , setCopied ] = useState ( false ) ;
13+ const theme = useTheme ( ) ;
14+
15+ // Truncates the id to 15 characters and adds an ellipsis and adds a clipboard copy button
16+ const copyToClipboard = ( e : React . MouseEvent < HTMLDivElement > ) => {
17+ e . stopPropagation ( ) ;
18+ navigator . clipboard . writeText ( id ) ;
19+ setCopied ( true ) ;
20+
21+ // Reset the copied status after a brief delay
22+ setTimeout ( ( ) => {
23+ setCopied ( false ) ;
24+ } , 2000 ) ;
25+ } ;
26+
27+ const truncatedId = _ . truncate ( id , { length : 15 } ) ;
28+
29+ return (
30+ < Box sx = { { display : 'flex' , alignItems : 'center' } } >
31+ < Tooltip title = { id } placement = "top" >
32+ < Typography
33+ variant = "body2"
34+ style = { {
35+ cursor : 'pointer' ,
36+ textWrap : 'nowrap' ,
37+ color : theme . palette . text . primary
38+ } }
39+ >
40+ { truncatedId }
41+ </ Typography >
42+ </ Tooltip >
43+ < Tooltip title = { copied ? 'Copied!' : 'Copy' } placement = "top" >
44+ < div onClick = { copyToClipboard } style = { { padding : '0.25rem' } } >
45+ < CopyIcon width = { 16 } height = { 16 } fill = { theme . palette . action . active } />
46+ </ div >
47+ </ Tooltip >
48+ </ Box >
49+ ) ;
50+ } ;
Original file line number Diff line number Diff line change 1+ import { FormatId } from './FormatId' ;
2+
3+ export { FormatId } ;
You can’t perform that action at this time.
0 commit comments