1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::fmt::Display;
use leptos::prelude::*;
use crate::{components::Description, Name};
use strum::VariantArray;
#[component]
pub fn Radio<T>(
#[prop(into)] label: TextProp,
#[prop(into, default = None)] description: Option<TextProp>,
name: Name,
value: RwSignal<T>,
//value_label: impl Fn(&T) -> TextProp + 'static,
) -> impl IntoView
where
T: Clone
+ Copy
+ Into<&'static str>
+ VariantArray
+ PartialEq
+ Display
+ Send
+ Sync
+ 'static,
{
view! {
<div class="field radio-group-field">
<fieldset>
<legend>{label.get()}</legend>
{ T::VARIANTS.iter().map(move |&option| {
let is_checked = move || value.get() == option;
let option_value: &'static str = option.into();
//let value_label = value_label(&option);
view! {
<div class="field radio-field">
<label for=format!("{}-{}", name.to_string(), option_value)>
<span class="custom custom-radio-button"></span>
<input
type="radio"
name=name.to_string()
id=format!("{}-{}", name.to_string(), option_value)
value=option_value
checked=is_checked
on:change=move |_| {
value.set(option);
}
/>
{format!("{}", option)}
</label>
</div>
}
}).collect::<Vec<_>>() }
<Description description={description} />
</fieldset>
</div>
}
}