use fission::prelude::*;
#[fission_reducer(SetQuantity)]
fn set_quantity(state: &mut OrderState, ctx: &mut ReducerContext<OrderState>) {
let Some(change) = ctx.input.text_change() else {
return;
};
if let Ok(quantity) = change.new_text.parse::<f32>() {
state.quantity = quantity.clamp(1.0, 10.0);
}
}
let widget: Widget = NumberInput {
value: view.state().quantity as f32,
display_text: Some(view.state().quantity.to_string()),
min: Some(1.0),
max: Some(10.0),
step: 1.0,
on_increment: Some(increment_quantity_action),
on_decrement: Some(decrement_quantity_action),
on_input: Some(ctx.bind(SetQuantity, reduce_with!(set_quantity))),
..Default::default()
}
.into();
Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
id | Option<WidgetId> | Stable identity for the inner text field. | Defaults to None. |
value | f32 | Current numeric value. | Defaults to 0.0. |
display_text | Option<String> | Exact text shown in the field. | If None, the widget formats value with format!("{}", value). |
min | Option<f32> | Intended minimum value. | Present for product meaning, but not enforced by the current widget implementation. |
max | Option<f32> | Intended maximum value. | Present for product meaning, but not enforced by the current widget implementation. |
step | f32 | Intended adjustment step. | Defaults to 1.0, but the current widget does not apply it automatically. Your reducer does. |
field_width | Option<f32> | Width of the central text field. | If None, width is estimated from display_text. |
button_size | Option<f32> | Size of the plus and minus buttons. | Defaults to 32.0 with a lower bound of 28.0. |
gap | Option<f32> | Spacing between the buttons and field. | Defaults to 4.0. |
on_increment | Option<ActionEnvelope> | Action fired by the plus button. | Defaults to None. |
on_decrement | Option<ActionEnvelope> | Action fired by the minus button. | Defaults to None. |
on_input | Option<ActionEnvelope> | Action fired for typed edits in the central field. | Preserves the bound action; parse ctx.input.text_change().new_text in the reducer. |