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::{
h_flex,
input::ClearButton,
input::clear_button,
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]);
@ -674,7 +674,7 @@ where
.child(self.display_title(window, cx)),
)
.when(show_clean, |this| {
this.child(ClearButton::new(window, cx).map(|this| {
this.child(clear_button(cx).map(|this| {
if self.disabled {
this.disabled(true)
} else {

View file

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

View file

@ -24,10 +24,11 @@ use gpui::{
use super::blink_cursor::BlinkCursor;
use super::change::Change;
use super::element::TextElement;
use super::{number_input, ClearButton};
use super::number_input;
use crate::history::History;
use crate::indicator::Indicator;
use crate::input::clear_button;
use crate::scroll::{Scrollbar, ScrollbarAxis, ScrollbarState};
use crate::ActiveTheme;
use crate::Size;
@ -1640,7 +1641,7 @@ impl Render for TextInput {
})
.when(
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)
.when(self.is_multi_line(), |this| {

View file

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