Expand description
Leptos hooks and components for accessible, pointer-events drag-and-drop.
This crate is the framework-binding layer; see taino_dnd_core for the
framework-free primitives that power it.
§Quick start
use leptos::prelude::*;
use taino_dnd_core::{DraggableId, DroppableId};
use taino_dnd_leptos::{provide_dnd_context, use_draggable, use_droppable};
#[component]
fn App() -> impl IntoView {
provide_dnd_context();
let d = use_draggable(DraggableId(1));
let z = use_droppable(DroppableId(2));
view! {
<div
node_ref=d.node_ref
on:pointerdown=move |e| d.on_pointer_down(&e)
on:pointermove=move |e| d.on_pointer_move(&e)
on:pointerup=move |e| d.on_pointer_up(&e)
on:pointercancel=move |e| d.on_pointer_cancel(&e)
style=move || d.style()
>
"Drag me"
</div>
<div node_ref=z.node_ref class:over=move || z.is_over.get()>
"Drop zone"
</div>
}
}See docs/ROADMAP.md
for the staged plan; Stage 1 ships the API in this quick-start, Stage 2 adds
keyboard sensors, animations, auto-scroll, and ARIA announcements.
Structs§
- Auto
Scroll Config - Tuning knobs for auto-scroll.
- DndContext
- Shared drag-and-drop state installed at the root of a region that uses
taino-dnd-leptos. - Drop
Result - The outcome of a completed drag interaction.
- Flip
Config - Configuration for
use_flip_with. The default is 220 ms with a standard ease-out curve. - Modifier
Context - Read-only inputs available to
Modifier::applybeyond the displacement itself. - UseDraggable
- Handle returned by
use_draggable. Wire its fields onto a<div>in your view. - UseDroppable
- Handle returned by
use_droppable. Wire itsnode_refto your element and readis_overfor hover styling. - Vector
- A 2D displacement vector in CSS pixels.
Enums§
- Announce
Event - A drag-lifecycle event worth announcing to assistive technology.
- Axis
- Cardinal axis used by
Modifier::RestrictToAxis. - Modifier
- Built-in modifiers.
Functions§
- DndAnnouncer
- A visually-hidden ARIA live region that announces drag-and-drop activity.
- Drag
Overlay - A fixed-position layer that follows the active drag.
- default_
announcement - The library’s built-in announcement strings — raw numeric ids.
- provide_
dnd_ context - Install a
DndContextfor descendants. Call once near the root of your drag-and-drop region (typically inside the top-level component for a page or a board). - use_
dnd_ context - Retrieve the nearest ancestor
DndContext. - use_
drag_ container - Register a container element. Returns a
NodeRef<Div>for the user to attach to whichever element should bound the drags. - use_
draggable - Register an element as a draggable identified by
id. - use_
draggable_ with - Like
use_draggable, but with a reactivedisabledflag. - use_
droppable - Register an element as a drop target identified by
id. - use_
droppable_ with - Like
use_droppable, but with a reactivedisabledflag. - use_
flip - Install FLIP animation tracking on the element behind
node_ref. - use_
flip_ with - Like
use_flipbut with a customFlipConfig.