mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-02 08:34:15 -05:00
feat: RadioGroup adds name prop
This commit is contained in:
parent
9e6a1220d5
commit
61b937f688
2 changed files with 13 additions and 4 deletions
|
@ -23,14 +23,14 @@ pub fn Radio(
|
||||||
move |_| {
|
move |_| {
|
||||||
item_value.with_value(|value| {
|
item_value.with_value(|value| {
|
||||||
group
|
group
|
||||||
.0
|
.value
|
||||||
.with(|group_value| group_value.as_ref() == Some(value))
|
.with(|group_value| group_value.as_ref() == Some(value))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let on_change = move |_| {
|
let on_change = move |_| {
|
||||||
group.0.set(Some(item_value.get_value()));
|
group.value.set(Some(item_value.get_value()));
|
||||||
};
|
};
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
|
@ -43,6 +43,7 @@ pub fn Radio(
|
||||||
class="thaw-radio__input"
|
class="thaw-radio__input"
|
||||||
type="radio"
|
type="radio"
|
||||||
id=id.clone()
|
id=id.clone()
|
||||||
|
name=group.name
|
||||||
value=item_value.get_value()
|
value=item_value.get_value()
|
||||||
prop:checked=move || checked.get()
|
prop:checked=move || checked.get()
|
||||||
on:change=on_change
|
on:change=on_change
|
||||||
|
|
|
@ -4,10 +4,15 @@ use thaw_utils::Model;
|
||||||
#[component]
|
#[component]
|
||||||
pub fn RadioGroup(
|
pub fn RadioGroup(
|
||||||
#[prop(optional, into)] value: Model<Option<String>>,
|
#[prop(optional, into)] value: Model<Option<String>>,
|
||||||
|
/// The name of this radio group.
|
||||||
|
#[prop(optional, into)]
|
||||||
|
name: Option<String>,
|
||||||
children: Children,
|
children: Children,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
|
let name = name.unwrap_or_else(|| uuid::Uuid::new_v4().to_string());
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Provider value=RadioGroupInjection(value)>
|
<Provider value=RadioGroupInjection{ value, name }>
|
||||||
<div class="thaw-radio-group" role="radiogroup" style="display: flex;align-items: flex-start">
|
<div class="thaw-radio-group" role="radiogroup" style="display: flex;align-items: flex-start">
|
||||||
{children()}
|
{children()}
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,7 +21,10 @@ pub fn RadioGroup(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct RadioGroupInjection(pub Model<Option<String>>);
|
pub(crate) struct RadioGroupInjection {
|
||||||
|
pub value: Model<Option<String>>,
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
impl RadioGroupInjection {
|
impl RadioGroupInjection {
|
||||||
pub fn use_() -> RadioGroupInjection {
|
pub fn use_() -> RadioGroupInjection {
|
||||||
|
|
Loading…
Add table
Reference in a new issue