Skip to content

Commit

Permalink
feat(file-upload-item): custom icon (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
reme3d2y committed Oct 11, 2021
1 parent e8d284b commit 59b8925
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/file-upload-item/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ describe('FileUploadItem', () => {
expect(container.firstElementChild).toHaveClass(className);
});

it('should use custom icon', () => {
const dataTestId = 'test-id';
const { queryByTestId } = render(
<FileUploadItem icon={() => <div data-test-id={dataTestId} />} />,
);

expect(queryByTestId(dataTestId)).toBeInTheDocument();
});

describe('Callbacks tests', () => {
it('should call `onDelete` prop', () => {
const cb = jest.fn();
Expand Down
11 changes: 8 additions & 3 deletions packages/file-upload-item/src/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { MouseEvent, ReactNode, useCallback } from 'react';
import React, { ElementType, MouseEvent, ReactNode, useCallback } from 'react';
import cn from 'classnames';

import { IconButton } from '@alfalab/core-components-icon-button';
Expand Down Expand Up @@ -75,6 +75,11 @@ export type FileUploadItemProps = {
*/
children?: React.ReactNode;

/**
* Компонент кастомной иконки
*/
icon?: ElementType<{ className?: string }>;

/**
* Обработчик загрузки файла
*/
Expand Down Expand Up @@ -102,6 +107,7 @@ export const FileUploadItem: React.FC<FileUploadItemProps> = ({
id = '0',
name = '',
size,
icon: Icon = fileIcon(name),
uploadDate,
downloadLink,
uploadStatus,
Expand Down Expand Up @@ -142,11 +148,10 @@ export const FileUploadItem: React.FC<FileUploadItemProps> = ({
case 'UPLOADING':
return <Spinner visible={true} />;
default: {
const Icon = fileIcon(name);
return <Icon className={styles.icon} />;
}
}
}, [name, uploadStatus]);
}, [uploadStatus]);

const renderName = useCallback(
() => (
Expand Down

0 comments on commit 59b8925

Please sign in to comment.