2023-10-03 15:57:35 +08:00
|
|
|
mod checkbox_group;
|
|
|
|
mod checkbox_item;
|
|
|
|
|
2023-10-07 15:43:39 +08:00
|
|
|
use crate::{
|
|
|
|
components::*,
|
|
|
|
icon::*,
|
|
|
|
theme::use_theme,
|
|
|
|
utils::{maybe_rw_signal::MaybeRwSignal, mount_style::mount_style},
|
|
|
|
Theme,
|
|
|
|
};
|
2023-10-03 15:57:35 +08:00
|
|
|
pub use checkbox_group::CheckboxGroup;
|
|
|
|
pub use checkbox_item::CheckboxItem;
|
2023-06-30 22:25:41 +08:00
|
|
|
use icondata::AiIcon;
|
2023-04-14 17:28:32 +08:00
|
|
|
use leptos::*;
|
|
|
|
|
|
|
|
#[component]
|
2023-10-07 15:43:39 +08:00
|
|
|
pub fn Checkbox(
|
|
|
|
#[prop(optional, into)] checked: MaybeRwSignal<bool>,
|
|
|
|
children: Children,
|
|
|
|
) -> impl IntoView {
|
2023-08-29 09:11:22 +08:00
|
|
|
let theme = use_theme(Theme::light);
|
2023-10-07 21:41:03 +08:00
|
|
|
mount_style("checkbox", include_str!("./checkbox.css"));
|
2023-04-14 17:28:32 +08:00
|
|
|
|
2023-08-29 09:11:22 +08:00
|
|
|
let css_vars = create_memo(move |_| {
|
2023-04-14 17:28:32 +08:00
|
|
|
let mut css_vars = String::new();
|
|
|
|
let theme = theme.get();
|
|
|
|
let bg_color = theme.common.color_primary;
|
|
|
|
css_vars.push_str(&format!("--background-color-checked: {bg_color};"));
|
|
|
|
css_vars
|
|
|
|
});
|
2023-06-10 12:40:52 +08:00
|
|
|
|
2023-10-07 21:41:03 +08:00
|
|
|
view! {
|
2023-10-08 09:28:13 +08:00
|
|
|
<div
|
|
|
|
class:melt-checkbox=true
|
|
|
|
class=("melt-checkbox--checked", move || checked.get())
|
|
|
|
style=move || css_vars.get()
|
|
|
|
on:click=move |_| checked.set(!checked.get_untracked())
|
|
|
|
>
|
|
|
|
<input class="melt-checkbox__input" type="checkbox"/>
|
2023-04-14 17:28:32 +08:00
|
|
|
<div class="melt-checkbox__dot">
|
2023-10-07 15:43:39 +08:00
|
|
|
<If cond=checked.clone_into()>
|
2023-06-10 12:40:52 +08:00
|
|
|
<Then slot>
|
2023-06-30 22:25:41 +08:00
|
|
|
<Icon icon=Icon::from(AiIcon::AiCheckOutlined) style="color: white"/>
|
2023-06-10 12:40:52 +08:00
|
|
|
</Then>
|
|
|
|
</If>
|
2023-04-14 17:28:32 +08:00
|
|
|
</div>
|
2023-10-08 09:28:13 +08:00
|
|
|
<div class="melt-checkbox__label">{children()}</div>
|
2023-04-14 17:28:32 +08:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|