glass_switch

Function glass_switch 

Source
pub fn glass_switch(args: impl Into<GlassSwitchArgs>, state: GlassSwitchState)
Expand description

§glass_switch

Renders an interactive switch with a customizable glass effect and smooth animation.

§Usage

Use to toggle a boolean state (on/off) with a visually distinct, modern look.

§Parameters

  • args — configures the switch’s appearance and on_toggle callback; see GlassSwitchArgs.
  • state — a clonable GlassSwitchState to manage the component’s checked and animation state.

§Examples

use std::sync::Arc;
use tessera_ui_basic_components::glass_switch::{
    glass_switch, GlassSwitchArgsBuilder, GlassSwitchState,
};

let state = GlassSwitchState::new(false);
assert!(!state.is_checked());

// The on_toggle callback would be passed to the component.
let on_toggle = Arc::new({
    let state = state.clone();
    move |_is_checked: bool| {
        state.toggle();
    }
});

// In a real app, a click would trigger the callback, which toggles the state.
// For this test, we can call toggle directly to simulate this.
state.toggle();
assert!(state.is_checked());