feat(button): Support customize loading icon (#281)
This commit is contained in:
parent
76be7a8ed8
commit
2c1119a7bd
2 changed files with 14 additions and 1 deletions
|
|
@ -549,6 +549,7 @@ impl Render for ButtonStory {
|
|||
.child(
|
||||
Button::new("icon-button-primary", cx)
|
||||
.icon(IconName::Search)
|
||||
.loading_icon(IconName::LoaderCircle)
|
||||
.primary()
|
||||
.disabled(disabled)
|
||||
.selected(selected)
|
||||
|
|
@ -595,6 +596,7 @@ impl Render for ButtonStory {
|
|||
.child(
|
||||
Button::new("icon-button-ghost", cx)
|
||||
.icon(IconName::ArrowLeft)
|
||||
.loading_icon(IconName::LoaderCircle)
|
||||
.ghost()
|
||||
.disabled(disabled)
|
||||
.selected(selected)
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ pub struct Button {
|
|||
on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
pub(crate) stop_propagation: bool,
|
||||
loading: bool,
|
||||
loading_icon: Option<Icon>,
|
||||
}
|
||||
|
||||
impl From<Button> for AnyElement {
|
||||
|
|
@ -192,6 +193,7 @@ impl Button {
|
|||
loading: false,
|
||||
compact: false,
|
||||
children: Vec::new(),
|
||||
loading_icon: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -258,6 +260,11 @@ impl Button {
|
|||
self.stop_propagation = val;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn loading_icon(mut self, icon: impl Into<Icon>) -> Self {
|
||||
self.loading_icon = Some(icon.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Disableable for Button {
|
||||
|
|
@ -435,7 +442,11 @@ impl RenderOnce for Button {
|
|||
})
|
||||
})
|
||||
.when(self.loading, |this| {
|
||||
this.child(Indicator::new().with_size(self.size))
|
||||
this.child(
|
||||
Indicator::new()
|
||||
.with_size(self.size)
|
||||
.when_some(self.loading_icon, |this, icon| this.icon(icon)),
|
||||
)
|
||||
})
|
||||
.when_some(self.label, |this, label| {
|
||||
this.child(
|
||||
|
|
|
|||
Loading…
Reference in a new issue