checkbox

Function checkbox 

Source
pub fn checkbox(args: impl Into<CheckboxArgs>, state: Arc<CheckboxState>)
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.

§Arguments

The component is configured by passing CheckboxArgs and a CheckboxState.

  • on_toggle: A callback function Arc<dyn Fn(bool) + Send + Sync> that is invoked when the user clicks the checkbox. It receives the new checked state as an argument, allowing the application state to be updated.

§Example

use std::sync::Arc;
use parking_lot::RwLock;
use tessera_ui_basic_components::checkbox::{checkbox, CheckboxArgs, CheckboxState, CheckmarkState};

// Create a checkbox that is initially unchecked.
let unchecked_state = Arc::new(CheckboxState::default());
checkbox(
    CheckboxArgs {
        on_toggle: Arc::new(|new_state| {
            // In a real app, you would update your state here.
            println!("Checkbox toggled to: {}", new_state);
        }),
        ..Default::default()
    },
    unchecked_state,
);

// Create a checkbox that is initially checked.
let checked_state = Arc::new(CheckboxState::new(true));
checkbox(CheckboxArgs::default(), checked_state);