1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-06-14 15:39:42 +07:00
verdaccio-ui/src/components/CopyToClipBoard/CopyToClipBoard.tsx
Priscila Oliveira f84fd79c5b fix: detailContainer Component - Replaced class by func. comp (#130)
* refactor: coverted class comp. into func.comp

* refactor: added forward ref comp.

* fix: fixed external link color

* fix: fixed typo

* refactor: applied feedbacks
2019-10-03 18:17:04 +02:00

41 lines
1.0 KiB
TypeScript

import FileCopy from '@material-ui/icons/FileCopy';
import React from 'react';
import { copyToClipBoardUtility } from '../../utils/cli-utils';
import { TEXT } from '../../utils/constants';
import Tooltip from '../../muiComponents/Tooltip';
import { ClipBoardCopy, ClipBoardCopyText, CopyIcon } from './styles';
interface Props {
text: string;
children?: React.ReactNode;
}
const renderText = (text, children): JSX.Element => {
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;