Skip to content

Commit 7715d08

Browse files
committed
Overlay kind of works
1 parent 3710b3f commit 7715d08

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/ui/components/DataTable/Row.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ const Row = ({
6161
showBulkSelectCheckboxes,
6262

6363
sortable,
64-
overlay,
6564
}: {
6665
clickable?: boolean;
6766
highlightCols: number[];
@@ -73,7 +72,6 @@ const Row = ({
7372
showBulkSelectCheckboxes: boolean;
7473

7574
sortable?: RenderRowProps;
76-
overlay?: boolean;
7775
}) => {
7876
const { clicked, toggleClicked } = useClickable();
7977

@@ -84,14 +82,16 @@ const Row = ({
8482
className={clsx(row.classNames, {
8583
"table-warning": clickable && clicked,
8684
"opacity-0":
87-
sortable && !overlay && sortable.draggedIndex === sortable.index,
85+
sortable &&
86+
!sortable.overlay &&
87+
sortable.draggedIndex === sortable.index,
8888
})}
8989
onClick={clickable ? toggleClicked : undefined}
9090
ref={node => {
9191
if (sortable?.setNodeRef) {
9292
sortable.setNodeRef(node);
9393
}
94-
if (overlay) {
94+
if (sortable?.overlay) {
9595
overlayRowRef.current = node;
9696
}
9797
}}

src/ui/components/DataTable/sortable.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type SortableTableContextInfo = {
5050
highlightHandle: HighlightHandle<ShouldBeValue>;
5151
renderRow: (props: RenderRowProps) => ReactNode;
5252
row: string; //Row<ShouldBeValue>;
53+
rows: ShouldBeValue[];
5354
rowClassName: string; // RowClassName<ShouldBeValue> | undefined;
5455
rowLabels: string[] | undefined;
5556
tableRef: string; //RefObject<HTMLTableElement | null>;
@@ -311,8 +312,9 @@ export const SortableContextWrappers = ({
311312
rowClassName: "???",
312313
rowLabels: undefined,
313314
tableRef: "???",
315+
rows,
314316
}),
315-
[clickedIndex, draggedIndex, highlightHandle, renderRow],
317+
[clickedIndex, draggedIndex, highlightHandle, renderRow, rows],
316318
);
317319

318320
// string rather than string | number because 0 as an ID doesn't work, and that's more likely than an empty string!
@@ -392,12 +394,18 @@ export const SortableContextWrappers = ({
392394
};
393395

394396
export const MyDragOverlay = () => {
395-
const { draggedIndex, row } = useContext(SortableTableContext);
397+
const { draggedIndex, renderRow, rows } = useContext(SortableTableContext);
396398

397-
console.log("MyDragOverlay", draggedIndex, row);
398399
return (
399400
<DragOverlay wrapperElement="tbody">
400-
{draggedIndex !== undefined ? <div>HELLO!</div> : null}
401+
{draggedIndex !== undefined
402+
? renderRow({
403+
draggedIndex,
404+
index: draggedIndex,
405+
overlay: true,
406+
value: rows[draggedIndex],
407+
})
408+
: null}
401409
</DragOverlay>
402410
);
403411
};

0 commit comments

Comments
 (0)