mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-02 16:44:15 -05:00
feat: add button component on_click prop
This commit is contained in:
parent
9d824b2676
commit
5db0b60d6c
3 changed files with 57 additions and 12 deletions
|
@ -113,24 +113,46 @@ pub fn ButtonPage() -> impl IntoView {
|
||||||
#[component]
|
#[component]
|
||||||
pub fn LoadingButton() -> impl IntoView {
|
pub fn LoadingButton() -> impl IntoView {
|
||||||
let loading = create_rw_signal(false);
|
let loading = create_rw_signal(false);
|
||||||
|
let on_click = move |_| {
|
||||||
|
loading.set(true);
|
||||||
|
set_timeout(
|
||||||
|
move || {
|
||||||
|
loading.set(false);
|
||||||
|
},
|
||||||
|
std::time::Duration::new(2, 0),
|
||||||
|
);
|
||||||
|
};
|
||||||
view! {
|
view! {
|
||||||
<h3>"loading"</h3>
|
<h3>"Loading"</h3>
|
||||||
<Demo>
|
<Demo>
|
||||||
<Space>
|
<Space>
|
||||||
<Button loading color=ButtonColor::ERROR icon=icondata::AiIcon::AiCloseOutlined on:click=move |_| loading.set(true)>
|
<Button loading on_click icon=icondata::AiIcon::AiCloseOutlined>
|
||||||
"ERROR Color Icon"
|
"Click Me"
|
||||||
</Button>
|
</Button>
|
||||||
<Button loading color=ButtonColor::ERROR icon=icondata::AiIcon::AiCloseOutlined round=true>
|
<Button loading on_click>
|
||||||
|
"Click Me"
|
||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
<DemoCode slot html=highlight_str!(r#"
|
<DemoCode slot html=highlight_str!(r#"
|
||||||
let loading = create_rw_signal(false);
|
let loading = create_rw_signal(false);
|
||||||
|
let on_click = move |_| {
|
||||||
|
loading.set(true);
|
||||||
|
set_timeout(
|
||||||
|
move || {
|
||||||
|
loading.set(false);
|
||||||
|
},
|
||||||
|
std::time::Duration::new(2, 0),
|
||||||
|
);
|
||||||
|
};
|
||||||
view! {
|
view! {
|
||||||
<Button loading color=ButtonColor::ERROR icon=icondata::AiIcon::AiCloseOutlined>
|
<Space>
|
||||||
"ERROR Color Icon"
|
<Button loading on_click icon=icondata::AiIcon::AiCloseOutlined>
|
||||||
</Button>
|
"Click Me"
|
||||||
<Button loading color=ButtonColor::ERROR icon=icondata::AiIcon::AiCloseOutlined round=true>
|
</Button>
|
||||||
</Button>
|
<Button loading on_click>
|
||||||
|
"Click Me"
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
}
|
}
|
||||||
"#, "rust")>
|
"#, "rust")>
|
||||||
""
|
""
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
color: var(--font-color);
|
color: var(--font-color);
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -14,12 +13,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.melt-button:hover {
|
.melt-button:hover {
|
||||||
transition: all 0.3s;
|
|
||||||
border-color: var(--border-color-hover);
|
border-color: var(--border-color-hover);
|
||||||
background-color: var(--background-color-hover);
|
background-color: var(--background-color-hover);
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
transition: all 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.melt-button:active {
|
.melt-button:active:not(.melt-button--disabled) {
|
||||||
transition: all 0.3s;
|
transition: all 0.3s;
|
||||||
border-color: var(--border-color-hover);
|
border-color: var(--border-color-hover);
|
||||||
background-color: var(--background-color-active);
|
background-color: var(--background-color-active);
|
||||||
|
|
|
@ -58,6 +58,8 @@ pub fn Button(
|
||||||
#[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, into)] loading: MaybeSignal<bool>,
|
||||||
|
#[prop(optional, into)] disabled: MaybeSignal<bool>,
|
||||||
|
#[prop(optional, into)] on_click: Option<Callback<ev::MouseEvent>>,
|
||||||
#[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);
|
||||||
|
@ -90,13 +92,33 @@ pub fn Button(
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let disabled = create_memo(move |_| {
|
||||||
|
if loading.get() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
disabled.get()
|
||||||
|
});
|
||||||
|
|
||||||
|
let on_click = move |event| {
|
||||||
|
if disabled.get() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Some(callback) = on_click.as_ref() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
callback.call(event);
|
||||||
|
};
|
||||||
|
|
||||||
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)
|
||||||
class=("melt-button--link", move || type_.get() == ButtonType::LINK)
|
class=("melt-button--link", move || type_.get() == ButtonType::LINK)
|
||||||
class=("melt-button--round", move || round.get())
|
class=("melt-button--round", move || round.get())
|
||||||
|
class=("melt-button--disabled", move || disabled.get())
|
||||||
style=move || format!("{}{}", css_vars.get(), style.get())
|
style=move || format!("{}{}", css_vars.get(), style.get())
|
||||||
|
on:click=on_click
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
move || {
|
move || {
|
||||||
|
|
Loading…
Add table
Reference in a new issue