Files
requestarr/src/components/Settings/CopyButton.tsx
Ryan Cohen 16545eec22 feat: tooltip foundation (#2950)
* feat: add foundation for tooltips

* fix: add lang

* refactor: remove React import where no longer necessary
2022-08-19 19:35:50 +09:00

41 lines
974 B
TypeScript

import { ClipboardCopyIcon } from '@heroicons/react/solid';
import { useEffect } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { useToasts } from 'react-toast-notifications';
import useClipboard from 'react-use-clipboard';
const messages = defineMessages({
copied: 'Copied API key to clipboard.',
});
const CopyButton = ({ textToCopy }: { textToCopy: string }) => {
const intl = useIntl();
const [isCopied, setCopied] = useClipboard(textToCopy, {
successDuration: 1000,
});
const { addToast } = useToasts();
useEffect(() => {
if (isCopied) {
addToast(intl.formatMessage(messages.copied), {
appearance: 'info',
autoDismiss: true,
});
}
}, [isCopied, addToast, intl]);
return (
<button
onClick={(e) => {
e.preventDefault();
setCopied();
}}
className="input-action"
>
<ClipboardCopyIcon />
</button>
);
};
export default CopyButton;