switch

Function switch 

Source
pub fn switch(args: impl Into<SwitchArgs>, state: SwitchState)
Expand description

§switch

Renders an animated on/off toggle switch.

§Usage

Use for settings or any other boolean state that the user can control.

§Parameters

  • args — configures the switch’s appearance and on_toggle callback; see SwitchArgs.
  • state — a clonable SwitchState to manage the checked/unchecked state.

§Examples

use std::sync::Arc;
use tessera_ui_basic_components::switch::{switch, SwitchArgsBuilder, SwitchState};

let switch_state = SwitchState::new(false);

switch(
    SwitchArgsBuilder::default()
        .on_toggle(Arc::new(|checked| {
            println!("Switch is now: {}", if checked { "ON" } else { "OFF" });
        }))
        .build()
        .unwrap(),
    switch_state,
);