2018-10-04 15:39:14 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
|
|
|
import { clipboard } from 'electron';
|
|
|
|
import { FormRow } from 'component/common/form';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import * as icons from 'constants/icons';
|
2018-10-29 18:23:53 +01:00
|
|
|
|
2018-10-04 15:39:14 +02:00
|
|
|
type Props = {
|
|
|
|
copyable: string,
|
2018-10-29 18:23:53 +01:00
|
|
|
doToast: ({ message: string }) => void,
|
2018-10-04 15:39:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default class CopyableText extends React.PureComponent<Props> {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.input = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
input: ?HTMLInputElement;
|
|
|
|
|
|
|
|
render() {
|
2018-10-29 18:23:53 +01:00
|
|
|
const { copyable, doToast, noSnackbar } = this.props;
|
2018-10-04 15:39:14 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FormRow verticallyCentered padded stretch>
|
|
|
|
<input
|
|
|
|
className="input-copyable form-field__input"
|
|
|
|
readOnly
|
|
|
|
value={copyable || ''}
|
|
|
|
ref={input => {
|
|
|
|
this.input = input;
|
|
|
|
}}
|
|
|
|
onFocus={() => {
|
|
|
|
if (this.input) {
|
|
|
|
this.input.select();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
noPadding
|
|
|
|
button="secondary"
|
|
|
|
icon={icons.CLIPBOARD}
|
|
|
|
onClick={() => {
|
|
|
|
clipboard.writeText(copyable);
|
2018-10-29 18:23:53 +01:00
|
|
|
doToast({
|
|
|
|
message: __('Text copied'),
|
|
|
|
});
|
2018-10-04 15:39:14 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</FormRow>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|