Skip to content

Commit

Permalink
Split out SortableItem to new file
Browse files Browse the repository at this point in the history
  • Loading branch information
zichongkao committed May 18, 2023
1 parent ee5a503 commit a845dfe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
35 changes: 3 additions & 32 deletions src/components/edit/AreaCRUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import {
SortableContext,
sortableKeyboardCoordinates,
rectSortingStrategy
, useSortable
} from '@dnd-kit/sortable'
import { CSS } from '@dnd-kit/utilities'
import { SortableItem } from './SortableItem'

export type AreaCRUDProps = Pick<AreaType, 'uuid' | 'areaName'> & {
childAreas: AreaType[]
Expand Down Expand Up @@ -77,7 +76,7 @@ export const AreaCRUD = ({ uuid: parentUuid, areaName: parentName, childAreas, e
}

return (
<div>
<>
<div className='flex items-center justify-between'>
<div className='flex items-center gap-3'>
<h3 className='flex items-center gap-4'><AreaEntityIcon />Areas</h3>
Expand Down Expand Up @@ -153,35 +152,7 @@ export const AreaCRUD = ({ uuid: parentUuid, areaName: parentName, childAreas, e
<AddAreaTriggerButtonMd />
</AddAreaTrigger>
</div>)}
</div>
)
}

interface SortableItemProps {
id: string
children: JSX.Element
}

export const SortableItem = (props: SortableItemProps): JSX.Element => {
const {
attributes,
listeners,
setNodeRef,
transform,
transition,
isDragging
} = useSortable({ id: props.id })

const style = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.3 : 1
}

return (
<div ref={setNodeRef} style={style} {...attributes} {...listeners}>
{props.children}
</div>
</>
)
}

Expand Down
30 changes: 30 additions & 0 deletions src/components/edit/SortableItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { CSS } from '@dnd-kit/utilities'
import { useSortable } from '@dnd-kit/sortable'

interface SortableItemProps {
id: string
children: JSX.Element
}

export const SortableItem = (props: SortableItemProps): JSX.Element => {
const {
attributes,
listeners,
setNodeRef,
transform,
transition,
isDragging
} = useSortable({ id: props.id })

const style = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.3 : 1
}

return (
<div ref={setNodeRef} style={style} {...attributes} {...listeners}>
{props.children}
</div>
)
}

0 comments on commit a845dfe

Please sign in to comment.