@@ -7,43 +7,43 @@ import {
77 UniqueIdentifier ,
88 useSensor ,
99 useSensors ,
10- } from " @dnd-kit/core" ;
10+ } from ' @dnd-kit/core'
1111import {
1212 arrayMove ,
1313 SortableContext ,
1414 sortableKeyboardCoordinates ,
1515 verticalListSortingStrategy ,
16- } from " @dnd-kit/sortable" ;
17- import { CSS } from " @dnd-kit/utilities" ;
18- import { useSortable } from " @dnd-kit/sortable" ;
19- import { Drag } from " ./icons" ;
16+ } from ' @dnd-kit/sortable'
17+ import { CSS } from ' @dnd-kit/utilities'
18+ import { useSortable } from ' @dnd-kit/sortable'
19+ import { Drag } from ' ./icons'
2020
2121type Props < T > = {
22- children : ( item : T , index : number ) => React . ReactNode ;
23- setItems : ( items : T [ ] ) => void ;
24- items : T [ ] ;
25- disableDragByIndex ?: number ;
26- } ;
22+ children : ( item : T , index : number ) => React . ReactNode
23+ setItems : ( items : T [ ] ) => void
24+ items : T [ ]
25+ disableDragByIndex ?: number
26+ }
2727
2828function ItemWrapper ( {
2929 children,
3030 id,
31- disabledDrag ,
31+ hasDragDisabled ,
3232} : {
33- children : React . ReactNode ;
34- id : UniqueIdentifier ;
35- disabledDrag : boolean ;
33+ children : React . ReactNode
34+ id : UniqueIdentifier
35+ hasDragDisabled : boolean
3636} ) {
3737 const { attributes, listeners, setNodeRef, transform, transition } =
38- useSortable ( { id } ) ;
38+ useSortable ( { id } )
3939 const style = {
4040 transform : CSS . Transform . toString ( transform ) ,
4141 transition,
42- } ;
42+ }
4343
4444 return (
45- < div style = { style } className = "flex items-center w-full" >
46- { disabledDrag ? (
45+ < div style = { style } className = "flex w-full items-center " >
46+ { hasDragDisabled ? (
4747 < div className = "size-8" />
4848 ) : (
4949 < div ref = { setNodeRef } { ...attributes } { ...listeners } className = "size-8" >
@@ -52,7 +52,7 @@ function ItemWrapper({
5252 ) }
5353 < div className = "grow" > { children } </ div >
5454 </ div >
55- ) ;
55+ )
5656}
5757
5858export function SortableArea < T extends { id : UniqueIdentifier } > ( {
@@ -65,21 +65,22 @@ export function SortableArea<T extends { id: UniqueIdentifier }>({
6565 useSensor ( PointerSensor ) ,
6666 useSensor ( KeyboardSensor , {
6767 coordinateGetter : sortableKeyboardCoordinates ,
68- } ) ,
69- ) ;
68+ } )
69+ )
7070
7171 function handleDragEnd ( event : DragEndEvent ) {
72- const { active, over } = event ;
72+ const { active, over } = event
7373
7474 if ( over == null ) {
75- return ;
75+ // The item was dropped in it's original place
76+ return
7677 }
7778
7879 if ( active . id !== over . id ) {
79- const oldIndex = items . findIndex ( ( { id } ) => id === active . id ) ;
80- const newIndex = items . findIndex ( ( { id } ) => id === over . id ) ;
80+ const oldIndex = items . findIndex ( ( { id } ) => id === active . id )
81+ const newIndex = items . findIndex ( ( { id } ) => id === over . id )
8182
82- setItems ( arrayMove ( items , oldIndex , newIndex ) ) ;
83+ setItems ( arrayMove ( items , oldIndex , newIndex ) )
8384 }
8485 }
8586
@@ -94,12 +95,12 @@ export function SortableArea<T extends { id: UniqueIdentifier }>({
9495 < ItemWrapper
9596 key = { index }
9697 id = { item . id }
97- disabledDrag = { disableDragByIndex === index }
98+ hasDragDisabled = { disableDragByIndex === index }
9899 >
99100 { children ( item , index ) }
100101 </ ItemWrapper >
101102 ) ) }
102103 </ SortableContext >
103104 </ DndContext >
104- ) ;
105+ )
105106}
0 commit comments