Fix isInternalUrl for subdomain support
Refactor / reduce plumbing
This commit is contained in:
34
app/components/CopyToClipboard.js
Normal file
34
app/components/CopyToClipboard.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import copy from 'copy-to-clipboard';
|
||||
|
||||
type Props = {
|
||||
text: string,
|
||||
children?: React.Node,
|
||||
onClick?: () => *,
|
||||
onCopy: () => *,
|
||||
};
|
||||
|
||||
class CopyToClipboard extends React.PureComponent<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;
|
||||
Reference in New Issue
Block a user