From a8b61c5ffad3eac7f0855654e8a64214d5bd96e9 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Mon, 8 Dec 2025 10:16:19 -0300 Subject: [PATCH] ui: Remove support for unnecessary Switch colors (#44388) This PR removes the default, error, warning, and success color variants from the `SwitchColor` enum. In the most YAGNI spirit, I think we'll probably never want to use these colors for the switch, so there's no reason to support them. And if we ever want to do it, we can re-add them. I also took the opportunity to change the default color to be "accent", which is _already_ what we use for all instances of this component, so there's no need to have to define it every time. This effectively makes the enum support only "accent" and "custom", which I think is okay for now if we ever need an escape hatch before committing to supporting new values. Release Notes: - N/A --- crates/agent_ui/src/agent_configuration.rs | 3 +- crates/debugger_ui/src/new_process_modal.rs | 1 - crates/extensions_ui/src/extensions_ui.rs | 3 +- crates/settings_ui/src/settings_ui.rs | 5 +- crates/ui/src/components/toggle.rs | 60 ++------------------- 5 files changed, 7 insertions(+), 65 deletions(-) diff --git a/crates/agent_ui/src/agent_configuration.rs b/crates/agent_ui/src/agent_configuration.rs index f831329e2cde40dbb9d4b9e882d6bc942f383422..3e4654af6e7b47055611cf81886cc0a93436a264 100644 --- a/crates/agent_ui/src/agent_configuration.rs +++ b/crates/agent_ui/src/agent_configuration.rs @@ -36,7 +36,7 @@ use settings::{Settings, SettingsStore, update_settings_file}; use ui::{ Button, ButtonStyle, Chip, CommonAnimationExt, ContextMenu, ContextMenuEntry, Disclosure, Divider, DividerColor, ElevationIndex, IconName, IconPosition, IconSize, Indicator, LabelSize, - PopoverMenu, Switch, SwitchColor, Tooltip, WithScrollbar, prelude::*, + PopoverMenu, Switch, Tooltip, WithScrollbar, prelude::*, }; use util::ResultExt as _; use workspace::{Workspace, create_and_open_local_file}; @@ -879,7 +879,6 @@ impl AgentConfiguration { .child(context_server_configuration_menu) .child( Switch::new("context-server-switch", is_running.into()) - .color(SwitchColor::Accent) .on_click({ let context_server_manager = self.context_server_store.clone(); let fs = self.fs.clone(); diff --git a/crates/debugger_ui/src/new_process_modal.rs b/crates/debugger_ui/src/new_process_modal.rs index ca13e3eed5fd770e8b80f0cd5b8610ff1e9e2f51..24f6cc8f341519425b33433c3324f8afe7401ab7 100644 --- a/crates/debugger_ui/src/new_process_modal.rs +++ b/crates/debugger_ui/src/new_process_modal.rs @@ -881,7 +881,6 @@ impl ConfigureMode { .label("Stop on Entry") .label_position(SwitchLabelPosition::Start) .label_size(LabelSize::Default) - .color(ui::SwitchColor::Accent) .on_click({ let this = cx.weak_entity(); move |state, _, cx| { diff --git a/crates/extensions_ui/src/extensions_ui.rs b/crates/extensions_ui/src/extensions_ui.rs index 89247ae5a49a99b2a4f2261892b2656e14bb8674..3dd4803ce17adb053f86f29e3724d58d479136c6 100644 --- a/crates/extensions_ui/src/extensions_ui.rs +++ b/crates/extensions_ui/src/extensions_ui.rs @@ -1472,8 +1472,7 @@ impl ExtensionsPage { }, ); }, - )) - .color(ui::SwitchColor::Accent), + )), ), ), ) diff --git a/crates/settings_ui/src/settings_ui.rs b/crates/settings_ui/src/settings_ui.rs index 43925c1893abcb200f525a8513bc5c81e93d6a75..4464d3bdd951d4b7bf2511cfd718b0f297b8fc78 100644 --- a/crates/settings_ui/src/settings_ui.rs +++ b/crates/settings_ui/src/settings_ui.rs @@ -29,8 +29,8 @@ use std::{ use title_bar::platform_title_bar::PlatformTitleBar; use ui::{ Banner, ContextMenu, Divider, DividerColor, DropdownMenu, DropdownStyle, IconButtonShape, - KeyBinding, KeybindingHint, PopoverMenu, Switch, SwitchColor, Tooltip, TreeViewItem, - WithScrollbar, prelude::*, + KeyBinding, KeybindingHint, PopoverMenu, Switch, Tooltip, TreeViewItem, WithScrollbar, + prelude::*, }; use ui_input::{NumberField, NumberFieldType}; use util::{ResultExt as _, paths::PathStyle, rel_path::RelPath}; @@ -3501,7 +3501,6 @@ fn render_toggle_button + From + Copy>( Switch::new("toggle_button", toggle_state) .tab_index(0_isize) - .color(SwitchColor::Accent) .on_click({ move |state, _window, cx| { telemetry::event!("Settings Change", setting = field.json_path, type = file.setting_type()); diff --git a/crates/ui/src/components/toggle.rs b/crates/ui/src/components/toggle.rs index 1e637f24194b86f0c06aef806975df635f45a6cd..e0360d6a2a86c212a47ba3dd8df7d40f0c3e152a 100644 --- a/crates/ui/src/components/toggle.rs +++ b/crates/ui/src/components/toggle.rs @@ -281,11 +281,7 @@ impl RenderOnce for Checkbox { #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)] pub enum SwitchColor { #[default] - Default, Accent, - Error, - Warning, - Success, Custom(Hsla), } @@ -299,27 +295,10 @@ impl SwitchColor { } match self { - SwitchColor::Default => { - let colors = cx.theme().colors(); - let base_color = colors.text; - let bg_color = colors.element_background.blend(base_color.opacity(0.08)); - (bg_color, colors.border_variant) - } SwitchColor::Accent => { let status = cx.theme().status(); - (status.info.opacity(0.4), status.info.opacity(0.2)) - } - SwitchColor::Error => { - let status = cx.theme().status(); - (status.error.opacity(0.4), status.error.opacity(0.2)) - } - SwitchColor::Warning => { - let status = cx.theme().status(); - (status.warning.opacity(0.4), status.warning.opacity(0.2)) - } - SwitchColor::Success => { - let status = cx.theme().status(); - (status.success.opacity(0.4), status.success.opacity(0.2)) + let colors = cx.theme().colors(); + (status.info.opacity(0.4), colors.text_accent.opacity(0.2)) } SwitchColor::Custom(color) => (*color, color.opacity(0.6)), } @@ -329,11 +308,7 @@ impl SwitchColor { impl From for Color { fn from(color: SwitchColor) -> Self { match color { - SwitchColor::Default => Color::Default, SwitchColor::Accent => Color::Accent, - SwitchColor::Error => Color::Error, - SwitchColor::Warning => Color::Warning, - SwitchColor::Success => Color::Success, SwitchColor::Custom(_) => Color::Default, } } @@ -980,37 +955,8 @@ impl Component for Switch { "Colors", vec![ single_example( - "Default", - Switch::new("switch_default_style", ToggleState::Selected) - .color(SwitchColor::Default) - .on_click(|_, _, _cx| {}) - .into_any_element(), - ), - single_example( - "Accent", + "Accent (Default)", Switch::new("switch_accent_style", ToggleState::Selected) - .color(SwitchColor::Accent) - .on_click(|_, _, _cx| {}) - .into_any_element(), - ), - single_example( - "Error", - Switch::new("switch_error_style", ToggleState::Selected) - .color(SwitchColor::Error) - .on_click(|_, _, _cx| {}) - .into_any_element(), - ), - single_example( - "Warning", - Switch::new("switch_warning_style", ToggleState::Selected) - .color(SwitchColor::Warning) - .on_click(|_, _, _cx| {}) - .into_any_element(), - ), - single_example( - "Success", - Switch::new("switch_success_style", ToggleState::Selected) - .color(SwitchColor::Success) .on_click(|_, _, _cx| {}) .into_any_element(), ),