Skip to main content

subspace_dashboard/
toggle.rs

1//! Shared switches and the layout for independent boolean options.
2
3pub mod track;
4
5use gpui_kit::component::{ActiveTheme as _, h_flex, switch::Switch};
6use gpui_kit::{App, Div, ElementId, SharedString, Styled, div, prelude::*};
7
8/// A native switch whose on track meets the switch contrast rule in
9/// [`track`]. Build every switch here, not with `Switch::new`: the theme
10/// fixes the off track and knob, but only the switch can set its on colour.
11pub fn switch(id: impl Into<ElementId>, cx: &App) -> Switch {
12    Switch::new(id).color(track::switch_colors(cx.theme()).on)
13}
14
15/// Places a wrapping label beside a trailing native switch.
16///
17/// The caller owns the value and commit boundary. The switch retains its native
18/// keyboard, focus, disabled state, and change callback.
19pub fn toggle_row(label: impl Into<SharedString>, switch: Switch) -> Div {
20    let label = label.into();
21    h_flex()
22        .w_full()
23        .items_start()
24        .gap_3()
25        .child(div().flex_1().min_w_0().child(label.clone()))
26        .child(
27            div()
28                .flex_shrink_0()
29                .child(switch.accessibility_label(label)),
30        )
31}
32
33#[cfg(test)]
34mod tests;