mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
Added tracking code form.
This commit is contained in:
parent
c4b75e4aec
commit
58a1be7a30
27 changed files with 100 additions and 42 deletions
23
components/common/CopyButton.js
Normal file
23
components/common/CopyButton.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import React, { useState } from 'react';
|
||||
import Button from './Button';
|
||||
|
||||
const defaultText = 'Copy to clipboard';
|
||||
|
||||
export default function CopyButton({ element, ...props }) {
|
||||
const [text, setText] = useState(defaultText);
|
||||
|
||||
function handleClick() {
|
||||
if (element?.current) {
|
||||
element.current.select();
|
||||
document.execCommand('copy');
|
||||
setText('Copied!');
|
||||
window.getSelection().removeAllRanges();
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Button {...props} onClick={handleClick}>
|
||||
{text}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue