Skip to content

Commit 07d5529

Browse files
committed
[FEAT]: Add disableScroll prop to work together with resultOnTooltip prop of FileItem component
1 parent d312751 commit 07d5529

4 files changed

Lines changed: 108 additions & 24 deletions

File tree

src/components/dropzone/components/Dropzone/Dropzone.scss

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap");
44

55
.dropzone-ui {
6+
.dropzone-ui-ripple {
7+
position: absolute;
8+
width: 0%;
9+
height: 0%;
10+
//background-color: aqua;
11+
top: 0;
12+
left: 0;
13+
overflow: hidden;
14+
//padding-left: 15px;
15+
//z-index: -1;
16+
span.ripple {
17+
// width: 100%;
18+
//height: 100%;
19+
// overflow: hidden;
20+
position: absolute;
21+
border-radius: 50%;
22+
transform: scale(0);
23+
animation: ripple 500ms linear;
24+
background-color: rgba(255, 255, 255, 0.7);
25+
}
26+
27+
@keyframes ripple {
28+
to {
29+
transform: scale(4);
30+
opacity: 0;
31+
}
32+
}
33+
}
634
color: #646c7f;
735
position: relative;
836
min-height: 280px;
@@ -16,15 +44,15 @@
1644
flex-direction: column;
1745
align-items: center;
1846
justify-content: center;
19-
overflow: hidden;
47+
//overflow: hidden;
2048
padding: 24px 0;
2149
&.drag {
2250
border: none;
2351
}
2452
&.clickable {
2553
cursor: pointer;
2654
}
27-
span.ripple {
55+
/* span.ripple {
2856
// width: 100%;
2957
//height: 100%;
3058
// overflow: hidden;
@@ -40,7 +68,7 @@
4068
transform: scale(4);
4169
opacity: 0;
4270
}
43-
}
71+
} */
4472

4573
//verflow: hidden;
4674
.dz-ui-header {

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
validateFile,
1111
} from "../utils/validation.utils";
1212
import { DropzoneProps, DropzonePropsDefault } from "./DropzoneProps";
13-
import { createRipple } from "../utils/dropzone-ui.utils";
13+
import {
14+
createRipple,
15+
createRippleFromElement,
16+
} from "../utils/dropzone-ui.utils";
1417
import DropzoneHeader from "../DropzoneHeader/DropzoneHeader";
1518
import DropzoneFooter from "../DropzoneFooter.tsx/DropzoneFooter";
1619
import { FileItemContainer } from "../../../../components/file-item";
@@ -66,9 +69,10 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
6669
label,
6770
fakeUploading,
6871
localization,
72+
disableScroll,
6973
} = mergeProps(props, DropzonePropsDefault);
70-
71-
74+
//ref for ripple
75+
const dz_ui_ripple_ref = useRef<HTMLDivElement>(null);
7276
//re-validation: for development purposes and for preventing clean fileList in web page code generator
7377
useEffect(() => {
7478
if (files.length > 0) {
@@ -103,14 +107,14 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
103107
const [localView, setLocalView] =
104108
useState<FileItemContainerProps["view"]>("grid");
105109
const [localMessage, setLocalMessage] = useState<string>("");
106-
110+
107111
//ClassName for dynamic style
108112
const [onUploadingStart, setOnUploadingStart] = useState<boolean>(false);
109113
// const [queueFiles, setQueueFiles] = useState<FileValidated[]>([]);
110114
const classNameCreated: string = useDropzoneStyles(
111115
color,
112116
backgroundColor,
113-
maxHeight,
117+
disableScroll ? undefined : maxHeight,
114118
minHeight
115119
);
116120
const finalClassName: string = `dropzone-ui${classNameCreated}${
@@ -126,10 +130,12 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
126130
}
127131
}, [value]);
128132
useEffect(() => {
129-
if (view) {
133+
if (disableScroll) {
134+
setLocalView("grid");
135+
} else if (view) {
130136
setLocalView(view);
131137
}
132-
}, [view]);
138+
}, [view, disableScroll]);
133139
useEffect(() => {
134140
if (uploadingMessage) {
135141
setLocalMessage(uploadingMessage);
@@ -267,12 +273,10 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
267273
DropzoneLocalizer.uploadFinished as FunctionLabel;
268274
setLocalMessage(
269275
finishUploadMessenger(missingUpload - totalRejected, totalRejected)
270-
271276
);
272277
setTimeout(() => {
273278
setOnUploadingStart(false);
274279
}, 2300);
275-
276280
} else {
277281
setLocalMessage(
278282
DropzoneLocalizer.noFilesMessage as string
@@ -322,7 +326,9 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
322326
localValidator
323327
);
324328
if (!disableRipple) {
325-
createRipple(evt, color as string);
329+
createRippleFromElement(dz_ui_ripple_ref.current, color as string);
330+
331+
// createRipple(evt, color as string);
326332
}
327333
setIsDragging(false);
328334
handleFilesChange(output);
@@ -411,7 +417,8 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
411417
let referenceInput = inputRef.current;
412418
referenceInput?.click();
413419
if (!disableRipple) {
414-
createRipple(e, color as string);
420+
createRippleFromElement(dz_ui_ripple_ref.current, color as string);
421+
//createRipple(e, color as string);
415422
}
416423
onClick?.(e);
417424
}
@@ -422,7 +429,6 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
422429
//onDrop?.([]);
423430
};
424431
const handleChangeView = (newView: "grid" | "list") => {
425-
426432
setLocalView(newView);
427433
onChangeView?.(newView);
428434
};
@@ -435,6 +441,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
435441
onClick={clickable ? handleClick : () => {}}
436442
// onDragLeave={handleDragLeave}
437443
>
444+
<div className="dropzone-ui-ripple" ref={dz_ui_ripple_ref}></div>
438445
{header && (
439446
<DropzoneHeader
440447
maxFileSize={maxFileSize}
@@ -444,7 +451,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
444451
//handleReset={handleReset}
445452
onUploadingStart={onUploadingStart}
446453
view={localView}
447-
hideViewIcon={view ? true : false}
454+
hideViewIcon={view || disableScroll ? true : false}
448455
onChangeView={handleChangeView}
449456
onUploadStart={!uploadOnDrop ? handleUploadStart : undefined}
450457
onClean={onClean && !onUploadingStart ? handleCleanFiles : undefined}
@@ -453,7 +460,14 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
453460
/>
454461
)}
455462
{children && value && files && files.length > 0 ? (
456-
<FileItemContainer view={localView} style={{ minHeight, maxHeight }}>
463+
<FileItemContainer
464+
view={localView}
465+
style={{
466+
minHeight: minHeight,
467+
maxHeight: disableScroll ? undefined : maxHeight,
468+
}}
469+
disableScroll={disableScroll}
470+
>
457471
{children}
458472
</FileItemContainer>
459473
) : (

src/components/dropzone/components/Dropzone/DropzoneProps.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,14 @@ export interface DropzoneProps extends OverridableProps {
194194
/**
195195
* language to be used
196196
* for now
197-
* only English, French , Portuguese and Spanish are supported
197+
* only English, French , Portuguese, Chinnese (traditional and simplyfied) and Spanish are supported
198198
*/
199199
localization?: Localization;
200+
/**
201+
* if present or true, removes scrolls
202+
* and sets the Dropzone in a grid view
203+
*/
204+
disableScroll?: boolean;
200205
}
201206

202207
export const DropzonePropsDefault: DropzoneProps = {
@@ -225,7 +230,8 @@ export const DropzonePropsDefault: DropzoneProps = {
225230
onClean: undefined,
226231
behaviour: "add",
227232
label: undefined,
228-
localization: "EN-en"
233+
localization: "EN-en",
234+
disableScroll:undefined
229235
};
230236

231237

src/components/dropzone/components/utils/dropzone-ui.utils.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ export function createRipple<
1010
buttonAnchorDiv.clientWidth,
1111
buttonAnchorDiv.clientHeight
1212
);
13-
const radius = diameter / 2;
13+
const radius: number = diameter / 2;
1414

1515
circle.style.width = circle.style.height = `${diameter}px`;
16-
circle.style.left = `${
17-
event.clientX - buttonAnchorDiv.offsetLeft - radius
18-
}px`;
16+
circle.style.left = `${event.clientX - buttonAnchorDiv.offsetLeft - radius
17+
}px`;
1918
circle.style.top = `${event.clientY - buttonAnchorDiv.offsetTop - radius}px`;
2019
circle.classList.add("ripple");
2120

@@ -29,4 +28,41 @@ export function createRipple<
2928
ripple.remove();
3029
}
3130
buttonAnchorDiv.appendChild(circle);
32-
}
31+
}
32+
33+
34+
export function createRippleFromElement(element: HTMLDivElement | null, color: string) {
35+
if (!element) {
36+
return;
37+
}
38+
const buttonAnchorDiv = element;
39+
buttonAnchorDiv.style.height="100%";
40+
buttonAnchorDiv.style.width="100%";
41+
const circle: HTMLSpanElement = document.createElement("span");
42+
const diameter = Math.max(
43+
buttonAnchorDiv.clientWidth,
44+
buttonAnchorDiv.clientHeight
45+
);
46+
const radius: number = diameter / 2;
47+
48+
circle.style.width = circle.style.height = `${diameter}px`;
49+
circle.style.left = `${buttonAnchorDiv.offsetLeft - radius
50+
}px`;
51+
circle.style.top = `${buttonAnchorDiv.offsetTop - radius}px`;
52+
circle.classList.add("ripple");
53+
54+
circle.style.backgroundColor = hexColorToRGB(
55+
asureColor(colourNameToHex(color)),
56+
0.4
57+
);
58+
59+
const ripple = buttonAnchorDiv.getElementsByClassName("ripple")[0];
60+
if (ripple) {
61+
ripple.remove();
62+
}
63+
buttonAnchorDiv.appendChild(circle);
64+
setTimeout(()=>{
65+
buttonAnchorDiv.style.height="0%";
66+
buttonAnchorDiv.style.width="0%";
67+
},500);
68+
}

0 commit comments

Comments
 (0)