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 crate::{Icon, Variant};
use yew::{html, Component, ComponentLink, Html};
use yew::{Callback, Properties};
#[derive(Clone, PartialEq, Properties)]
pub struct Props {
#[prop_or_default]
pub id: String,
pub label: String,
pub onclick: Callback<yew::MouseEvent>,
#[prop_or_default]
pub variant: Variant,
#[prop_or_default]
pub icon: Option<Icon>,
}
pub struct Button {
props: Props,
}
impl Component for Button {
type Message = ();
type Properties = Props;
fn create(props: Self::Properties, _link: ComponentLink<Self>) -> Self {
Self { props }
}
fn update(&mut self, _msg: Self::Message) -> bool {
true
}
fn change(&mut self, props: Self::Properties) -> bool {
if self.props != props {
self.props = props;
true
} else {
false
}
}
fn view(&self) -> Html {
html! {
<button
id=self.props.id.clone()
class=("pf-c-button", self.props.variant.as_class())
type="button"
onclick=self.props.onclick.clone()>
{ self.icon() }
{ self.props.label.clone() }
</button>
}
}
}
impl Button {
pub fn icon(&self) -> Html {
match self.props.icon {
Some(i) => html! {
<span class="pf-c-button__icon pf-m-start">
<i class=(i.as_class())/>
</span>
},
None => html! {},
}
}
}