lbry-desktop/src/renderer/component/copyableText/view.jsx

56 lines
1.2 KiB
React
Raw Normal View History

2018-10-04 15:39:14 +02:00
// @flow
2018-11-26 02:21:25 +01:00
import * as ICONS from 'constants/icons';
2018-10-04 15:39:14 +02:00
import * as React from 'react';
import { clipboard } from 'electron';
import { FormRow } from 'component/common/form';
import Button from 'component/button';
2018-10-04 15:39:14 +02:00
type Props = {
copyable: string,
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() {
const { copyable, doToast } = this.props;
2018-10-04 15:39:14 +02:00
return (
<FormRow verticallyCentered stretch>
2018-10-04 15:39:14 +02:00
<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"
2018-11-26 02:21:25 +01:00
icon={ICONS.CLIPBOARD}
2018-10-04 15:39:14 +02:00
onClick={() => {
clipboard.writeText(copyable);
doToast({
message: __('Text copied'),
});
2018-10-04 15:39:14 +02:00
}}
/>
</FormRow>
);
}
}