diff --git a/packages/design/src/FormManager/FormEdit/components/PreviewSequencePattern/DraggableList.tsx b/packages/design/src/FormManager/FormEdit/components/PreviewSequencePattern/DraggableList.tsx index 6bc03617..035822ac 100644 --- a/packages/design/src/FormManager/FormEdit/components/PreviewSequencePattern/DraggableList.tsx +++ b/packages/design/src/FormManager/FormEdit/components/PreviewSequencePattern/DraggableList.tsx @@ -1,4 +1,4 @@ -import React, { Children } from 'react'; +import React, { Children, useState } from 'react'; import { DndContext, closestCenter, @@ -7,6 +7,7 @@ import { useSensor, useSensors, UniqueIdentifier, + DragOverlay, } from '@dnd-kit/core'; import { arrayMove, @@ -24,6 +25,7 @@ type DraggableListProps = React.PropsWithChildren<{ order: UniqueIdentifier[]; updateOrder: (order: UniqueIdentifier[]) => void; }>; + export const DraggableList: React.FC = ({ children, order, @@ -35,10 +37,11 @@ export const DraggableList: React.FC = ({ ); const arrayChildren = Children.toArray(children); + const [activeId, setActiveId] = useState(null); return (
{ + onFocus={(event) => { // Stop onFocus events from bubbling up to parent elements. event.stopPropagation(); }} @@ -46,8 +49,13 @@ export const DraggableList: React.FC = ({ { + onDragStart={(event) => { + setActiveId(event.active.id); + }} + onDragEnd={(event) => { const { active, over } = event; + setActiveId(null); + if (over === null) { return; } @@ -58,40 +66,99 @@ export const DraggableList: React.FC = ({ updateOrder(newOrder); } }} + onDragCancel={() => { + setActiveId(null); + }} > {arrayChildren.map((child, index) => { const patternId = order[index]; return ( - + {child} ); })} + + + {activeId ? ( + + {arrayChildren[order.indexOf(activeId)]} + + ) : null} +
); }; +const SortableItemOverlay = ({ + children, +}: { + children: React.ReactNode; +}) => { + const context = useFormManagerStore((state) => state.context); + + return ( +
+
+
+ +
+
{children}
+
+
+ ); +}; + const SortableItem = ({ id, children, + isActive, + isOver, }: { id: UniqueIdentifier; children: React.ReactNode; + isActive: boolean; + isOver: boolean; }) => { const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id }); - const context = useFormManagerStore(state => state.context); + const context = useFormManagerStore((state) => state.context); return (
@@ -99,6 +166,7 @@ const SortableItem = ({ className="grid-col-12 width-full draggable-list-button cursor-grab padding-2" {...listeners} {...attributes} + style={{ outline: isActive ? 'none' : '' }} >