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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use yew::prelude::*;
pub struct Radio {
props: RadioProps,
}
#[derive(Clone, PartialEq, Properties)]
pub struct RadioProps {
#[prop_or_default]
pub disabled: bool,
#[prop_or_default]
pub inline: bool,
#[prop_or_default]
pub large: bool,
#[prop_or_default]
pub checked: Option<bool>,
#[prop_or_default]
pub name: Option<String>,
#[prop_or_default]
pub onchange: Option<Callback<ChangeData>>,
#[prop_or_default]
pub label: yew::virtual_dom::VNode,
#[prop_or_default]
pub value: Option<String>,
}
impl Component for Radio {
type Message = ();
type Properties = RadioProps;
fn create(props: Self::Properties, _link: ComponentLink<Self>) -> Self {
Self { props }
}
fn update(&mut self, _msg: Self::Message) -> ShouldRender {
true
}
fn change(&mut self, props: Self::Properties) -> ShouldRender {
if self.props != props {
self.props = props;
true
} else {
false
}
}
fn view(&self) -> Html {
html! {
<label
class=classes!(
"bp3-control",
"bp3-radio",
self.props.disabled.then(|| "bp3-disabled"),
self.props.inline.then(|| "bp3-inline"),
self.props.large.then(|| "bp3-large"),
)
>
<input
type="radio"
onchange={self.props.onchange.clone().unwrap_or_default()}
disabled=self.props.disabled
value={self.props.value.clone().unwrap_or_default()}
checked=self.props.checked.unwrap_or(false)
name={self.props.name.clone().unwrap_or_default()}
/>
<span
class=classes!("bp3-control-indicator")
>
</span>
{self.props.label.clone()}
</label>
}
}
}