You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1017 B
46 lines
1017 B
4 years ago
|
import React from 'react';
|
||
4 years ago
|
import {Button} from 'reactstrap';
|
||
|
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
||
|
|
||
|
|
||
|
const CopyField = props => {
|
||
|
const ref = React.createRef();
|
||
|
const handleClickOnField = event => {
|
||
|
event.target.focus();
|
||
|
event.target.select();
|
||
|
};
|
||
|
const handleClickOnButton = event => {
|
||
|
const input = ref.current;
|
||
|
input.focus();
|
||
|
input.select();
|
||
|
document.execCommand('copy');
|
||
|
};
|
||
|
|
||
|
const {t, value, icon} = props;
|
||
|
|
||
|
return (
|
||
|
<div className="input-group ">
|
||
|
<input
|
||
|
type="text"
|
||
|
className="form-control"
|
||
|
ref={ref}
|
||
|
value={value}
|
||
|
readOnly
|
||
|
onClick={handleClickOnField}
|
||
|
/>
|
||
|
|
||
|
<div className="input-group-append">
|
||
|
<Button
|
||
|
className="btn btn-outline-light"
|
||
|
onClick={handleClickOnButton}
|
||
|
type="button">
|
||
|
<FontAwesomeIcon icon={icon} className="mr-2" />
|
||
|
{t('Copy')}
|
||
|
</Button>
|
||
|
</div>
|
||
|
</div>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export default CopyField;
|