-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
CopyToClipBoard.tsx
50 lines (44 loc) 路 1.3 KB
/
CopyToClipBoard.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import styled from '@emotion/styled';
import FileCopy from '@mui/icons-material/FileCopy';
import IconButton from '@mui/material/IconButton';
import Tooltip from '@mui/material/Tooltip';
import React from 'react';
import { copyToClipBoardUtility } from './utils';
interface Props {
text: string;
title?: string;
dataTestId: string;
children?: React.ReactNode;
}
const Wrapper = styled('div')({
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
});
const Content = styled('span')({
display: 'inline-block',
overflow: 'hidden',
textOverflow: 'ellipsis',
height: 'auto',
whiteSpace: 'break-spaces',
fontSize: '1rem',
});
function CopyToClipBoard({ text, children, dataTestId, title, ...props }: Props) {
return (
<Wrapper {...props}>
<Content>{children ?? text}</Content>
{title ? (
<Tooltip disableFocusListener={true} title={title}>
<IconButton data-testid={dataTestId} onClick={copyToClipBoardUtility(text)} size="small">
<FileCopy fontSize="small" />
</IconButton>
</Tooltip>
) : (
<IconButton data-testid={dataTestId} onClick={copyToClipBoardUtility(text)} size="small">
<FileCopy fontSize="small" />
</IconButton>
)}
</Wrapper>
);
}
export default CopyToClipBoard;