security-checklist/components/Button/CopyLinkButton.js

39 lines
966 B
JavaScript
Raw Permalink Normal View History

// @flow
// $FlowIssue
import React, { useState } from 'react';
import { CopyLinkButton as StyledCopyLinkButton } from './style';
import Icon from '../Icon';
import type { ButtonProps } from './types';
type CopyLinkProps = {
...$Exact<ButtonProps>,
text: string,
};
export default function CopyLinkButton(props: CopyLinkProps) {
const { text, children } = props;
const [isClicked, handleClick] = useState(false);
const onClick = () => {
handleClick(true);
setTimeout(() => handleClick(false), 2000);
};
return (
<StyledCopyLinkButton
data-clipboard-text={text}
onSuccess={onClick}
component="button"
data-cy="copy-link-button"
isClicked={isClicked}
aria-label="Copy the websites address to your clipboard."
2019-02-06 14:02:13 +00:00
type="button"
2019-12-27 04:17:53 +00:00
// $FlowIssue
{...props}
>
<Icon glyph="link" size={24} />
<span>{isClicked ? 'Copied!' : children}</span>
</StyledCopyLinkButton>
);
}