(frontend) add copy link button

Add a copy link button to the doc
visibility component. This button will
copy the link of the doc to the clipboard.
This commit is contained in:
Anthony LC
2024-09-06 18:03:30 +02:00
committed by Anthony LC
parent 4321511631
commit 37db31a8d5
4 changed files with 53 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import {
Button,
Switch,
VariantType,
useToastProvider,
@@ -60,6 +61,26 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
)}
/>
</Box>
<Button
onClick={() => {
navigator.clipboard
.writeText(window.location.href)
.then(() => {
toast(t('Link Copied !'), VariantType.SUCCESS, {
duration: 3000,
});
})
.catch(() => {
toast(t('Failed to copy link'), VariantType.ERROR, {
duration: 3000,
});
});
}}
color="primary"
icon={<span className="material-icons">copy</span>}
>
{t('Copy link')}
</Button>
</Card>
);
};