Skip to content

Commit

Permalink
feat(component): add icon props for FileUploader dropzone (#1343)
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-apostoliuk authored Feb 14, 2024
1 parent f1e09a6 commit 96b8a86
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
14 changes: 6 additions & 8 deletions packages/big-design/src/components/FileUploader/DropZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export interface DropZoneLocalization {
}

interface Props extends InputHTMLAttributes<HTMLInputElement> {
label?: string;
description?: string;
icon?: React.ReactNode;
label?: string;
localization?: DropZoneLocalization;
onFilesChange(files: FileList | null): void;
}
Expand All @@ -36,14 +37,15 @@ export const DropZone = ({
accept,
description,
disabled,
icon = <DraftIcon />,
id,
label,
localization = defaultLocalization,
multiple,
onFilesChange,
}: Props) => {
const [isDragOver, setIsDragOver] = useState(false);
const [isFilesValid, setIsFilesValid] = useState(false);
const [isFilesValid, setIsFilesValid] = useState(true);

const fileInputRef = useRef<HTMLInputElement | null>(null);

Expand Down Expand Up @@ -114,11 +116,7 @@ export const DropZone = ({
);

const renderDropzoneIcon = useMemo(() => {
const icon = isFilesValid ? (
<FileDownloadIcon color="primary30" size={40} />
) : (
<RemoveCircleOutlineIcon color="danger30" size={40} />
);
const icon = isFilesValid ? <FileDownloadIcon /> : <RemoveCircleOutlineIcon />;

return (
<Box as="span" marginHorizontal="auto">
Expand Down Expand Up @@ -185,7 +183,7 @@ export const DropZone = ({
) : (
<>
<Flex alignItems="center">
<DraftIcon color={disabled ? 'secondary50' : 'primary30'} size={40} />
{icon}
<div>
{renderedLabel}
{renderedDescription}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export interface FileUploaderLocalization extends DropZoneLocalization {
}

interface DropzoneConfig {
label?: string;
description?: string;
icon?: React.ReactNode;
label?: string;
}

export interface FileValidationError {
Expand All @@ -50,10 +51,10 @@ interface Props {
dropzoneConfig?: DropzoneConfig;
error?: React.ReactNode | React.ReactNode[];
files: File[];
previewHidden?: boolean;
label?: React.ReactNode;
labelId?: string;
localization?: FileUploaderLocalization;
previewHidden?: boolean;
validators?: ValidatorConfig[];
onFilesChange(files: File[]): void;
onFilesError?(errors: FileValidationError[]): void;
Expand All @@ -68,11 +69,11 @@ export const FileUploader: React.FC<FileUploaderProps> = ({
dropzoneConfig = {},
error,
files,
previewHidden = false,
label,
labelId,
localization = defaultLocalization,
multiple,
previewHidden = false,
validators = [],
onFilesChange,
onFilesError,
Expand Down Expand Up @@ -211,6 +212,7 @@ export const FileUploader: React.FC<FileUploaderProps> = ({
accept={accept}
description={dropzoneConfig.description}
disabled={disabled}
icon={dropzoneConfig.icon}
id={id}
label={dropzoneConfig.label}
localization={localization}
Expand All @@ -222,6 +224,7 @@ export const FileUploader: React.FC<FileUploaderProps> = ({
accept,
disabled,
dropzoneConfig.description,
dropzoneConfig.icon,
dropzoneConfig.label,
files.length,
handleFilesChange,
Expand Down
16 changes: 16 additions & 0 deletions packages/big-design/src/components/FileUploader/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ export const DropzoneStyled = styled(Flex)<{
background-color: ${({ theme }) => theme.colors.primary10};
}
`};
svg {
width: ${remCalc(40)};
height: ${remCalc(40)};
fill: ${({ theme, disabled, isValid, isDragOver }) => {
if (disabled) {
return theme.colors.secondary50;
}
if (!isValid && isDragOver) {
return theme.colors.danger30;
}
return theme.colors.primary30;
}};
}
`;

export const FileStyled = styled(Flex)<{ isValid: boolean }>`
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/PropTables/FileUploaderPropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const fileUploaderProps: Prop[] = [
},
{
name: 'dropzoneConfig',
types: '{ label?: string; description?: string }',
types: '{ label?: string; description?: string; icon?: ReactNode }',
description: 'Adds a label and a description to the drop-zone box.',
},
{
Expand Down

0 comments on commit 96b8a86

Please sign in to comment.