Lite, fast, Beautiful and configurable drag & drop list.
Demo: Legato Dnd React Demo
Use with frameworks:
- for Vue 2.x: vue2-legato-dnd
- for Vue 3.x: vue-legato-dnd
- for React: react-legato-dnd
# npm
npm install legato-dnd
# yarn
yarn add legato-dnd
const el = document.getElementById('container')
for (let i = 0; i < 10; ++i) {
let child = document.createElement('div')
child = Legato.draggable(child)
el.append(child)
}
const container = new Legato.DragDrop({ container: el })
props from Container, usage:
type ScrollDeltaFunctionType = ({state}: { state: ParentState }) => number
type PlaceholderFunctionType = () => HTMLElement
type MoveGroup = [number, number]
interface DragDropProps {
container: HTMLElement,
vertical?: boolean, // default false
groups?: MoveGroup[],
transitionDuration?: number, // default 200
placeholder?: HTMLElement | PlaceholderFunctionType,
scrollSpeed?: ScrollDeltaFunctionType,
scrollThreshold?: number, // default 0
lockCrossAxis?: boolean, // default false
lockArea?: boolean, // default false
startDelay?: number, // default 0
touchStartDelay?: number, // default 200
startOffsetTolerate?: number, // default 5
name?: string,
inactiveClass?: string,
startActiveClass?: string,
dragActiveClass?: string,
dropActiveClass?: string,
}
basic usage:
const dragDrop = new DragDrop(options)
dragDrop.on('dragStart', () => {
console.log('dragStart')
})
dragDrop.on('orderChange', ({from, to, order}) => {
// do something
})
// position event
export interface EnterViewportEdgeEvent {
state: ParentState
}
export interface LeaveViewportEdgeEvent {
state: ParentState
}
export interface EnterContainerEdgeEvent {
intersectState: IntersectState
}
export interface LeaveContainerEdgeEvent {
intersectState: IntersectState
}
// scroll
export interface ProgrammingScrollStartEvent {
startTime: number,
state: ParentState
}
export interface ProgrammingScrollEndEvent {
startTime: number,
endTime: number,
endState: ParentState,
startState: ParentState
}
export interface ProgrammingScrollErrorEvent {
startTime: number,
state: ParentState,
scrollDelta: number
}
export interface ProgrammingScrollEvent {
startTime: number,
state: ParentState,
scrollDelta: number,
offset: number
}
// lifestyle
export interface BeforeDragStartEvent {
startIndex: number,
startGroup: MoveGroup,
cancel: () => void
}
export interface DragStartEvent {
startIndex: number,
startGroup: MoveGroup,
}
export interface DragOverEvent {
startIndex: number,
startGroup: MoveGroup,
currentIndex: number,
currentGroup: MoveGroup
}
export interface DragCrossEvent {
order: number[],
startIndex: number,
startGroup: MoveGroup,
currentIndex: number,
currentGroup: MoveGroup
lastCurrentIndex: number,
}
export interface BeforeDropEvent {
startIndex: number,
startGroup: MoveGroup,
endIndex: number,
endGroup: MoveGroup
}
export interface DropEvent {
startIndex: number,
startGroup: MoveGroup,
endIndex: number,
endGroup: MoveGroup
}
export interface DragEndEvent {
startIndex: number,
startGroup: MoveGroup,
endIndex: number,
endGroup: MoveGroup,
order: number[]
}
export interface OrderChangeEvent {
order: number[],
startIndex: number,
startGroup: MoveGroup,
endIndex: number,
endGroup: MoveGroup
}