* chore: Centralize env parsing, defaults, deprecation * wip * test * test * tsc * docs, more validation * fix: Allow empty REDIS_URL (defaults to localhost) * test * fix: SLACK_MESSAGE_ACTIONS not bool * fix: Add SMTP port validation
41 lines
956 B
TypeScript
41 lines
956 B
TypeScript
import copy from "copy-to-clipboard";
|
|
import * as React from "react";
|
|
import env from "~/env";
|
|
|
|
type Props = {
|
|
text: string;
|
|
children?: React.ReactElement;
|
|
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
onCopy?: () => void;
|
|
};
|
|
|
|
class CopyToClipboard extends React.PureComponent<Props> {
|
|
onClick = (ev: React.SyntheticEvent) => {
|
|
const { text, onCopy, children } = this.props;
|
|
const elem = React.Children.only(children);
|
|
|
|
copy(text, {
|
|
debug: env.ENVIRONMENT !== "production",
|
|
format: "text/plain",
|
|
});
|
|
|
|
onCopy?.();
|
|
|
|
if (elem && elem.props && typeof elem.props.onClick === "function") {
|
|
elem.props.onClick(ev);
|
|
}
|
|
};
|
|
|
|
render() {
|
|
const { text, onCopy, children, ...rest } = this.props;
|
|
const elem = React.Children.only(children);
|
|
if (!elem) {
|
|
return null;
|
|
}
|
|
|
|
return React.cloneElement(elem, { ...rest, onClick: this.onClick });
|
|
}
|
|
}
|
|
|
|
export default CopyToClipboard;
|