2023-10-03 15:57:35 +08:00
|
|
|
mod checkbox_group;
|
|
|
|
mod checkbox_item;
|
|
|
|
|
2023-06-30 22:25:41 +08:00
|
|
|
use crate::{components::*, icon::*, theme::use_theme, utils::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::*;
|
2023-06-10 12:40:52 +08:00
|
|
|
use stylers::style_sheet_str;
|
2023-04-14 17:28:32 +08:00
|
|
|
|
|
|
|
#[component]
|
2023-08-29 09:11:22 +08:00
|
|
|
pub fn Checkbox(#[prop(into)] checked: RwSignal<bool>, children: Children) -> impl IntoView {
|
|
|
|
let theme = use_theme(Theme::light);
|
2023-04-14 17:28:32 +08:00
|
|
|
let class_name = mount_style("checkbox", || {
|
|
|
|
style_sheet_str!("./src/checkbox/checkbox.css")
|
|
|
|
});
|
|
|
|
|
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-08-29 09:11:22 +08:00
|
|
|
view! { class=class_name,
|
2023-06-10 12:40:52 +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())>
|
2023-04-14 17:28:32 +08:00
|
|
|
<input class="melt-checkbox__input" type="checkbox" />
|
|
|
|
<div class="melt-checkbox__dot">
|
2023-06-10 12:40:52 +08:00
|
|
|
<If cond=checked>
|
|
|
|
<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>
|
|
|
|
<div class="melt-checkbox__label">
|
2023-08-29 09:11:22 +08:00
|
|
|
{ children() }
|
2023-04-14 17:28:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|