diff --git a/demo_markdown/docs/checkbox/mod.md b/demo_markdown/docs/checkbox/mod.md
index e1eb6fd..0e26a48 100644
--- a/demo_markdown/docs/checkbox/mod.md
+++ b/demo_markdown/docs/checkbox/mod.md
@@ -1,10 +1,10 @@
# Checkbox
```rust demo
-let value = create_rw_signal(false);
+let checked = RwSignal::new(false);
view! {
- "Click"
+ "Click"
}
```
@@ -14,13 +14,13 @@ view! {
```rust demo
use std::collections::HashSet;
-let value = create_rw_signal(HashSet::new());
+let value = RwSignal::new(HashSet::new());
view! {
-
-
-
+
+
+
"value: " {move || format!("{:?}", value.get())}
}
diff --git a/thaw/src/checkbox/checkbox.css b/thaw/src/checkbox/checkbox.css
index 3eb7bc5..a7a3501 100644
--- a/thaw/src/checkbox/checkbox.css
+++ b/thaw/src/checkbox/checkbox.css
@@ -106,4 +106,5 @@
font-family: var(--fontFamilyBase);
font-size: var(--fontSizeBase300);
color: inherit;
+ cursor: inherit;
}
diff --git a/thaw/src/checkbox/checkbox_group.rs b/thaw/src/checkbox/checkbox_group.rs
index 9082359..44bed97 100644
--- a/thaw/src/checkbox/checkbox_group.rs
+++ b/thaw/src/checkbox/checkbox_group.rs
@@ -7,12 +7,20 @@ pub fn CheckboxGroup(
#[prop(optional, into)] value: Model>,
children: Children,
) -> impl IntoView {
- view! { }
+ view! {
+
+
+ {children()}
+
+
+ }
}
#[derive(Clone)]
pub(crate) struct CheckboxGroupInjection(pub Model>);
-pub(crate) fn use_checkbox_group() -> CheckboxGroupInjection {
- expect_context()
+impl CheckboxGroupInjection {
+ pub fn use_() -> Self {
+ expect_context()
+ }
}
diff --git a/thaw/src/checkbox/checkbox_item.rs b/thaw/src/checkbox/checkbox_item.rs
index 8c5179f..e5812fc 100644
--- a/thaw/src/checkbox/checkbox_item.rs
+++ b/thaw/src/checkbox/checkbox_item.rs
@@ -1,4 +1,4 @@
-use crate::checkbox::{checkbox_group::use_checkbox_group, Checkbox};
+use super::{checkbox_group::CheckboxGroupInjection, Checkbox};
use leptos::*;
use thaw_utils::OptionalProp;
@@ -6,39 +6,39 @@ use thaw_utils::OptionalProp;
pub fn CheckboxItem(
#[prop(optional, into)] label: Option,
#[prop(optional, into)] class: OptionalProp>,
- #[prop(into)] key: String,
+ #[prop(into)] value: String,
) -> impl IntoView {
- let checkbox_group_value = use_checkbox_group().0;
+ let group_value = CheckboxGroupInjection::use_().0;
let checked = RwSignal::new(false);
- let item_key = StoredValue::new(key);
+ let item_value = StoredValue::new(value);
let is_checked = Memo::new(move |_| {
- checkbox_group_value.with(|value| item_key.with_value(|key| value.contains(key)))
+ group_value.with(|group_value| item_value.with_value(|value| group_value.contains(value)))
});
Effect::new(move |_| {
checked.track();
if is_checked.get_untracked() {
- checkbox_group_value.update(move |value| {
- item_key.with_value(|key| {
- value.remove(key);
+ group_value.update(move |group_value| {
+ item_value.with_value(|value| {
+ group_value.remove(value);
});
});
} else if checked.get_untracked() {
- checkbox_group_value.update(move |value| {
- value.insert(item_key.get_value());
+ group_value.update(move |group_value| {
+ group_value.insert(item_value.get_value());
});
}
});
if let Some(label) = label {
view! {
-
+
{label}
}
} else {
- view! { }
+ view! { }
}
}
diff --git a/thaw/src/checkbox/mod.rs b/thaw/src/checkbox/mod.rs
index e5c307f..b3ece84 100644
--- a/thaw/src/checkbox/mod.rs
+++ b/thaw/src/checkbox/mod.rs
@@ -4,38 +4,56 @@ mod checkbox_item;
pub use checkbox_group::CheckboxGroup;
pub use checkbox_item::CheckboxItem;
-use crate::icon::*;
use leptos::*;
use thaw_components::*;
use thaw_utils::{class_list, mount_style, Model, OptionalProp};
#[component]
pub fn Checkbox(
- #[prop(optional, into)] value: Model,
+ #[prop(optional, into)] checked: Model,
#[prop(optional, into)] class: OptionalProp>,
#[prop(optional)] children: Option,
) -> impl IntoView {
mount_style("checkbox", include_str!("./checkbox.css"));
+ let id = uuid::Uuid::new_v4().to_string();
+ let input_ref = NodeRef::::new();
+
+ let on_change = move |_| {
+ let input = input_ref.get_untracked().unwrap();
+ checked.set(input.checked())
+ };
+
view! {
}