2019-01-13 01:52:43 +00:00
|
|
|
|
// @flow
|
|
|
|
|
|
// $FlowIssue
|
|
|
|
|
|
import React, { useState } from 'react';
|
2019-02-06 14:01:46 +00:00
|
|
|
|
import { CopyLinkButton as StyledCopyLinkButton } from './style';
|
2019-01-13 01:52:43 +00:00
|
|
|
|
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 (
|
2019-02-06 14:01:46 +00:00
|
|
|
|
<StyledCopyLinkButton
|
2019-01-13 01:52:43 +00:00
|
|
|
|
data-clipboard-text={text}
|
|
|
|
|
|
onSuccess={onClick}
|
2019-02-06 14:01:46 +00:00
|
|
|
|
component="button"
|
|
|
|
|
|
data-cy="copy-link-button"
|
|
|
|
|
|
isClicked={isClicked}
|
|
|
|
|
|
aria-label="Copy the website’s address to your clipboard."
|
2019-02-06 14:02:13 +00:00
|
|
|
|
type="button"
|
2019-12-27 04:17:53 +00:00
|
|
|
|
// $FlowIssue
|
2019-02-06 14:01:46 +00:00
|
|
|
|
{...props}
|
2019-01-13 01:52:43 +00:00
|
|
|
|
>
|
2019-02-06 14:01:46 +00:00
|
|
|
|
<Icon glyph="link" size={24} />
|
2019-02-06 17:55:50 +00:00
|
|
|
|
<span>{isClicked ? 'Copied!' : children}</span>
|
2019-02-06 14:01:46 +00:00
|
|
|
|
</StyledCopyLinkButton>
|
2019-01-13 01:52:43 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|