use fission::prelude::*;
fission_component! {
pub NewsletterChoice<()> {
state { subscribed: bool = false }
}
view(choice, _state, cx) =>
Checkbox(
checked: choice.subscribed,
label: Some(cx.tr("preferences.product_updates")),
on_toggle: reduce {
choice.subscribed = !choice.subscribed;
},
)
}
Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
id | Option<WidgetId> | Stable widget identity. | Defaults to None. |
name | Option<String> | Successful-control name for Static site and SSR forms. | Several checkboxes may share a repeated field name. |
form_id | Option<String> | Associates the checkbox with a server form. | Must match the form schema id. |
form_value | Option<String> | Machine value submitted when checked. | Leave unset for a Boolean field (on); set a distinct value for each repeated option. |
checked | bool | Whether the checkbox is currently selected. | Defaults to false. |
on_toggle | Option<ActionEnvelope> | Action dispatched when the user toggles the checkbox. | Defaults to None. |
label | Option<String> | Visible text shown next to the indicator. | Defaults to None, but most real checkboxes should have a label. |
// Inside a Compose view; region and selected_regions come from the parent model.
Checkbox(
name: Some("regions".into()),
form_id: Some("connect".into()),
form_value: Some(region.code.clone()),
label: Some(region.display_name.clone()),
checked: selected_regions.contains(®ion.code),
)