Skip to content

Commit 8ebb9ed

Browse files
committed
[FIX]: Fix custom children and replace behaviour='replace' in Dropzone
1 parent 8981b82 commit 8ebb9ed

File tree

11 files changed

+74
-72
lines changed

11 files changed

+74
-72
lines changed

README.md

Lines changed: 15 additions & 16 deletions
Large diffs are not rendered by default.

build/index.es.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/index.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 8 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dropzone-ui/react",
3-
"version": "6.5.5",
3+
"version": "6.7.10",
44
"description": "The best and most complete React library for managing file uploads. Multilanguage support. Server side support. Material design styles. Code generator on webpage.",
55
"main": "./build/index.js",
66
"module": "./build/index.es.js",
@@ -35,16 +35,14 @@
3535
"bugs": {
3636
"url": "https://github.com/dropzone-ui/dropzone-ui-react/issues"
3737
},
38-
"homepage": "http://www.dropzone-ui.com",
38+
"homepage": "https://dropzone-ui.herokuapp.com/",
3939
"dependencies": {
40-
"@dynamicss/dynamicss": "^2.2.0",
41-
"@unlimited-react-components/kernel": "^1.0.2",
42-
"@unlimited-react-components/material-button": "^1.2.8"
40+
4341
},
4442
"peerDependencies": {
45-
"axios": "^0.24.0",
46-
"react": "^17.0.2",
47-
"react-dom": "^17.0.2"
43+
"axios": "latest",
44+
"react": "^17.0.0 || ^18.0.0",
45+
"react-dom": "^17.0.0 || ^18.0.0"
4846
},
4947
"devDependencies": {
5048
"@rollup/plugin-commonjs": "^21.0.1",

src/components/dropzone/components/Dropzone/Dropzone.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,14 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
293293
}
294294
};
295295
const handleFilesChange = (output: FileValidated[]) => {
296+
//console.log("handleFilesChange:", output);
296297
//setNumberOfValidFiles(output.filter((x:FileValidated) => x.valid).length);
297298
onDrop?.(output);
299+
300+
// onChange fix: when adding more files when max amount was reached
301+
// and behaviour is set to "replace", prevent replacing the current selection
302+
// with a list of non valid files
303+
298304
onChange?.(behaviour === "replace" ? output : [...files, ...output]);
299305

300306
setFiles(output);
@@ -318,19 +324,19 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
318324
return;
319325
}
320326
let fileList: FileList = evt.dataTransfer.files;
327+
321328
const remainingValids: number = (maxFiles || Infinity) - numberOfValidFiles;
322329
const localValidator: FileValidator = {
323330
accept: accept,
324331
maxFileSize: maxFileSize,
325332
};
326333
const output: FileValidated[] = fileListvalidator(
327334
fileList,
328-
remainingValids,
335+
behaviour === "replace" ? maxFiles || Infinity : remainingValids,
329336
localValidator
330337
);
331338
if (!disableRipple) {
332339
createRippleFromElement(dz_ui_ripple_ref.current, evt, color as string);
333-
334340
// createRipple(evt, color as string);
335341
}
336342
setIsDragging(false);
@@ -351,7 +357,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
351357
};
352358
const output: FileValidated[] = fileListvalidator(
353359
fileList,
354-
remainingValids,
360+
behaviour === "replace" ? maxFiles || Infinity : remainingValids,
355361
localValidator
356362
);
357363
// Clean input element to trigger onChange event on input
@@ -467,6 +473,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
467473
localization={localization}
468474
/>
469475
)}
476+
470477
{children && value && files && files.length > 0 ? (
471478
<FileItemContainer
472479
view={localView}
@@ -481,9 +488,15 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
481488
{children}
482489
</FileItemContainer>
483490
) : (
484-
<DropzoneLabel>
485-
{label || (DropzoneLocalizer.defaultLabel as string)}
486-
</DropzoneLabel>
491+
<>
492+
{children ? (
493+
<>{children}</>
494+
) : (
495+
<DropzoneLabel>
496+
{label || (DropzoneLocalizer.defaultLabel as string)}
497+
</DropzoneLabel>
498+
)}
499+
</>
487500
)}
488501

489502
{footer && (

src/components/dropzone/components/DropzoneFooter.tsx/DropzoneFooter.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,24 @@ import {
77
import { DropzoneFooterProps } from "./DropzoneFooterProps";
88

99
const DropzoneFooter: FC<DropzoneFooterProps> = (
10-
props: DropzoneFooterProps,
10+
props: DropzoneFooterProps
1111
) => {
1212
const { accept, message, localization } = props;
1313

1414
const DropzoneFooterLocalizer: LocalLabels = DropzoneLocalizerSelector(
15-
localization,
15+
localization
1616
).footer as LocalLabels;
1717
const accepCustomMessenger: FunctionLabel =
1818
DropzoneFooterLocalizer.acceptCustom as FunctionLabel;
1919
return (
2020
<div className="dz-ui-footer" onClick={undefined}>
21-
{/* message
22-
? message
23-
: !accept
24-
? localization === "ES-es"
25-
? `Todos los tipos de archivo aceptados`
26-
: `All file types accepted`
27-
: localization === "ES-es"
28-
? `Archivos aceptados: ${accept}`
29-
: `File types: ${accept}` */}
30-
{message
31-
? message
32-
: !accept
33-
? DropzoneFooterLocalizer.acceptAll
34-
: accepCustomMessenger(accept)}
21+
<>
22+
{message
23+
? message
24+
: !accept
25+
? DropzoneFooterLocalizer.acceptAll
26+
: accepCustomMessenger(accept)}
27+
</>
3528
</div>
3629
);
3730
};

src/components/dropzone/components/DropzoneHeader/DropzoneHeader.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface DropzoneHeaderProps {
3232
* only English and Spanish is supported
3333
*/
3434
localization?: Localization;
35-
hideViewIcon?:boolean;
35+
hideViewIcon?: boolean;
3636
}
3737

3838
const DropzoneHeader: FC<DropzoneHeaderProps> = (
@@ -71,10 +71,12 @@ const DropzoneHeader: FC<DropzoneHeaderProps> = (
7171
} else {
7272
result.push(
7373
<Fragment>
74-
{DropzoneHeaderLocalizer.uploadFilesMessage}
75-
{/* localization === "ES-es" ? `Subir archivos` : "Upload files" */}
74+
<>
75+
{DropzoneHeaderLocalizer.uploadFilesMessage}
76+
{/* localization === "ES-es" ? `Subir archivos` : "Upload files" */}
7677

77-
<Upload color="#646c7f" onClick={handleStartUploading} />
78+
<Upload color="#646c7f" onClick={handleStartUploading} />
79+
</>
7880
</Fragment>
7981
);
8082
}

src/components/paper/components/PaperProps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { OverridableProps } from "@unlimited-react-components/kernel";
22

33

4+
45
export interface PaperProps extends OverridableProps {
56
/**
67
* The elevation of the paper to produce a shadow
@@ -25,7 +26,7 @@ export interface PaperProps extends OverridableProps {
2526
component?: "div" | "span";
2627
}
2728
export const PaperPropsDefault: PaperProps = {
28-
children: () => { },
29+
children: undefined,
2930
shadow: 2,
3031
className: "",
3132
style: {},

0 commit comments

Comments
 (0)