2019-06-20 19:37:28 +07:00
|
|
|
import FileCopy from '@material-ui/icons/FileCopy';
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { copyToClipBoardUtility } from '../../utils/cli-utils';
|
|
|
|
import { TEXT } from '../../utils/constants';
|
2019-10-03 23:17:04 +07:00
|
|
|
import Tooltip from '../../muiComponents/Tooltip';
|
2019-06-20 19:37:28 +07:00
|
|
|
|
|
|
|
import { ClipBoardCopy, ClipBoardCopyText, CopyIcon } from './styles';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
text: string;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2019-10-11 03:20:05 +07:00
|
|
|
const renderText = (text: string, children: React.ReactNode): JSX.Element => {
|
2019-06-20 19:37:28 +07:00
|
|
|
if (children) {
|
|
|
|
return <ClipBoardCopyText>{children}</ClipBoardCopyText>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <ClipBoardCopyText>{text}</ClipBoardCopyText>;
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderToolTipFileCopy = (text: string): React.ReactElement<HTMLElement> => (
|
|
|
|
<Tooltip disableFocusListener={true} title={TEXT.CLIPBOARD_COPY}>
|
|
|
|
<CopyIcon onClick={copyToClipBoardUtility(text)}>
|
|
|
|
<FileCopy />
|
|
|
|
</CopyIcon>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
|
|
|
|
const CopyToClipBoard: React.FC<Props> = ({ text, children }) => {
|
|
|
|
return (
|
|
|
|
<ClipBoardCopy>
|
|
|
|
{renderText(text, children)}
|
|
|
|
{renderToolTipFileCopy(text)}
|
|
|
|
</ClipBoardCopy>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CopyToClipBoard;
|