frontend > app

This commit is contained in:
Tom Moor
2017-10-25 22:49:04 -07:00
parent aa34db8318
commit 4863680d86
239 changed files with 11 additions and 11 deletions

View File

@@ -0,0 +1,36 @@
// @flow
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: Props;
onClick = (ev: SyntheticEvent) => {
const { text, onCopy, children } = this.props;
const elem = React.Children.only(children);
copy(text, {
debug: __DEV__,
});
if (onCopy) onCopy();
if (elem && elem.props && typeof elem.props.onClick === 'function') {
elem.props.onClick(ev);
}
};
render() {
const { text: _text, onCopy: _onCopy, children, ...rest } = this.props;
const elem = React.Children.only(children);
return React.cloneElement(elem, { ...rest, onClick: this.onClick });
}
}
export default CopyToClipboard;

View File

@@ -0,0 +1,3 @@
// @flow
import CopyToClipboard from './CopyToClipboard';
export default CopyToClipboard;