Skip to content

Commit 248d60d

Browse files
authored
fix(Gallery): actions placement (#314)
1 parent 73054ce commit 248d60d

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

src/components/Gallery/__stories__/Gallery.stories.tsx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ const EmptyGalleryTemplate: StoryFn<GalleryProps> = () => {
212212
export const EmptyGallery = EmptyGalleryTemplate.bind({});
213213

214214
const SingleItemGalleryTemplate: StoryFn<GalleryProps> = () => {
215+
const mobile = useMobile();
215216
const [open, setOpen] = React.useState(false);
216217

217218
const handleToggle = React.useCallback(() => {
@@ -227,13 +228,60 @@ const SingleItemGalleryTemplate: StoryFn<GalleryProps> = () => {
227228
name: 'Corgi image',
228229
});
229230

231+
const renderActions = React.useCallback(
232+
(file: GalleryFile) => {
233+
const result: GalleryItemAction[] = [
234+
{
235+
id: 'clipboard',
236+
title: file.type === 'text' ? 'Copy text' : 'Copy link',
237+
icon: <Icon data={Link} size={mobile ? 18 : 16} />,
238+
render: (buttonProps) => {
239+
return (
240+
<CopyToClipboard
241+
onCopy={() =>
242+
alert(file.type === 'text' ? 'Text copied!' : 'Link copied!')
243+
}
244+
text={file.type === 'text' ? file.text : file.url || ''}
245+
>
246+
{() => {
247+
if (mobile) {
248+
return <Button {...buttonProps} />;
249+
}
250+
return (
251+
<ActionTooltip
252+
title={file.type === 'text' ? 'Copy text' : 'Copy link'}
253+
>
254+
<Button {...buttonProps} />
255+
</ActionTooltip>
256+
);
257+
}}
258+
</CopyToClipboard>
259+
);
260+
},
261+
},
262+
];
263+
264+
if (file.type !== 'text') {
265+
result.push({
266+
id: 'new-tab',
267+
title: 'Open in new tab',
268+
icon: <Icon data={ArrowUpRightFromSquare} size={mobile ? 18 : 16} />,
269+
href: file.url,
270+
});
271+
}
272+
273+
return result;
274+
},
275+
[mobile],
276+
);
277+
230278
return (
231279
<React.Fragment>
232280
<Button onClick={handleOpen} view="action" size="l">
233281
Open gallery
234282
</Button>
235283
<Gallery open={open} onOpenChange={handleToggle}>
236-
<GalleryItem {...imageGalleryItem} />
284+
<GalleryItem {...imageGalleryItem} actions={renderActions(files[0])} />
237285
</Gallery>
238286
</React.Fragment>
239287
);

src/components/Gallery/components/MobileGalleryHeader/MobileGalleryHeader.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ $block: '.#{variables.$ns}gallery-header-mobile';
3737
}
3838
}
3939

40+
&__button-actions {
41+
grid-column: 3;
42+
}
43+
4044
&__footer {
4145
width: 100%;
4246
padding: var(--g-spacing-2) var(--g-spacing-5) var(--g-spacing-2);

src/components/Gallery/components/MobileGalleryHeader/MobileGalleryHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const MobileGalleryHeader = ({
7777
onClick={handleMobileActionClick}
7878
aria-label={i18n('close')}
7979
color="primary"
80+
className={cnGalleryHeaderMobile('button-actions')}
8081
>
8182
<Icon size={MOBILE_ICON_SIZE} data={Ellipsis} />
8283
</Button>

0 commit comments

Comments
 (0)