-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5710 from gooddata/ine-lx-599
feat: show resizers + new style
- Loading branch information
Showing
17 changed files
with
281 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
libs/sdk-ui-dashboard/src/presentation/dragAndDrop/HoveredWidgetContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// (C) 2024 GoodData Corporation | ||
import { ObjRef, areObjRefsEqual } from "@gooddata/sdk-model"; | ||
import React, { createContext, useContext, useState, ReactNode } from "react"; | ||
|
||
// Define the shape of the context state | ||
interface HoveredWidgetContextState { | ||
hoveredWidgets: ObjRef[] | null; | ||
addHoveredWidget: (widgetRef: ObjRef | null) => void; | ||
removeHoveredWidget: (widgetRef: ObjRef | null) => void; | ||
isHovered: (widgetRef: ObjRef) => boolean; | ||
} | ||
|
||
// Create the context with a default value | ||
const HoveredWidgetContext = createContext<HoveredWidgetContextState | undefined>(undefined); | ||
|
||
// Create the provider component | ||
export const HoveredWidgetProvider: React.FC<{ children: ReactNode }> = ({ children }) => { | ||
const [hoveredWidgets, setHoveredWidget] = useState<ObjRef[]>([]); | ||
|
||
const addHoveredWidget = (widgetRef: ObjRef | null) => { | ||
if (widgetRef && !hoveredWidgets?.some((ref) => areObjRefsEqual(ref, widgetRef))) { | ||
setHoveredWidget((prevWidgets) => [...(prevWidgets || []), widgetRef]); | ||
} | ||
}; | ||
|
||
const removeHoveredWidget = (widgetRef: ObjRef | null) => { | ||
if (widgetRef && hoveredWidgets) { | ||
setHoveredWidget( | ||
(prevWidgets) => prevWidgets?.filter((ref) => !areObjRefsEqual(ref, widgetRef)) ?? [], | ||
); | ||
} | ||
}; | ||
|
||
const isHovered = (widgetRef: ObjRef) => { | ||
return hoveredWidgets?.some((ref) => areObjRefsEqual(ref, widgetRef)) || false; | ||
}; | ||
|
||
return ( | ||
<HoveredWidgetContext.Provider | ||
value={{ hoveredWidgets, addHoveredWidget, removeHoveredWidget, isHovered }} | ||
> | ||
{children} | ||
</HoveredWidgetContext.Provider> | ||
); | ||
}; | ||
|
||
// Custom hook to use the HoveredWidgetContext | ||
export const useHoveredWidget = (): HoveredWidgetContextState => { | ||
const context = useContext(HoveredWidgetContext); | ||
if (!context) { | ||
throw new Error("useHoveredWidget must be used within a HoveredWidgetProvider"); | ||
} | ||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
libs/sdk-ui-dashboard/src/presentation/flexibleLayout/dragAndDrop/Resize/HoverDetector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// (C) 2019-2024 GoodData Corporation | ||
import React, { useEffect, useRef } from "react"; | ||
import { ObjRef } from "@gooddata/sdk-model"; | ||
import { useHoveredWidget } from "../../../dragAndDrop/HoveredWidgetContext.js"; | ||
|
||
interface HoverDetectorProps { | ||
widgetRef: ObjRef; | ||
children?: React.ReactNode; | ||
} | ||
|
||
export const HoverDetector: React.FC<HoverDetectorProps> = ({ widgetRef, children }) => { | ||
const { addHoveredWidget, removeHoveredWidget } = useHoveredWidget(); | ||
const divRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
const handleMouseEnter = () => { | ||
addHoveredWidget(widgetRef); | ||
}; | ||
const handleMouseLeave = () => { | ||
removeHoveredWidget(widgetRef); | ||
}; | ||
|
||
const divElement = divRef.current; | ||
if (divElement) { | ||
divElement.addEventListener("mouseenter", handleMouseEnter); | ||
divElement.addEventListener("mouseleave", handleMouseLeave); | ||
} | ||
|
||
return () => { | ||
if (divElement) { | ||
divElement.removeEventListener("mouseenter", handleMouseEnter); | ||
divElement.removeEventListener("mouseleave", handleMouseLeave); | ||
} | ||
}; | ||
}, [addHoveredWidget, removeHoveredWidget, widgetRef]); | ||
|
||
return ( | ||
<div ref={divRef} className="gd-hover-detector"> | ||
{children} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
libs/sdk-ui-dashboard/src/presentation/flexibleLayout/dragAndDrop/Resize/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.