use std::ops::RangeInclusive; use leptos::{Signal, View}; use super::{ControlBuilder, ControlData, ControlRenderData, ValidatedControlData}; use crate::{form::FormToolData, form_builder::FormBuilder, styles::FormStyle}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct StepperData { pub(crate) name: String, pub(crate) label: Option, pub(crate) step: Option, pub(crate) min: Option, pub(crate) max: Option, } impl ControlData for StepperData { type ReturnType = String; fn build_control( fs: &FS, control: ControlRenderData, value_getter: Signal, value_setter: Box, validation_state: Signal>, ) -> View { fs.stepper(control, value_getter, value_setter, validation_state) } } impl ValidatedControlData for StepperData {} impl FormBuilder { pub fn stepper( self, builder: impl Fn( ControlBuilder, ) -> ControlBuilder, ) -> Self { self.new_control(builder) } } impl ControlBuilder { pub fn named(mut self, control_name: impl ToString) -> Self { self.data.name = control_name.to_string(); self } pub fn labeled(mut self, label: impl ToString) -> Self { self.data.label = Some(label.to_string()); self } pub fn step(mut self, step: i32) -> Self { self.data.step = Some(step); self } pub fn min(mut self, min: i32) -> Self { self.data.min = Some(min); self } pub fn max(mut self, max: i32) -> Self { self.data.max = Some(max); self } pub fn range(mut self, range: RangeInclusive) -> Self { self.data.min = Some(*range.start()); self.data.max = Some(*range.end()); self } }