chore: Refactor ClearButton to as method. (#598)

This commit is contained in:
Jason Lee 2025-02-04 17:34:26 +08:00 committed by GitHub
parent dffb419145
commit 155f2ee3b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 19 deletions

View file

@ -9,9 +9,9 @@ use rust_i18n::t;
use crate::{ use crate::{
h_flex, h_flex,
input::ClearButton, input::clear_button,
list::{self, List, ListDelegate, ListItem}, list::{self, List, ListDelegate, ListItem},
v_flex, ActiveTheme, Disableable, Icon, IconName, Sizable, Size, StyleSized, StyledExt, v_flex, ActiveTheme, Disableable as _, Icon, IconName, Sizable, Size, StyleSized, StyledExt,
}; };
actions!(dropdown, [Up, Down, Enter, Escape]); actions!(dropdown, [Up, Down, Enter, Escape]);
@ -674,7 +674,7 @@ where
.child(self.display_title(window, cx)), .child(self.display_title(window, cx)),
) )
.when(show_clean, |this| { .when(show_clean, |this| {
this.child(ClearButton::new(window, cx).map(|this| { this.child(clear_button(cx).map(|this| {
if self.disabled { if self.disabled {
this.disabled(true) this.disabled(true)
} else { } else {

View file

@ -1,17 +1,14 @@
use gpui::{App, Styled, Window}; use gpui::{App, Styled};
use crate::{ use crate::{
button::{Button, ButtonVariants as _}, button::{Button, ButtonVariants as _},
ActiveTheme as _, Icon, IconName, Sizable as _, ActiveTheme as _, Icon, IconName, Sizable as _,
}; };
pub(crate) struct ClearButton {} pub(crate) fn clear_button(cx: &App) -> Button {
Button::new("clean")
impl ClearButton { .icon(Icon::new(IconName::CircleX))
pub fn new(_: &mut Window, cx: &mut App) -> Button { .ghost()
Button::new("clean") .xsmall()
.icon(Icon::new(IconName::CircleX).text_color(cx.theme().muted_foreground)) .text_color(cx.theme().muted_foreground)
.ghost()
.xsmall()
}
} }

View file

@ -24,10 +24,11 @@ use gpui::{
use super::blink_cursor::BlinkCursor; use super::blink_cursor::BlinkCursor;
use super::change::Change; use super::change::Change;
use super::element::TextElement; use super::element::TextElement;
use super::{number_input, ClearButton}; use super::number_input;
use crate::history::History; use crate::history::History;
use crate::indicator::Indicator; use crate::indicator::Indicator;
use crate::input::clear_button;
use crate::scroll::{Scrollbar, ScrollbarAxis, ScrollbarState}; use crate::scroll::{Scrollbar, ScrollbarAxis, ScrollbarState};
use crate::ActiveTheme; use crate::ActiveTheme;
use crate::Size; use crate::Size;
@ -1640,7 +1641,7 @@ impl Render for TextInput {
}) })
.when( .when(
self.cleanable && !self.loading && !self.text.is_empty() && self.is_single_line(), self.cleanable && !self.loading && !self.text.is_empty() && self.is_single_line(),
|this| this.child(ClearButton::new(window, cx).on_click(cx.listener(Self::clean))), |this| this.child(clear_button(cx).on_click(cx.listener(Self::clean))),
) )
.children(suffix) .children(suffix)
.when(self.is_multi_line(), |this| { .when(self.is_multi_line(), |this| {

View file

@ -11,7 +11,7 @@ use crate::{
button::{Button, ButtonVariants as _}, button::{Button, ButtonVariants as _},
dropdown::Escape, dropdown::Escape,
h_flex, h_flex,
input::ClearButton, input::clear_button,
v_flex, ActiveTheme, Icon, IconName, Sizable, Size, StyleSized as _, StyledExt as _, v_flex, ActiveTheme, Icon, IconName, Sizable, Size, StyleSized as _, StyledExt as _,
}; };
@ -326,9 +326,7 @@ impl Render for DatePicker {
.gap_1() .gap_1()
.child(div().w_full().overflow_hidden().child(display_title)) .child(div().w_full().overflow_hidden().child(display_title))
.when(show_clean, |this| { .when(show_clean, |this| {
this.child( this.child(clear_button(cx).on_click(cx.listener(Self::clean)))
ClearButton::new(window, cx).on_click(cx.listener(Self::clean)),
)
}) })
.when(!show_clean, |this| { .when(!show_clean, |this| {
this.child( this.child(