simplified copy button
This commit is contained in:
@ -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);
|
||||||
|
Reference in New Issue
Block a user