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
use css_in_rust_next::Style;
use web_sys::MouseEvent;
use yew::{html, Callback, Component, Context, Html, Properties};
#[derive(PartialEq, Properties)]
pub struct ButtonProperties {
pub label: String,
pub icon: Option<Html>,
#[prop_or_default]
pub disabled: bool,
pub onclick: Callback<MouseEvent>,
}
pub struct Button {
style: Style,
}
impl Component for Button {
type Message = ();
type Properties = ButtonProperties;
fn create(_ctx: &Context<Self>) -> Self {
let style = Style::create(
"Component",
r#"
padding: 7px;
cursor: pointer;
svg {
vertical-align: middle;
height: 18px;
}
"#,
)
.unwrap();
Button { style }
}
fn view(&self, ctx: &Context<Self>) -> Html {
html!(
<button onclick={ctx.props().onclick.clone()} class={self.style.clone()} disabled={ctx.props().disabled}>
{ctx.props().icon.clone().unwrap_or_default()}
{&ctx.props().label}
</button>
)
}
}