2024-09-17 11:55:21 +05:30
|
|
|
import React, { createContext, useContext, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
const DragWidgetContext = createContext()
|
|
|
|
|
|
|
|
|
|
export const useDragWidgetContext = () => useContext(DragWidgetContext)
|
|
|
|
|
|
2024-09-27 11:42:34 +05:30
|
|
|
// Provider component to wrap around parts that need drag-and-drop functionality
|
2024-09-17 11:55:21 +05:30
|
|
|
export const DragWidgetProvider = ({ children }) => {
|
|
|
|
|
const [draggedElement, setDraggedElement] = useState(null)
|
|
|
|
|
|
|
|
|
|
const onDragStart = (element) => {
|
|
|
|
|
setDraggedElement(element)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onDragEnd = () => {
|
|
|
|
|
setDraggedElement(null)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<DragWidgetContext.Provider value={{ draggedElement, onDragStart, onDragEnd }}>
|
|
|
|
|
{children}
|
|
|
|
|
</DragWidgetContext.Provider>
|
|
|
|
|
)
|
|
|
|
|
}
|