pub fn checkbox(args: impl Into<CheckboxArgs>)
Expand description
Renders a checkbox component.
The checkbox is a standard UI element that allows users to select or deselect an option.
It visually represents its state, typically as a square box that is either empty or contains a checkmark.
The component handles its own animation and state transitions when an optional CheckboxState
is provided.
§Arguments
The component is configured by passing CheckboxArgs
.
checked
: Abool
indicating whether the checkbox is currently checked. This determines its visual appearance.on_toggle
: A callback functionArc<dyn Fn(bool) + Send + Sync>
that is invoked when the user clicks the checkbox. It receives the newchecked
state as an argument, allowing the application state to be updated.
§Example
use std::sync::Arc;
use tessera_ui_basic_components::checkbox::{checkbox, CheckboxArgs};
// Create a checkbox that is initially unchecked.
// The `on_toggle` callback is triggered when the user clicks it.
checkbox(CheckboxArgs {
checked: false,
on_toggle: Arc::new(|new_state| {
// In a real app, you would update your state here.
println!("Checkbox toggled to: {}", new_state);
}),
..Default::default()
});
// Create a checkbox that is initially checked.
checkbox(CheckboxArgs {
checked: true,
..Default::default()
});