fix(ui): fix longstanding drag-and-drop duplication issue (#502)
* fix(ui): fixed color switching on list reordering * chore: remove lock file * chore: add back lock file * feat(ui): fix color duplication issue and prevent scrolling beyond parent * feat(ui): add to storybook * fix(ui): remove white background while dragging * chore: remove dnd pangea from package.json * chore: rebuild lock file * chore: remove nested li element issue * fix(ui): allow grabbing cursor while dragging * fix(ui): address chromatic errors * fix(ui): address chromatic errors * fix(ui): address linting issues and pass tests * fix(ui): create hook for modifying the cursor globally * chore: add check for storybook env * chore: add back unused import to AddAllButton * fix: make cursor grabbing hook more explicit * chore: move sortable list item into sortable list file * fix: remove isStorybook prop from ScheduleListItem --------- Co-authored-by: doprz <52579214+doprz@users.noreply.github.com>
This commit is contained in:
34
src/views/contexts/SortableItemContext.tsx
Normal file
34
src/views/contexts/SortableItemContext.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { DraggableAttributes, DraggableSyntheticListeners } from '@dnd-kit/core';
|
||||
import type { ReactNode } from 'react';
|
||||
import React, { createContext } from 'react';
|
||||
|
||||
interface Context {
|
||||
attributes: DraggableAttributes;
|
||||
listeners: DraggableSyntheticListeners;
|
||||
ref(node: HTMLElement | null): void;
|
||||
}
|
||||
|
||||
export const SortableItemContext = createContext<Context | null>(null);
|
||||
|
||||
interface SortableItemProviderProps {
|
||||
value: Context;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the sortable item context to its children
|
||||
*/
|
||||
export const SortableItemProvider: React.FC<SortableItemProviderProps> = ({ value, children }) => (
|
||||
<SortableItemContext.Provider value={value}>{children}</SortableItemContext.Provider>
|
||||
);
|
||||
|
||||
/**
|
||||
* @returns The sortable item context
|
||||
*/
|
||||
export const useSortableItemContext = () => {
|
||||
const context = React.useContext(SortableItemContext);
|
||||
if (!context) {
|
||||
throw new Error('useSortableItemContext must be used within a SortableItemContext.Provider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user