Components / SortableList

SortableList

Rows put in order by a drag or with Alt and the arrows.

Example

The component itself, running in WebAssembly, beside its code in a playground. Try it.

Code

use ravenrs::prelude::*;

fn sortable_list() -> impl View {
    let layers = State::new(vec!["Exposure", "Curves", "Grain", "Vignette"]);
    view_fn(move || {
        let shown = layers.get();
        let (names, moved) = (shown.clone(), layers.clone());
        SortableList::new(shown.len(), move |index| Text::new(shown[index]))
            .row_name(move |index| names[index].to_owned())
            .on_reorder(move |from, to| {
                moved.update(|list| {
                    let layer = list.remove(from);
                    list.insert(to, layer);
                });
            })
    })
}

Open in the playground, with every example →

Full API of SortableList →