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