color is_default switch when active

This commit is contained in:
jfmonty2 committed 2026-11-20 05:25:38 -05:00
1 parent c1186ad55e
commit dbcf72fa38
3 files changed
+59 -3

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
use gpui_kit::base::{Switch, SwitchThumb, SwitchTrack};
use gpui_kit::{
App, ElementId, Hsla, InteractiveElement, ParentElement, SharedString,
StatefulInteractiveElement, Styled, rems,
};
use gpui_omarchy::ActiveTheme;
/// gpui-omarchy's switch hard-codes its track and knob colors, so this rebuilds it
/// from the base parts in order to tint them with `color` when checked.
pub fn colored_switch(
id: impl Into<ElementId>,
label: impl Into<SharedString>,
checked: bool,
color: Hsla,
cx: &App,
) -> Switch {
let t = cx.omarchy();
let id = id.into();
let label = label.into();
Switch::new(id.clone())
.checked(checked)
.accessibility_label(label.clone())
.flex()
.items_center()
.gap(rems(0.5))
.p(rems(0.3125))
.border_1()
.border_color(t.foreground.opacity(0.))
.text_size(rems(0.75))
.hover(|s| s.bg(t.hover_fill()).border_color(t.focus_border()))
.focus_visible(|s| s.bg(t.hover_fill()).border_color(t.focus_border()))
.active(|s| s.bg(t.pressed_fill()))
.child(
SwitchTrack::new(id)
.checked(checked)
.w(rems(2.625))
.h(rems(1.375))
.flex_shrink_0()
.p(rems(0.125))
.border_1()
.border_color(if checked { color } else { t.control_border() })
.rounded_none()
.bg(if checked { color.opacity(0.18) } else { t.normal_fill() })
.child(
SwitchThumb::new(checked)
.size(rems(1.))
.rounded_none()
.bg(if checked { color } else { t.secondary })
.ml(rems(if checked { 1.25 } else { 0. })),
),
)
.child(label)
}
+2
View File
@@ -1,5 +1,7 @@
mod colored_switch;
mod error_alert; mod error_alert;
mod passphrase_input; mod passphrase_input;
pub use colored_switch::colored_switch;
pub use error_alert::error_alert; pub use error_alert::error_alert;
pub use passphrase_input::{PassphraseInput, PassphraseInputEvent}; pub use passphrase_input::{PassphraseInput, PassphraseInputEvent};
+3 -3
View File
@@ -5,10 +5,10 @@ use gpui_kit::{
}; };
use gpui_omarchy::{ use gpui_omarchy::{
ActiveTheme, ButtonVariant, ChoiceItem, IconName, Status, badge, button, empty_state, ActiveTheme, ButtonVariant, ChoiceItem, IconName, Status, badge, button, empty_state,
focus_scope, icon_button, input, switch, tab_list, focus_scope, icon_button, input, tab_list,
}; };
use crate::components::{PassphraseInput, PassphraseInputEvent, error_alert}; use crate::components::{PassphraseInput, PassphraseInputEvent, colored_switch, error_alert};
use crate::credentials::AwsCredential; use crate::credentials::AwsCredential;
use crate::session::AppSession; use crate::session::AppSession;
use super::Screen; use super::Screen;
@@ -188,7 +188,7 @@ impl CredentialsScreen {
.items_center() .items_center()
.gap(rems(0.5)) .gap(rems(0.5))
.child( .child(
switch("aws-default", "Default AWS access key", form.is_default, cx) colored_switch("aws-default", "Default AWS access key", form.is_default, t.success, cx)
.on_change(move |value, _, _, cx| this.update(cx, |this, cx| { .on_change(move |value, _, _, cx| this.update(cx, |this, cx| {
if let Some(form) = &mut this.aws_form { if let Some(form) = &mut this.aws_form {
form.is_default = value; form.is_default = value;