//! Small form controls: full-width slider with value readout above //! (mirrors the desktop `slider_item` layout) and a numeric input row. use web_sys::HtmlInputElement; use yew::prelude::*; #[derive(Properties, PartialEq)] pub struct SliderProps { pub label: AttrValue, /// formatted value shown right of the label pub display: AttrValue, pub value: f64, pub min: f64, pub max: f64, pub step: f64, pub onchange: Callback, } #[function_component(SliderItem)] pub fn slider_item(p: &SliderProps) -> Html { let onchange = { let onchange = p.onchange.clone(); Callback::from(move |e: Event| { let input: HtmlInputElement = e.target_unchecked_into(); if let Ok(v) = input.value().parse::() { onchange.emit(v); } }) }; html! {
{ p.label.as_ref().to_string() } { p.display.as_ref().to_string() }
} } #[derive(Properties, PartialEq)] pub struct NumProps { pub label: AttrValue, pub value: f64, pub step: f64, #[prop_or(2)] pub decimals: usize, pub onchange: Callback, } #[function_component(NumItem)] pub fn num_item(p: &NumProps) -> Html { let onchange = { let onchange = p.onchange.clone(); Callback::from(move |e: Event| { let input: HtmlInputElement = e.target_unchecked_into(); if let Ok(v) = input.value().parse::() { onchange.emit(v); } }) }; let display = format!("{:.*}", p.decimals, p.value); html! { } }