Skip to content
Snippets Groups Projects
Commit b5127cbe authored by Jose Manuel Serrano Amaut's avatar Jose Manuel Serrano Amaut
Browse files

[FIX]: Solve issue when multiple dropzones are in the same page. Specify a...

[FIX]: Solve issue when multiple dropzones are in the same page. Specify a unique id for each dropzone drop layer and styles related to border and bg color
parent 9865add3
No related branches found
No related tags found
No related merge requests found
import { DynamicSheet, DynamiCSS } from "@dynamicss/dynamicss"; import { DynamicSheet, DynamiCSS } from "@dynamicss/dynamicss";
import * as React from "react"; import * as React from "react";
import { dropLayerDynamicStyle } from "../utils/dropLayerDynamicStyle"; import { makeDropLayerDynamicStyle } from "../utils/dropLayerDynamicStyle";
const BASE_DROP_LAYER_STYLE: string = "files-ui-styles-drop-layer";
const DROP_LAYER_STYLE_ID: string = "files-ui-styles-drop-layer";
/** /**
* *
* @param color * @param color
...@@ -11,26 +13,48 @@ const DROP_LAYER_STYLE_ID: string = "files-ui-styles-drop-layer"; ...@@ -11,26 +13,48 @@ const DROP_LAYER_STYLE_ID: string = "files-ui-styles-drop-layer";
* @returns the classname for layer * @returns the classname for layer
*/ */
const useDropLayerClassName = ( const useDropLayerClassName = (
dropzoneId: string,
color?: string, color?: string,
isDragging?: boolean, //isDragging?: boolean,
makeClassName?: boolean makeClassName?: boolean
): string => { ): string => {
const [idStyles, setIdStyles] = React.useState<string>(""); const [idStyles, setIdStyles] = React.useState<string>("");
const [styleInjected, setStyleInjected] = React.useState<boolean>(false); const [styleInjected, setStyleInjected] = React.useState<boolean>(false);
const [classNameCreated, setClassNameCreated] = React.useState<string>(""); const [classNameCreated, setClassNameCreated] = React.useState<string>("");
const finalDropzoneId: string = (color === undefined) ? "default" : dropzoneId.replaceAll(":", "_");
React.useEffect(() => { React.useEffect(() => {
//console.log("useDropLayerClassName", color, isDragging, makeClassName); //console.log("useDropLayerClassName", color, isDragging, makeClassName);
const handleInserStyle = ( const handleInserStyle = (
color: string, color?: string,
isDragging?: boolean //isDragging?: boolean
) => { ) => {
let finalClassName: string = ""; let finalClassName: string = "";
let styleSheet: DynamicSheet = dropLayerDynamicStyle(DROP_LAYER_STYLE_ID, color, isDragging); let styleSheet: DynamicSheet = makeDropLayerDynamicStyle(finalDropzoneId, color
//isDragging
);
let idStyle: string = ""; let idStyle: string = "";
if (!styleInjected) { console.log("useDropLayerClassName handleInserStyle", color, styleSheet);
if (finalDropzoneId === "default" && !styleInjected) {
//check if already inserted
if (DynamiCSS.existStyleSheet(finalDropzoneId)) {
setStyleInjected(true);
setIdStyles(idStyle);
} else {
idStyle = DynamiCSS.insertStyleSheet(styleSheet);
setIdStyles(idStyle);
if (idStyle !== "") {
setStyleInjected(true);
}
}
} else if (!styleInjected) {
idStyle = DynamiCSS.insertStyleSheet(styleSheet); idStyle = DynamiCSS.insertStyleSheet(styleSheet);
setIdStyles(idStyle); setIdStyles(idStyle);
if (idStyle !== "") { if (idStyle !== "") {
...@@ -40,22 +64,26 @@ const useDropLayerClassName = ( ...@@ -40,22 +64,26 @@ const useDropLayerClassName = (
//already a stylesheet associated //already a stylesheet associated
DynamiCSS.editStyleSheet(idStyles, styleSheet.sheetRules || []); DynamiCSS.editStyleSheet(idStyles, styleSheet.sheetRules || []);
} }
finalClassName += `dropzone-ui-layer`; finalClassName += `dropzone-layer-${finalDropzoneId}`;
if (isDragging) { /* if (isDragging) {
finalClassName += ` dui-layer-drag`; finalClassName += ` dropzone-layer-drag`;
} } */
setClassNameCreated(finalClassName); setClassNameCreated(finalClassName);
}; };
//console.log("=>", isDragging); //console.log("=>", isDragging);
if (makeClassName) { if (makeClassName) {
handleInserStyle(color as string, isDragging); handleInserStyle(color,
// isDragging
);
} }
// eslint-disable-next-line // eslint-disable-next-line
}, [color, isDragging, makeClassName]); }, [color,
// isDragging,
makeClassName]);
return classNameCreated; return classNameCreated;
} }
......
import { completeAsureColor } from "../../../core"; import { completeAsureColor } from "../../../core";
import { DEFAULT_BORDER_RADIUS } from "../../dropzone/components/dropzone/DropzoneProps"; import { DEFAULT_BORDER_RADIUS } from "../../dropzone/components/dropzone/DropzoneProps";
export const dropLayerDynamicStyle = (styleId: string, color: string | undefined, isDragging: boolean | undefined) => { export const makeDropLayerDynamicStyle = (
dropzoneId: string,
color: string | undefined,
) => {
return { return {
id: "files-ui-styles-drop-layer", id: "files-ui-drop-layer-style-id-" + dropzoneId,
sheetRules: [ sheetRules: [
{ {
className: `dropzone-ui-layer`, className: `dropzone-layer-${dropzoneId}`,
rules: { rules: {
backgroundColor: completeAsureColor(color, 0.4),
backgroundColor:
completeAsureColor(color, 0.4),
borderRadius: DEFAULT_BORDER_RADIUS, borderRadius: DEFAULT_BORDER_RADIUS,
position: "absolute", position: "absolute",
left: 0, left: 0,
top: 0, top: 0,
width: "0%", width: "0%",
height: "0%", height: "0%",
border: isDragging ? `2px dashed ${completeAsureColor(color, 1)}` : undefined,
zIndex: 20, zIndex: 20,
border: `0px dashed ${completeAsureColor(color)}`
}, },
}, },
{ {
className: `dui-layer-drag`, className: `dropzone-layer-drag`,
rules: { rules: {
width: "100%", width: "100%",
height: "100%", height: "100%",
borderWidth:"2px"
}, },
} }
], ],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment