Skip to content

Commit

Permalink
Refactor - reuse UploadButton, move icons
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Sep 8, 2023
1 parent e9fe703 commit 9a5ebc0
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/components/ReactFileUtilities/FileIcon/FileIconSet/v1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Font Awesome Free 5.15.3 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
*/
import React, { SVGProps } from 'react';
import React, { ComponentPropsWithoutRef } from 'react';

export type IconPropsV1 = { size?: number } & SVGProps<SVGSVGElement>;
export type IconPropsV1 = { size?: number } & ComponentPropsWithoutRef<'svg'>;

const DEFAULT_SIZE = 20;

Expand Down
4 changes: 2 additions & 2 deletions src/components/ReactFileUtilities/FileIcon/FileIconSet/v2.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { SVGProps } from 'react';
import React, { ComponentPropsWithoutRef } from 'react';

export type IconTypeV2 = 'standard' | 'alt';

export type IconPropsV2 = {
mimeType?: string;
size?: number;
type?: IconTypeV2;
} & SVGProps<SVGSVGElement>;
} & ComponentPropsWithoutRef<'svg'>;

const DEFAULT_SIZE = 40;

Expand Down
15 changes: 8 additions & 7 deletions src/components/ReactFileUtilities/FileUploadButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PropsWithChildren } from 'react';

import { AttachmentIcon } from './AttachmentIcon';
import { useHandleFileChangeWrapper } from './utils';
import { AttachmentIcon } from './icons';
import { UploadButton } from './UploadButton';

export type FileUploadButtonProps = {
handleFiles: (files: FileList | File[]) => void;
Expand All @@ -11,6 +11,9 @@ export type FileUploadButtonProps = {
resetOnChange?: boolean;
};

/**
* @deprecated will be removed in the next major release
*/
export const FileUploadButton = ({
disabled = false,
multiple = false,
Expand All @@ -24,19 +27,17 @@ export const FileUploadButton = ({
className = `${className} rfu-file-upload-button--disabled`;
}

const onFileChange = useHandleFileChangeWrapper(resetOnChange, handleFiles);

return (
<div className={className}>
<label>
<input
<UploadButton
accept={Array.isArray(accepts) ? accepts.join(',') : accepts}
aria-label='File input'
className='rfu-file-input'
disabled={disabled}
multiple={multiple}
onChange={onFileChange}
type='file'
onFileChange={handleFiles}
resetOnChange={resetOnChange}
/>
{children}
</label>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReactFileUtilities/ImagePreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { MouseEvent, useCallback } from 'react';
import { LoadingIndicator } from './LoadingIndicator';
import { Thumbnail } from './Thumbnail';
import { ThumbnailPlaceholder } from './ThumbnailPlaceholder';
import { RetryIcon } from './RetryIcon';
import { RetryIcon } from './icons';

import type { ImageUpload } from './types';
import clsx from 'clsx';
Expand Down
43 changes: 21 additions & 22 deletions src/components/ReactFileUtilities/ImageUploadButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PropsWithChildren } from 'react';

import { PictureIcon } from './PictureIcon';
import { useHandleFileChangeWrapper } from './utils';
import { PictureIcon } from './icons';
import { UploadButton } from './UploadButton';

export type ImageUploadButtonProps = {
handleFiles: (files: File[]) => void;
Expand All @@ -10,29 +10,28 @@ export type ImageUploadButtonProps = {
resetOnChange?: boolean;
};

/**
* @deprecated will be removed in the next major release
*/
export const ImageUploadButton = ({
multiple = false,
disabled = false,
handleFiles,
children = <PictureIcon />,
resetOnChange = false,
}: PropsWithChildren<ImageUploadButtonProps>) => {
const onFileChange = useHandleFileChangeWrapper(resetOnChange, handleFiles);

return (
<div className='rfu-image-upload-button'>
<label>
<input
accept='image/*'
aria-label='Image input'
className='rfu-image-input'
disabled={disabled}
multiple={multiple}
onChange={onFileChange}
type='file'
/>
{children}
</label>
</div>
);
};
}: PropsWithChildren<ImageUploadButtonProps>) => (
<div className='rfu-image-upload-button'>
<label>
<UploadButton
accept='image/*'
aria-label='Image input'
className='rfu-image-input'
disabled={disabled}
multiple={multiple}
onFileChange={handleFiles}
resetOnChange={resetOnChange}
/>
{children}
</label>
</div>
);
8 changes: 5 additions & 3 deletions src/components/ReactFileUtilities/Thumbnail.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { MouseEventHandler, useCallback } from 'react';

import { IconButton } from './IconButton';
import { FilePlaceholder } from './FilePlaceholder';
import { CloseIcon } from './CloseIcon';
import { CloseIcon, FilePlaceholderIcon } from './icons';

export type ThumbnailProps = {
image: string;
Expand Down Expand Up @@ -30,7 +29,10 @@ export const Thumbnail = ({ alt, handleClose, image, size = 100 }: ThumbnailProp
{image ? (
<img alt={alt ?? ''} className='rfu-thumbnail__image' src={image} />
) : (
<FilePlaceholder className='rfu-thumbnail__image' preserveAspectRatio='xMinYMin slice' />
<FilePlaceholderIcon
className='rfu-thumbnail__image'
preserveAspectRatio='xMinYMin slice'
/>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { SVGProps } from 'react';
import React, { ComponentPropsWithoutRef } from 'react';

export const FilePlaceholder = (props: SVGProps<SVGSVGElement>) => (
export const FilePlaceholderIcon = (props: ComponentPropsWithoutRef<'svg'>) => (
<svg role='img' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg' {...props}>
<g>
<path
Expand Down
5 changes: 5 additions & 0 deletions src/components/ReactFileUtilities/icons/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './AttachmentIcon';
export * from './CloseIcon';
export * from './FilePlaceholderIcon';
export * from './PictureIcon';
export * from './RetryIcon';
3 changes: 1 addition & 2 deletions src/components/ReactFileUtilities/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
export * from './AttachmentIcon';
export * from './FileIcon';
export * from './FilePreviewer';
export * from './FileUploadButton';
export * from './ImageDropzone';
export * from './ImagePreviewer';
export * from './ImageUploadButton';
export * from './LoadingIndicator';
export * from './PictureIcon';
export * from './Thumbnail';
export * from './ThumbnailPlaceholder';
export * from './UploadButton';
export * from './types';
export * from './utils';
export { AttachmentIcon, PictureIcon } from './icons';

0 comments on commit 9a5ebc0

Please sign in to comment.