Components / ColorSwatch
ColorSwatch
Round color to pick from a palette.
Example
The component itself, running in WebAssembly, beside its code in a playground. Try it.
Code
use ravenrs::prelude::*;
fn color_swatch() -> impl View {
let current = State::new(0);
view_fn(move || {
let theme = Theme::raven_light();
let options =
[(Semantic::Accent, "Accent"), (Semantic::Success, "Success"), (Semantic::Danger, "Danger")];
let swatches: Vec<AnyView> = options
.iter()
.enumerate()
.map(|(i, (role, name))| {
let pick = current.clone();
Box::new(
ColorSwatch::new(theme.color(*role), *name)
.selected(current.get() == i)
.on_click(move || pick.set(i)),
) as AnyView
})
.collect();
HStack::new(swatches)
})
}