Skip to content

Commit

Permalink
feat(Upload): hides file extension text
Browse files Browse the repository at this point in the history
  • Loading branch information
langz committed Oct 18, 2024
1 parent 47bd8d3 commit f8d689b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export const UploadFileMaxSizeBasedOnFileType = () => (
{ fileType: 'txt', fileMaxSize: 0 },
{ fileType: 'zip', fileMaxSize: 99 },
]}
displayFileExtensionText={false}
/>
</ComponentBox>
)
Expand Down
1 change: 1 addition & 0 deletions packages/dnb-eufemia/src/components/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const Upload = (localProps: UploadAllProps) => {
errorAmountLimit, // eslint-disable-line
deleteButton, // eslint-disable-line
fileListAriaLabel, // eslint-disable-line
displayFileExtensionText, // eslint-disable-line
...props
} = extendedProps

Expand Down
9 changes: 7 additions & 2 deletions packages/dnb-eufemia/src/components/upload/UploadDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export const UploadProperties: PropertiesTableProps = {
status: 'required',
},
filesAmountLimit: {
doc: 'Defines the amount of files the user can select and upload. Defaults to 100.',
doc: 'Defines the amount of files the user can select and upload. Defaults to `100`.',
type: 'number',
status: 'optional',
},
fileMaxSize: {
doc: 'Defines the max file size of each file in MB. Use either `0` or `false` to disable. Defaults to 5 MB.',
doc: 'Defines the max file size of each file in MB. Use either `0` or `false` to disable. Defaults to `5`, 5 MB.',
type: ['number', 'false'],
status: 'optional',
},
Expand All @@ -26,6 +26,11 @@ export const UploadProperties: PropertiesTableProps = {
type: 'string',
status: 'optional',
},
displayFileExtensionText: {
doc: 'Defines if the file extension should be displayed in the file list for each file. Defaults to `true`.',
type: 'boolean',
status: 'optional',
},
skeleton: {
doc: 'Skeleton should be applied when loading content.',
type: 'boolean',
Expand Down
2 changes: 2 additions & 0 deletions packages/dnb-eufemia/src/components/upload/UploadFileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function UploadFileList() {
loadingText,
onFileDelete,
onChange,
displayFileExtensionText,
} = context

const { files, setFiles, setInternalFiles } = useUpload(id)
Expand Down Expand Up @@ -50,6 +51,7 @@ function UploadFileList() {
onDelete={onDeleteHandler}
deleteButtonText={deleteButton}
loadingText={loadingText}
displayFileExtensionText={displayFileExtensionText}
/>
)
})}
Expand Down
22 changes: 15 additions & 7 deletions packages/dnb-eufemia/src/components/upload/UploadFileListCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export type UploadFileListCellProps = {
*/
uploadFile: UploadFile

/**
* Wether or not to display the file extension text for the uploaded file
*/
displayFileExtensionText?: boolean

/**
* Calls onDelete when clicking the delete button
*/
Expand All @@ -63,6 +68,7 @@ const UploadFileListCell = ({
onDelete,
loadingText,
deleteButtonText,
displayFileExtensionText = true,
}: UploadFileListCellProps) => {
const { file, errorMessage, isLoading } = uploadFile
const hasWarning = errorMessage != null
Expand Down Expand Up @@ -169,13 +175,15 @@ const UploadFileListCell = ({
>
{file.name}
</a>
<P
className="dnb-upload__file-cell__subtitle"
size="x-small"
top="xx-small"
>
{humanFileType}
</P>
{displayFileExtensionText && (
<P
className="dnb-upload__file-cell__subtitle"
size="x-small"
top="xx-small"
>
{humanFileType}
</P>
)}
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,26 @@ describe('UploadFileListCell', () => {
)

const element = document.querySelector('.dnb-upload__file-cell__title')
const fileExtension = document.querySelector(
'.dnb-upload__file-cell__subtitle'
)

expect(element.textContent).toMatch('file.dat')
expect(fileExtension.textContent).toMatch('DAT')
})

it('supports not displaying file extension text', async () => {
render(
<UploadFileListCell
{...defaultProps}
uploadFile={{ file: createMockFile('file.dat', 100, 'dat') }}
displayFileExtensionText={false}
/>
)

expect(
document.querySelector('.dnb-upload__file-cell__subtitle')
).not.toBeInTheDocument()
})

it('renders the no error styling', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/dnb-eufemia/src/components/upload/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export type UploadProps = {
*/
onFileDelete?: ({ fileItem }: { fileItem: UploadFile }) => void

/**
* Defines if the file extension should be displayed in the file list for each file.
* Default: true
*/
displayFileExtensionText?: boolean

/**
* Custom text properties
*/
Expand Down

0 comments on commit f8d689b

Please sign in to comment.