1 import type { KeyboardEvent, MouseEvent } from 'react';
2 import { useCallback, useState } from 'react';
4 import { c } from 'ttag';
6 import { Button } from '@proton/atoms';
7 import { Icon, Tooltip } from '@proton/components';
8 import noop from '@proton/utils/noop';
10 import { useActions } from '../../../store';
11 import type { BrowserItemId } from '../../FileBrowser/interface';
15 linkId: BrowserItemId;
16 trashed: number | null;
21 const CopyLinkIcon = ({ shareId, linkId, trashed, isExpired, className }: Props) => {
22 const [isLoading, setIsLoading] = useState(false);
23 const { copyShareLinkToClipboard } = useActions();
25 const handleGetLink = useCallback(
26 (e: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>) => {
27 if (!copyShareLinkToClipboard) {
32 e.stopPropagation(); // To not show file preview when clicking (to not trigger other click event).
33 e.preventDefault(); // To not show file preview when pressing enter (to disable click event).
35 copyShareLinkToClipboard(new AbortController().signal, shareId, linkId)
44 if (!copyShareLinkToClipboard || isExpired || trashed) {
49 <Tooltip title={c('Action').t`Copy link`}>
56 onClick={handleGetLink}
58 if (e.key === 'Enter' || e.key === ' ') {
63 <Icon name="link" alt={c('Action').t`Copy link`} />
69 export default CopyLinkIcon;