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.
mvfront-react/components/CopyField.jsx

71 lines
1.6 KiB

3 years ago
/* eslint react/prop-types: 0 */
import React from "react";
import { Button } from "reactstrap";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faClone,
faVoteYea,
faExclamationTriangle,
faExternalLinkAlt,
} from "@fortawesome/free-solid-svg-icons";
3 years ago
const CopyField = (props) => {
3 years ago
const ref = React.createRef();
const handleClickOnField = (event) => {
3 years ago
event.target.focus();
event.target.select();
};
const handleClickOnButton = () => {
const input = ref.current;
input.focus();
input.select();
document.execCommand("copy");
};
const { t, value, iconCopy, iconOpen } = props;
3 years ago
return (
<div className="input-group my-4 ">
3 years ago
<input
type="text"
style={{display:"none"}}
3 years ago
className="form-control"
ref={ref}
value={value}
readOnly
onClick={handleClickOnField}
/>
<div className="input-group-append copy">
{/*
<Button
href={value}
target="_blank"
rel="noreferrer"
className="btn btn-success"
type="button"
>
<FontAwesomeIcon icon={iconOpen} className="mr-2" />
{t("Go")}
</Button>
*/}
3 years ago
<Button
className="btn btn-copy"
3 years ago
onClick={handleClickOnButton}
type="button"
>
{t("Copy")}
<FontAwesomeIcon icon={iconCopy} className="ml-2" />
3 years ago
</Button>
</div>
</div>
);
};
CopyField.defaultProps = {
iconCopy: faClone,
iconOpen: faExternalLinkAlt,
};
3 years ago
export default CopyField;