simplified copy button

This commit is contained in:
Jori Lallo
2017-08-22 20:26:05 -07:00
parent 38c8a46d32
commit 9facf6e0fb

View File

@ -2,24 +2,24 @@
import React, { PureComponent } from 'react';
import copy from 'copy-to-clipboard';
type Props = {
text: string,
children?: React.Element<any>,
onClick?: () => void,
onCopy: () => void,
};
class CopyToClipboard extends PureComponent {
props: {
text: string,
children?: React.Element<any>,
onClick?: () => void,
onCopy: (string, boolean) => void,
};
props: Props;
onClick = (ev: SyntheticEvent) => {
const { text, onCopy, children } = this.props;
const elem = React.Children.only(children);
const result = copy(text, {
copy(text, {
debug: __DEV__,
});
if (onCopy) {
onCopy(text, result);
}
if (onCopy) onCopy();
if (elem && elem.props && typeof elem.props.onClick === 'function') {
elem.props.onClick(ev);