diff --git a/src/components/drop-zone/DropZone.tsx b/src/components/drop-zone/DropZone.tsx index e3556746..ef28dad9 100644 --- a/src/components/drop-zone/DropZone.tsx +++ b/src/components/drop-zone/DropZone.tsx @@ -12,7 +12,12 @@ export interface DropZoneProps { ) => void; fileValidator?: (file: T) => FileError | FileError[] | null; } - +const centerStyle = css` + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +`; export function DropZoneContainer( props: DropZoneProps & { children: JSX.Element; @@ -30,7 +35,11 @@ export function DropZoneContainer( ); } -export function DropZone(props: DropZoneProps) { +export function DropZone( + props: DropZoneProps & { + emptyText?: string; + }, +) { return ; } @@ -39,12 +48,14 @@ function DropZoneContent( children?: JSX.Element; isContainer?: boolean; onClick?: MouseEventHandler; + emptyText?: string; }, ) { const { color = 'black', children, onDrop, + emptyText = 'Drag and drop your files here, or click to select files', isContainer = false, onClick, fileValidator, @@ -60,7 +71,6 @@ function DropZoneContent( validator: fileValidator, onDrop: handleOnDrop, }); - const getPropsOptions = useMemo(() => { if (onClick) { return { onClick }; @@ -102,14 +112,7 @@ function DropZoneContent(
{isDragActive ? ( -
+
Drop the files here

) : isContainer ? null : ( -

Drag and drop your files here, or click to select files

+

{emptyText}

)}
diff --git a/stories/components/drop-zone.stories.tsx b/stories/components/drop-zone.stories.tsx index 3a3c68eb..210d9593 100644 --- a/stories/components/drop-zone.stories.tsx +++ b/stories/components/drop-zone.stories.tsx @@ -17,7 +17,7 @@ interface DropZoneStoryProps { } function fileValidator(file: File) { - if (file.name.length > 20) { + if (file?.name?.length > 20) { return { message: 'File name is larger than 20 characters', code: 'name-too-large', @@ -26,13 +26,19 @@ function fileValidator(file: File) { return null; } -export function Control({ color }: DropZoneStoryProps) { +export function Control({ + color, + emptyText, +}: DropZoneStoryProps & { + emptyText?: string; +}) { const [files, setFiles] = useState([]); return (
{ setFiles(files); }} @@ -57,6 +63,7 @@ export function Control({ color }: DropZoneStoryProps) { Control.args = { color: 'black', + emptyText: 'Drag and drop your files', }; export function DropZoneContainerControl({ color }: DropZoneStoryProps) {