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.tsx

85 lines
1.9 KiB

3 years ago
/* eslint react/prop-types: 0 */
import React, { useState } from 'react';
import { Button, UncontrolledTooltip } from 'reactstrap';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faClone,
faExternalLinkAlt,
faCheck,
faCopy,
} from '@fortawesome/free-solid-svg-icons';
2 years ago
import ClipboardJS from 'clipboard';
const CopyField = ({ value, iconCopy = null, text }) => {
const [check, setCheck] = useState(false);
const handleClickOnField = (event) => {
3 years ago
event.target.focus();
event.target.select();
setCheck(true);
setTimeout(() => {
setCheck(false);
}, 3000);
3 years ago
};
2 years ago
if (typeof window !== 'undefined') {
2 years ago
new ClipboardJS('.btn');
}
3 years ago
let icon = null;
if (check) {
icon = faCheck;
} else if (iconCopy) {
icon = iconCopy;
} else {
icon = faCopy;
}
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"
value={value}
readOnly
onClick={handleClickOnField}
/>
<div className="input-group-append copy">
2 years ago
{/* <Button
href={value}
target="_blank"
rel="noreferrer"
className="btn btn-success"
type="button"
>
<FontAwesomeIcon icon={iconOpen} />
{t("Go")}
2 years ago
</Button> */}
3 years ago
<Button
2 years ago
data-clipboard-text={value}
target="_blank"
rel="noreferrer"
className="btn btn-copy"
3 years ago
type="button"
>
2 years ago
{text}
<FontAwesomeIcon icon={icon} />
3 years ago
</Button>
</div>
<UncontrolledTooltip placement="top" target="tooltip" trigger="click">
Lien copié
</UncontrolledTooltip>
3 years ago
</div>
);
};
CopyField.defaultProps = {
iconCopy: faClone,
iconOpen: faExternalLinkAlt,
};
3 years ago
export default CopyField;