import { defaultAnimateLayoutChanges, useSortable } from '@dnd-kit/sortable' import { CSS } from '@dnd-kit/utilities' import { useClientMotion } from '@/lib/useClientMotion' import { cn } from '@/lib/utils' import type { CSSProperties, ReactNode } from 'react' type Name = { text: string; language: string } const SortableItem = ({ id, name, fixed, children, moveGroup, handleId, renderShell }: { id: string; name: Name; fixed?: boolean; children: ReactNode moveGroup: (direction: number) => void; handleId: string renderShell?: (shell: { ref: (node: HTMLElement | null) => void style: CSSProperties; handle: ReactNode; dragging: boolean }) => ReactNode }, ) => { const motion = useClientMotion () const item = useSortable ({ id, disabled: fixed, transition: { duration: motion.duration ('reorder'), easing: motion.easing }, animateLayoutChanges: options => !motion.reduced && defaultAnimateLayoutChanges ({ ...options, wasDragging: true }) }) const handle = fixed ? : const style = { transform: CSS.Translate.toString (item.transform), transition: item.transition } if (renderShell != null) return renderShell ({ ref: item.setNodeRef, style, handle, dragging: item.isDragging }) return
{handle}
{children}
} export default SortableItem