mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 21:59:16 +03:00
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import type { CSSProperties, ReactNode } from 'react'
|
|
import { GripVertical } from 'lucide-react'
|
|
import { useSortable } from '@dnd-kit/sortable'
|
|
|
|
type SortableSectionProps = {
|
|
id: string
|
|
children: ReactNode
|
|
}
|
|
|
|
export function SortableSection({ id, children }: SortableSectionProps) {
|
|
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
id,
|
|
})
|
|
|
|
const style: CSSProperties = {
|
|
transform: transform
|
|
? `translate3d(${Math.round(transform.x)}px, ${Math.round(transform.y)}px, 0)`
|
|
: undefined,
|
|
transition,
|
|
}
|
|
|
|
return (
|
|
<div ref={setNodeRef} style={style} className="relative will-change-transform">
|
|
<button
|
|
aria-label="Drag to reorder section"
|
|
className="absolute -left-6 top-2 text-foreground-muted hover:text-foreground focus:outline-none cursor-grab active:cursor-grabbing"
|
|
{...attributes}
|
|
{...listeners}
|
|
>
|
|
<GripVertical size={14} />
|
|
</button>
|
|
<div className={isDragging ? 'opacity-70' : undefined}>{children}</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default SortableSection
|