Skip to content

Commit

Permalink
feat(FilePreview): add tooltip props for actions (#174)
Browse files Browse the repository at this point in the history
Co-authored-by: Maxim725 <[email protected]>
  • Loading branch information
Maxim725 and MaximVyatkin authored Apr 15, 2024
1 parent 4c1bbab commit e16cef8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/FilePreview/FilePreviewAction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {ActionTooltip, Button, Icon, IconData} from '@gravity-ui/uikit';
import {ActionTooltip, ActionTooltipProps, Button, Icon, IconData} from '@gravity-ui/uikit';

export interface FilePreviewActionProps {
id?: string;
Expand All @@ -12,6 +12,7 @@ export interface FilePreviewActionProps {
extraProps?:
| React.ButtonHTMLAttributes<HTMLButtonElement>
| React.AnchorHTMLAttributes<HTMLAnchorElement>;
tooltipExtraProps?: Omit<ActionTooltipProps, 'id' | 'title' | 'children'>;
}

export function FilePreviewAction({
Expand All @@ -22,9 +23,10 @@ export function FilePreviewAction({
disabled,
onClick,
extraProps,
tooltipExtraProps,
}: FilePreviewActionProps) {
return (
<ActionTooltip id={id} title={title}>
<ActionTooltip id={id} title={title} {...tooltipExtraProps}>
<Button
onClick={onClick}
view="raised"
Expand Down
26 changes: 26 additions & 0 deletions src/components/FilePreview/__stories__/FilePreview.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,29 @@ const NoClickableTemplate: StoryFn<Omit<FilePreviewProps, 'actions'>> = (args) =
};

export const NoClickable = NoClickableTemplate.bind({});

const WithoutActionTooltipTemplate: StoryFn<Omit<FilePreviewProps, 'actions'>> = (args) => {
return (
<Flex gap={4}>
<FilePreview
{...args}
file={{name: 'Clicable without tooltip', type: 'text/docs'} as File}
onClick={() => {
window.open('https://disk.yandex.com', '_blank');
}}
actions={[
{
icon: Xmark,
onClick: () => alert('Are you sure you want to delete the file?'),
title: 'Close',
tooltipExtraProps: {
disabled: true,
},
},
]}
/>
</Flex>
);
};

export const WithoutActionTooltip = WithoutActionTooltipTemplate.bind({});

0 comments on commit e16cef8

Please sign in to comment.