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] FileInput & FileItem circular dependency #884

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 1 addition & 10 deletions src/core/Form/FileInput/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { StatusText } from '../StatusText/StatusText';
import { FileItem } from './FileItem';

const baseClassName = 'fi-file-input';
export const fileInputClassNames = {
const fileInputClassNames = {
fullWidth: `${baseClassName}--full-width`,
inputOuterWrapper: `${baseClassName}_input-outer-wrapper`,
dragArea: `${baseClassName}_drag-area`,
Expand All @@ -57,16 +57,7 @@ export const fileInputClassNames = {
statusTextHasContent: `${baseClassName}_statusText--has-content`,
hiddenUnderFile: `${baseClassName}_label--hidden-under-file`,
dragAreaHasFile: `${baseClassName}_drag-area--has-file`,
fileItemOuterWrapper: `${baseClassName}_file-item-outer-wrapper`,
fileItem: `${baseClassName}_file-item`,
fileInfo: `${baseClassName}_file-info`,
fileName: `${baseClassName}_file-name`,
fileSize: `${baseClassName}_file-size`,
removeFileButton: `${baseClassName}_remove-file-button`,
smallScreen: `${baseClassName}--small-screen`,
errorIcon: `${baseClassName}_error-icon`,
loadingIcon: `${baseClassName}_loading-icon`,
fileItemErrorText: `${baseClassName}_file-item-error-text`,
};

interface BaseFileInputProps
Expand Down
39 changes: 24 additions & 15 deletions src/core/Form/FileInput/FileItem.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import React, { ReactNode } from 'react';
import {
ControlledFileItem,
FileItemRefs,
fileInputClassNames,
} from './FileInput';
import { ControlledFileItem, FileItemRefs } from './FileInput';
import { Button } from '../../Button/Button';
import { HtmlDiv, HtmlDivWithRef } from '../../../reset/HtmlDiv/HtmlDiv';
import {
Expand All @@ -30,6 +26,19 @@ interface FileItemProps {
metaData?: ControlledFileItem;
}

const baseClassName = 'fi-file-input';
const fileItemClassNames = {
fileItemOuterWrapper: `${baseClassName}_file-item-outer-wrapper`,
fileItem: `${baseClassName}_file-item`,
fileInfo: `${baseClassName}_file-info`,
fileName: `${baseClassName}_file-name`,
fileSize: `${baseClassName}_file-size`,
removeFileButton: `${baseClassName}_remove-file-button`,
errorIcon: `${baseClassName}_error-icon`,
loadingIcon: `${baseClassName}_loading-icon`,
fileItemErrorText: `${baseClassName}_file-item-error-text`,
};

const BaseFileItem = (props: FileItemProps) => {
const {
file,
Expand Down Expand Up @@ -74,16 +83,16 @@ const BaseFileItem = (props: FileItemProps) => {

return (
<HtmlDiv
className={fileInputClassNames.fileItemOuterWrapper}
className={fileItemClassNames.fileItemOuterWrapper}
role={multiFile ? 'listitem' : undefined}
>
<HtmlDiv className={fileInputClassNames.fileItem}>
<HtmlDiv className={fileInputClassNames.fileInfo}>
<HtmlDiv className={fileItemClassNames.fileItem}>
<HtmlDiv className={fileItemClassNames.fileInfo}>
{metaData?.status === 'error' && (
<IconErrorFilled className={fileInputClassNames.errorIcon} />
<IconErrorFilled className={fileItemClassNames.errorIcon} />
)}
{metaData?.status === 'loading' && (
<IconPreloader className={fileInputClassNames.loadingIcon} />
<IconPreloader className={fileItemClassNames.loadingIcon} />
)}
{!metaData?.status && <IconGenericFile />}
{filePreview ? (
Expand All @@ -92,7 +101,7 @@ const BaseFileItem = (props: FileItemProps) => {
fileItemRefs.fileNameRef as React.RefObject<HTMLAnchorElement>
}
href={URL.createObjectURL(file)}
className={classnames(fileInputClassNames.fileName, 'is-link')}
className={classnames(fileItemClassNames.fileName, 'is-link')}
target="_blank"
aria-label={getFileAriaLabel()}
aria-describedby={fileItemRefs.fileSizeElementId}
Expand All @@ -104,15 +113,15 @@ const BaseFileItem = (props: FileItemProps) => {
forwardedRef={
fileItemRefs.fileNameRef as React.RefObject<HTMLDivElement>
}
className={fileInputClassNames.fileName}
className={fileItemClassNames.fileName}
aria-label={getFileAriaLabel()}
aria-describedby={fileItemRefs.fileSizeElementId}
>
{file.name}
</HtmlDivWithRef>
)}
<HtmlDiv
className={fileInputClassNames.fileSize}
className={fileItemClassNames.fileSize}
id={filePreview ? fileItemRefs.fileSizeElementId : undefined}
>
{`(${getFileSizeText()})`}
Expand All @@ -139,14 +148,14 @@ const BaseFileItem = (props: FileItemProps) => {
aria-label={`${
metaData?.buttonText ? metaData.buttonText : removeFileText
} ${file.name}`}
className={fileInputClassNames.removeFileButton}
className={fileItemClassNames.removeFileButton}
ref={fileItemRefs.removeButtonRef}
>
{getButtonText()}
</Button>
</HtmlDiv>
{metaData?.errorText && (
<HtmlDiv className={fileInputClassNames.fileItemErrorText}>
<HtmlDiv className={fileItemClassNames.fileItemErrorText}>
{metaData.errorText}
</HtmlDiv>
)}
Expand Down