From f3d97bf8e20e4b00080cb383e4e194720c95cc42 Mon Sep 17 00:00:00 2001 From: Ratazzi Date: Thu, 15 May 2025 16:13:30 +0800 Subject: [PATCH] chore: Unify icon parameter types in ListItem and Dropdown. (#857) ## Changes This PR unifies icon parameter types in UI components: - Changed `ListItem.check_icon` parameter type from `IconName` to `impl Into` - Changed `Dropdown.icon` parameter type from `impl Into` to `impl Into` - Updated related rendering logic ## Impact - **API Consistency**: All components now accept the same icon parameter type - **Backward Compatible**: Existing code using `IconName` continues to work - **Enhanced Flexibility**: Components can now accept custom `Icon` instances directly --- crates/ui/src/dropdown.rs | 10 +++++----- crates/ui/src/list/list_item.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/ui/src/dropdown.rs b/crates/ui/src/dropdown.rs index c9b7b661..9b183aec 100644 --- a/crates/ui/src/dropdown.rs +++ b/crates/ui/src/dropdown.rs @@ -247,7 +247,7 @@ pub struct Dropdown { focus_handle: FocusHandle, list: Entity>>, size: Size, - icon: Option, + icon: Option, open: bool, cleanable: bool, placeholder: Option, @@ -408,7 +408,7 @@ where } /// Set the right icon for the dropdown input, instead of the default arrow icon. - pub fn icon(mut self, icon: impl Into) -> Self { + pub fn icon(mut self, icon: impl Into) -> Self { self.icon = Some(icon.into()); self } @@ -719,14 +719,14 @@ where Some(icon) => icon, None => { if self.open { - IconName::ChevronUp + Icon::new(IconName::ChevronUp) } else { - IconName::ChevronDown + Icon::new(IconName::ChevronDown) } } }; - this.child(Icon::new(icon).xsmall().text_color( + this.child(icon.xsmall().text_color( match self.disabled { true => cx.theme().muted_foreground.opacity(0.5), false => cx.theme().muted_foreground, diff --git a/crates/ui/src/list/list_item.rs b/crates/ui/src/list/list_item.rs index 1531fce1..4afa18b6 100644 --- a/crates/ui/src/list/list_item.rs +++ b/crates/ui/src/list/list_item.rs @@ -1,4 +1,4 @@ -use crate::{h_flex, ActiveTheme, Disableable, Icon, IconName, Selectable, Sizable as _}; +use crate::{h_flex, ActiveTheme, Disableable, Icon, Selectable, Sizable as _}; use gpui::{ div, prelude::FluentBuilder as _, AnyElement, App, ClickEvent, Div, ElementId, InteractiveElement, IntoElement, MouseButton, MouseMoveEvent, ParentElement, RenderOnce, @@ -38,8 +38,8 @@ impl ListItem { } /// Set to show check icon, default is None. - pub fn check_icon(mut self, icon: IconName) -> Self { - self.check_icon = Some(Icon::new(icon)); + pub fn check_icon(mut self, icon: impl Into) -> Self { + self.check_icon = Some(icon.into()); self }