Files
spacedrive/interface/app/$libraryId/Explorer/ExplorerDroppable.tsx
nikec caf4fc5cde [ENG-1353] explorer dnd (#1737)
* locations dnd

* fix icon

* reduce navigate timeout

* fix types

* another

* fix drag overlay count

* Update pnpm-lock.yaml

* merge

* ephemeral support and other improvements

* merge

* Tag dnd

* merge

* type

* merge

* remove offset

* update dnd logic to not depend on drag source

* handle allowed types if parent isn't available

* saved searches dnd navigation

* well

* rendering

* Update pnpm-lock.yaml

* types

* remove width

* Temporary solution

* merge

* @dnd-kit/utilities

* Update pnpm-lock.yaml

* explorer path dnd

* remove unused drag hook

* fix dnd on LayeredFileIcon

---------

Co-authored-by: Brendan Allan <brendonovich@outlook.com>
2023-12-13 11:59:27 +00:00

37 lines
1.2 KiB
TypeScript

import clsx from 'clsx';
import { createContext, HTMLAttributes, useContext, useMemo } from 'react';
import { useExplorerDroppable, UseExplorerDroppableProps } from './useExplorerDroppable';
const ExplorerDroppableContext = createContext<{ isDroppable: boolean } | null>(null);
export const useExplorerDroppableContext = () => {
const ctx = useContext(ExplorerDroppableContext);
if (ctx === null) throw new Error('ExplorerDroppableContext.Provider not found!');
return ctx;
};
/**
* Wrapper for explorer droppable items until dnd-kit solvers their re-rendering issues
* https://github.com/clauderic/dnd-kit/issues/1194#issuecomment-1696704815
*/
export const ExplorerDroppable = ({
droppable,
children,
...props
}: HTMLAttributes<HTMLDivElement> & { droppable: UseExplorerDroppableProps }) => {
const { isDroppable, className, setDroppableRef } = useExplorerDroppable(droppable);
const context = useMemo(() => ({ isDroppable }), [isDroppable]);
return (
<ExplorerDroppableContext.Provider value={context}>
<div {...props} ref={setDroppableRef} className={clsx(props.className, className)}>
{children}
</div>
</ExplorerDroppableContext.Provider>
);
};