Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/Gallery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ import {
actions={[
getGalleryItemCopyLinkAction({
copyUrl: 'https://example.jpg',
onCopy: () => console.log('link copied'),
onCopy: (text, success) => {
if (success) console.log('Link copied:', text);
},
}),
getGalleryItemDownloadAction({
downloadUrl: 'https://example.jpg',
Expand All @@ -149,6 +151,8 @@ import {
/>
```

The copy action shows feedback on success. `onCopy(text, success)` reports the result.

### Examples

#### Simple images gallery
Expand Down
28 changes: 15 additions & 13 deletions src/components/Gallery/utils/getGalleryItemCopyLinkAction.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Link} from '@gravity-ui/icons';
import {ActionTooltip, Button, CopyToClipboard, Icon} from '@gravity-ui/uikit';
import {ClipboardButton, type ClipboardButtonProps, Icon} from '@gravity-ui/uikit';

import {GalleryItemAction} from '../GalleryItem';

export type GetGalleryItemCopyLinkActionArgs = {
copyUrl: string;
onCopy?: () => void;
onCopy?: ClipboardButtonProps['onCopy'];
};

export function getGalleryItemCopyLinkAction({
Expand All @@ -17,16 +17,18 @@ export function getGalleryItemCopyLinkAction({
title: 'copy-url',
__titleT: ({t}) => t('copy-link'),
icon: <Icon data={Link} />,
__renderT: (props, {t}) => (
<CopyToClipboard text={copyUrl} onCopy={onCopy}>
{() => (
<div>
<ActionTooltip title={t('copy-link')}>
<Button {...props} />
</ActionTooltip>
</div>
)}
</CopyToClipboard>
),
__renderT: (props, {t}) => {
if (props.href !== undefined) return null;

return (
<ClipboardButton
{...props}
text={copyUrl}
tooltipInitialText={t('copy-link')}
onCopy={onCopy}
icon={<Icon data={Link} />}
/>
);
},
};
}
Loading