one-click-accessibility/modules/settings/assets/js/components/copy-link/index.js
Nirbhay Singh c5b59b4db2
[APP-1049] Add back button accessibility statement (#164)
* add: back button to the statement link section

* add: Edit link button to statement page section

* update: add admin_url and generate query args properly
2025-02-09 11:13:23 +02:00

64 lines
1.4 KiB
JavaScript

import { LinkIcon } from '@elementor/icons';
import IconButton from '@elementor/ui/IconButton';
import Tooltip from '@elementor/ui/Tooltip';
import clipboardCopy from 'clipboard-copy';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
const CopyLink = ({ content }) => {
const [open, setOpen] = useState(false);
const [copied, setCopied] = useState(false);
const handleClose = () => {
setOpen(false);
setTimeout(() => setCopied(false), 200); // add delay for animation
};
const handleOpen = () => {
setOpen(true);
};
const copyToClipboard = async () => {
await clipboardCopy(content);
setCopied(true);
};
return (
<Tooltip
open={open}
onClose={handleClose}
onOpen={handleOpen}
placement="top"
title={
copied
? __('Copied!', 'pojo-accessibility')
: __('Copy link', 'pojo-accessibility')
}
arrow={true}
PopperProps={{
modifiers: [
{
name: 'offset',
options: {
offset: [0, -16], // Adjusts the vertical (top) margin
},
},
{
name: 'zIndex',
enabled: true,
phase: 'beforeWrite',
fn: ({ state }) => {
state.styles.popper.zIndex = '99999'; // Apply zIndex to the Popper element
},
},
],
}}
>
<IconButton onClick={copyToClipboard} sx={{ marginLeft: 1 }}>
<LinkIcon width="1em" height="1em" />
</IconButton>
</Tooltip>
);
};
export default CopyLink;