Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FilePreview): Fix FilePreview a11y and styles #102

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 8 additions & 2 deletions src/components/FilePreview/FilePreview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,21 @@ $smallRoundedButtonSize: 24px;
flex-direction: column;
align-items: center;

cursor: pointer;
position: relative;
outline: none;

box-shadow: var(--gc-card-box-shadow);
background-color: var(--_-color-base-background);
border-radius: var(--_-border-radius);
padding: 4px 10px;

&_clickable {
cursor: pointer;
}

&_with-hover {
amje marked this conversation as resolved.
Show resolved Hide resolved
background-color: var(--_-color-base-background);
}

&::after {
position: absolute;
top: 0;
Expand Down
11 changes: 7 additions & 4 deletions src/components/FilePreview/FilePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ export function FilePreview({
}
}, [file, imageSrc]);

const clickable = Boolean(onClick);
const withActions = Boolean(actions?.length);

return (
<div className={cn(null, className)} data-qa={qa}>
<div
className={cn('card')}
role="button"
onKeyDown={onKeyDown}
tabIndex={0}
className={cn('card', {clickable, 'with-hover': clickable || withActions})}
role={clickable ? 'button' : undefined}
onKeyDown={clickable ? onKeyDown : undefined}
tabIndex={clickable ? 0 : undefined}
onClick={onClick}
>
{typeof previewSrc === 'string' ? (
Expand Down
37 changes: 36 additions & 1 deletion src/components/FilePreview/__stories__/FilePreview.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import {CircleExclamation, Link, Xmark} from '@gravity-ui/icons';
import {Flex} from '@gravity-ui/uikit';
import type {Meta, StoryFn} from '@storybook/react';

import {FilePreview, FilePreviewProps} from '../FilePreview';
Expand Down Expand Up @@ -58,7 +59,6 @@ const DefaultTemplate: StoryFn<FilePreviewProps> = (args) => {
};

export const Default = DefaultTemplate.bind({});

Default.args = {
file: {name: 'my-file.docs', type: 'text/docs'} as File,
onClick: () => {
Expand All @@ -72,3 +72,38 @@ Default.args = {
},
],
};

const NoClickableTemplate: StoryFn<Omit<FilePreviewProps, 'actions'>> = (args) => {
return (
<Flex gap={4}>
<FilePreview {...args} file={{name: 'No clickable', type: 'text/docs'} as File} />
<FilePreview
{...args}
file={{name: 'No clickable with actions', type: 'text/docs'} as File}
actions={[
{
icon: Xmark,
onClick: () => alert('Are you sure you want to delete the file?'),
title: 'Close',
},
]}
/>
<FilePreview
{...args}
file={{name: 'Clickable with actions', 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',
},
]}
/>
</Flex>
);
};

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