don't change text
This commit is contained in:
parent
11207f70bb
commit
a7976d6f79
|
|
@ -47,28 +47,10 @@ export const CopyToClipboardTextButton: React.FunctionComponent<{
|
||||||
value: string | (() => Promise<string>),
|
value: string | (() => Promise<string>),
|
||||||
description: string,
|
description: string,
|
||||||
}> = ({ value, description }) => {
|
}> = ({ value, description }) => {
|
||||||
const [copied, setCopied] = React.useState<boolean>();
|
const handleCopy = React.useCallback(async () => {
|
||||||
|
const valueToCopy = typeof value === 'function' ? await value() : value;
|
||||||
const handleCopy = React.useCallback(() => {
|
await navigator.clipboard.writeText(valueToCopy);
|
||||||
const valuePromise = typeof value === 'function' ? value() : Promise.resolve(value);
|
|
||||||
valuePromise.then(value => {
|
|
||||||
navigator.clipboard.writeText(value).then(() => {
|
|
||||||
setCopied(true);
|
|
||||||
setTimeout(() => {
|
|
||||||
setCopied(undefined);
|
|
||||||
}, 3000);
|
|
||||||
}, () => {
|
|
||||||
setCopied(false);
|
|
||||||
});
|
|
||||||
}, () => {
|
|
||||||
setCopied(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
return <ToolbarButton title={description ? description : 'Copy'} onClick={handleCopy} className='copy-to-clipboard-text-button'>
|
return <ToolbarButton title={description} onClick={handleCopy} className='copy-to-clipboard-text-button'>{description}</ToolbarButton>;
|
||||||
{copied === true && 'Copied!'}
|
|
||||||
{copied === false && 'Copy failed.'}
|
|
||||||
{copied === undefined && description}
|
|
||||||
</ToolbarButton>;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue