1- // @ts -nocheck
1+ //@ts -nocheck
22import React , { useState , useEffect , useCallback } from "react" ;
33import styled , { ThemeProvider } from "styled-components" ;
44import { v4 as uuidv4 } from "uuid" ;
55import { spaces } from "../common/variables.js" ;
66import useTheme from "../useTheme" ;
77import useTranslatedLabels from "../useTranslatedLabels" ;
88import DxcButton from "../button/Button" ;
9- import FileItem from "./FileItem" ;
109import FileInputPropsType from "./types" ;
10+ import FileItem from "./FileItem" ;
1111
1212const audioIcon = (
1313 < svg xmlns = "http://www.w3.org/2000/svg" width = "24" height = "24" viewBox = "0 0 24 24" fill = "currentColor" >
@@ -168,7 +168,7 @@ const DxcFileInput = ({
168168 </ Label >
169169 < HelperText disabled = { disabled } > { helperText } </ HelperText >
170170 { mode === "file" ? (
171- < FileContainer multiple = { multiple } files = { files } >
171+ < FileContainer singleFileMode = { ! multiple && files . length === 1 } >
172172 < ValueInput
173173 id = { fileInputId }
174174 type = "file"
@@ -193,22 +193,22 @@ const DxcFileInput = ({
193193 size = "fitContent"
194194 tabIndex = { tabIndex }
195195 />
196- < FileItemListContainer mode = { mode } multiple = { multiple } files = { files } >
197- { files . map ( ( file ) => (
198- < FileItem
199- mode = { mode }
200- multiple = { multiple }
201- name = { file . file . name }
202- error = { file . error }
203- showPreview = { mode === "file" && ! multiple ? false : showPreview }
204- numFiles = { files . length }
205- preview = { file . preview }
206- type = { file . file . type }
207- onDelete = { onDelete }
208- tabIndex = { tabIndex }
209- />
210- ) ) }
211- </ FileItemListContainer >
196+ { files . length > 0 && (
197+ < FileItemListContainer >
198+ { files . map ( ( file ) => (
199+ < FileItem
200+ fileName = { file . file . name }
201+ error = { file . error }
202+ singleFileMode = { ! multiple && files . length === 1 }
203+ showPreview = { mode === "file" && ! multiple ? false : showPreview }
204+ preview = { file . preview }
205+ type = { file . file . type }
206+ onDelete = { onDelete }
207+ tabIndex = { tabIndex }
208+ />
209+ ) ) }
210+ </ FileItemListContainer >
211+ ) }
212212 </ FileContainer >
213213 ) : (
214214 < Container >
@@ -232,15 +232,13 @@ const DxcFileInput = ({
232232 onDragOver = { handleDrag }
233233 onDragLeave = { handleDragOut }
234234 >
235- < ButtonContainer mode = { mode } >
236- < DxcButton
237- mode = "secondary"
238- label = { buttonLabel ?? translatedLabels . fileInput . dropAreaButtonLabelDefault }
239- onClick = { handleClick }
240- disabled = { disabled }
241- size = "fitContent"
242- />
243- </ ButtonContainer >
235+ < DxcButton
236+ mode = "secondary"
237+ label = { buttonLabel ?? translatedLabels . fileInput . dropAreaButtonLabelDefault }
238+ onClick = { handleClick }
239+ disabled = { disabled }
240+ size = "fitContent"
241+ />
244242 { mode === "dropzone" ? (
245243 < DropzoneLabel disabled = { disabled } >
246244 { dropAreaLabel ??
@@ -257,26 +255,27 @@ const DxcFileInput = ({
257255 </ FiledropLabel >
258256 ) }
259257 </ DragDropArea >
260- < FileItemListContainer mode = { mode } multiple = { multiple } files = { files } >
261- { files . map ( ( file ) => (
262- < FileItem
263- mode = { mode }
264- multiple = { multiple }
265- name = { file . file . name }
266- error = { file . error }
267- showPreview = { showPreview }
268- numFiles = { files . length }
269- preview = { file . preview }
270- type = { file . file . type }
271- onDelete = { onDelete }
272- tabIndex = { tabIndex }
273- />
274- ) ) }
275- </ FileItemListContainer >
258+ { files . length > 0 && (
259+ < FileItemListContainer >
260+ { files . map ( ( file ) => (
261+ < FileItem
262+ fileName = { file . file . name }
263+ error = { file . error }
264+ singleFileMode = { false }
265+ showPreview = { showPreview }
266+ preview = { file . preview }
267+ type = { file . file . type }
268+ onDelete = { onDelete }
269+ tabIndex = { tabIndex }
270+ />
271+ ) ) }
272+ </ FileItemListContainer >
273+ ) }
276274 </ Container >
277275 ) }
278- { files . length === 1 &&
279- files . map ( ( file ) => file . error && mode === "file" && ! multiple && < ErrorMessage > { file . error } </ ErrorMessage > ) }
276+ { mode === "file" && ! multiple && files . length === 1 && files [ 0 ] . error && (
277+ < ErrorMessage > { files [ 0 ] . error } </ ErrorMessage >
278+ ) }
280279 </ FileInputContainer >
281280 </ ThemeProvider >
282281 ) ;
@@ -313,12 +312,10 @@ const HelperText = styled.span`
313312 line-height: ${ ( props ) => props . theme . helperTextLineHeight } ;
314313` ;
315314
316- const FileContainer = styled . div `
315+ const FileContainer = styled . div < { singleFileMode : boolean } > `
317316 display: flex;
318317 ${ ( props ) =>
319- props . multiple || props . files . length > 1
320- ? "flex-direction: column; row-gap: 0.25rem;"
321- : "flex-direction: row; column-gap: 0.25rem;" }
318+ props . singleFileMode ? "flex-direction: row; column-gap: 0.25rem;" : "flex-direction: column; row-gap: 0.25rem;" }
322319 margin-top: 0.25rem;
323320` ;
324321
@@ -342,11 +339,16 @@ const Container = styled.div`
342339const DragDropArea = styled . div `
343340 box-sizing: border-box;
344341 display: flex;
345- flex-direction: ${ ( props ) => ( props . mode === "filedrop" ? "row" : "column" ) } ;
346- ${ ( props ) => props . mode === "dropzone" && "justify-content: center; padding: 1rem;" } ;
342+ ${ ( props ) =>
343+ props . mode === "filedrop"
344+ ? "flex-direction: row; column-gap: 0.75rem; height: 48px;"
345+ : "justify-content: center; flex-direction: column; row-gap: 0.5rem; height: 160px;" }
347346 align-items: center;
348- height: ${ ( props ) => ( props . mode === "filedrop" ? "48px" : "160px" ) } ;
349347 width: 320px;
348+ padding: ${ ( props ) =>
349+ props . mode === "filedrop"
350+ ? `calc(4px - ${ props . theme . dropBorderThickness } ) 1rem calc(4px - ${ props . theme . dropBorderThickness } ) calc(4px - ${ props . theme . dropBorderThickness } )`
351+ : "1rem" } ;
350352 overflow: hidden;
351353 box-shadow: 0 0 0 2px transparent;
352354 border-radius: ${ ( props ) => props . theme . dropBorderRadius } ;
@@ -365,18 +367,13 @@ const DragDropArea = styled.div`
365367 cursor: ${ ( props ) => props . disabled && "not-allowed" } ;
366368` ;
367369
368- const ButtonContainer = styled . div `
369- ${ ( props ) => props . mode === "filedrop" && "padding: 2px 12px 2px 3px" } ;
370- ` ;
371-
372370const DropzoneLabel = styled . div `
373371 display: -webkit-box;
374372 -webkit-box-orient: vertical;
375373 overflow: hidden;
376374 text-overflow: ellipsis;
377375 -webkit-line-clamp: 3;
378376 text-align: center;
379- margin-top: 0.5rem;
380377 color: ${ ( props ) => ( props . disabled ? props . theme . disabledDropLabelFontColor : props . theme . dropLabelFontColor ) } ;
381378 font-family: ${ ( props ) => props . theme . dropLabelFontFamily } ;
382379 font-size: ${ ( props ) => props . theme . dropLabelFontSize } ;
@@ -391,7 +388,6 @@ const FiledropLabel = styled.span`
391388 font-family: ${ ( props ) => props . theme . dropLabelFontFamily } ;
392389 font-size: ${ ( props ) => props . theme . dropLabelFontSize } ;
393390 font-weight: ${ ( props ) => props . theme . dropLabelFontWeight } ;
394- margin-right: 1rem;
395391` ;
396392
397393const ErrorMessage = styled . div `
0 commit comments