mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-02 16:44:15 -05:00
feat: add button component loading prop
This commit is contained in:
parent
1bab2ca4cb
commit
9d824b2676
4 changed files with 55 additions and 5 deletions
|
@ -13,7 +13,7 @@ license = "MIT"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
leptos = { version = "0.5.0", features = ["csr"] }
|
leptos = { version = "0.5.0", features = ["csr"] }
|
||||||
stylers = "0.3.2"
|
stylers = "0.3.2"
|
||||||
web-sys = { version = "0.3.62", features = ["DomRect"] }
|
web-sys = { version = "0.3.62", features = ["DomRect"] }
|
||||||
leptos_dom = { version = "0.5.0" }
|
leptos_dom = { version = "0.5.0" }
|
||||||
|
@ -22,6 +22,7 @@ icondata = { version = "0.0.7", features = [
|
||||||
"AiCloseOutlined",
|
"AiCloseOutlined",
|
||||||
"AiCheckOutlined",
|
"AiCheckOutlined",
|
||||||
"AiLeftOutlined",
|
"AiLeftOutlined",
|
||||||
|
"AiLoadingOutlined",
|
||||||
] }
|
] }
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
|
@ -92,6 +92,7 @@ pub fn ButtonPage() -> impl IntoView {
|
||||||
""
|
""
|
||||||
</DemoCode>
|
</DemoCode>
|
||||||
</Demo>
|
</Demo>
|
||||||
|
<LoadingButton />
|
||||||
<h3>"style"</h3>
|
<h3>"style"</h3>
|
||||||
<Demo>
|
<Demo>
|
||||||
<Space>
|
<Space>
|
||||||
|
@ -108,3 +109,32 @@ pub fn ButtonPage() -> impl IntoView {
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn LoadingButton() -> impl IntoView {
|
||||||
|
let loading = create_rw_signal(false);
|
||||||
|
view! {
|
||||||
|
<h3>"loading"</h3>
|
||||||
|
<Demo>
|
||||||
|
<Space>
|
||||||
|
<Button loading color=ButtonColor::ERROR icon=icondata::AiIcon::AiCloseOutlined on:click=move |_| loading.set(true)>
|
||||||
|
"ERROR Color Icon"
|
||||||
|
</Button>
|
||||||
|
<Button loading color=ButtonColor::ERROR icon=icondata::AiIcon::AiCloseOutlined round=true>
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
<DemoCode slot html=highlight_str!(r#"
|
||||||
|
let loading = create_rw_signal(false);
|
||||||
|
view! {
|
||||||
|
<Button loading color=ButtonColor::ERROR icon=icondata::AiIcon::AiCloseOutlined>
|
||||||
|
"ERROR Color Icon"
|
||||||
|
</Button>
|
||||||
|
<Button loading color=ButtonColor::ERROR icon=icondata::AiIcon::AiCloseOutlined round=true>
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
"#, "rust")>
|
||||||
|
""
|
||||||
|
</DemoCode>
|
||||||
|
</Demo>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -43,3 +43,9 @@
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes meltLoadingCircle {
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ pub fn Button(
|
||||||
#[prop(optional, into)] color: MaybeSignal<ButtonColor>,
|
#[prop(optional, into)] color: MaybeSignal<ButtonColor>,
|
||||||
#[prop(optional, into)] round: MaybeSignal<bool>,
|
#[prop(optional, into)] round: MaybeSignal<bool>,
|
||||||
#[prop(optional, into)] icon: Option<Icon>,
|
#[prop(optional, into)] icon: Option<Icon>,
|
||||||
|
#[prop(optional, into)] loading: MaybeSignal<bool>,
|
||||||
#[prop(optional)] children: Option<ChildrenFn>,
|
#[prop(optional)] children: Option<ChildrenFn>,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
let theme = use_theme(Theme::light);
|
let theme = use_theme(Theme::light);
|
||||||
|
@ -89,7 +90,7 @@ pub fn Button(
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
view! { class=class_name,
|
view! {class=class_name,
|
||||||
<button
|
<button
|
||||||
class:melt-button=true
|
class:melt-button=true
|
||||||
class=("melt-button--text", move || type_.get() == ButtonType::TEXT)
|
class=("melt-button--text", move || type_.get() == ButtonType::TEXT)
|
||||||
|
@ -97,9 +98,21 @@ pub fn Button(
|
||||||
class=("melt-button--round", move || round.get())
|
class=("melt-button--round", move || round.get())
|
||||||
style=move || format!("{}{}", css_vars.get(), style.get())
|
style=move || format!("{}{}", css_vars.get(), style.get())
|
||||||
>
|
>
|
||||||
<OptionComp value=icon let:icon>
|
{
|
||||||
<Icon icon=icon style=icon_style/>
|
move || {
|
||||||
</OptionComp>
|
if loading.get() {
|
||||||
|
view! {
|
||||||
|
<Icon icon=Icon::from(AiIcon::AiLoadingOutlined) style=format!("animation: meltLoadingCircle 1s infinite linear;{icon_style}")/>
|
||||||
|
}.into()
|
||||||
|
} else if let Some(icon) = icon {
|
||||||
|
view! {
|
||||||
|
<Icon icon=icon style=icon_style/>
|
||||||
|
}.into()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
<OptionComp value=children let:children>
|
<OptionComp value=children let:children>
|
||||||
{ children() }
|
{ children() }
|
||||||
</OptionComp>
|
</OptionComp>
|
||||||
|
|
Loading…
Add table
Reference in a new issue