design_system/button/
button.rs

1use css_in_rust::Style;
2use yew::prelude::*;
3
4use yew_styles::button::{Button as Btn, Props, Msg};
5
6pub struct Button {
7    link: ComponentLink<Self>,
8    // title: String,
9    // onsignal: Callback<()>,
10    // color: String,
11    // style: Style,
12    props: Props,
13}
14
15// #[derive(Debug)]
16// pub enum Msg {
17//     Clicked,
18// }
19
20// #[derive(Clone, PartialEq, Properties, Debug)]
21// pub struct Props {
22//     #[prop_or_default]
23//     pub title: String,
24//     pub color: String,
25//     pub onsignal: Callback<()>,
26//     #[prop_or_default]
27//     pub class: String,
28// }
29
30impl Component for Button {
31    type Message = Msg;
32    type Properties = Props;
33
34    fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
35        // let style =
36        //     Style::create("button", include_str!("button.scss")).expect("An error occured while creating the style.");
37
38        Button {
39            props,
40            link
41        }
42    }
43
44    fn update(&mut self, msg: Self::Message) -> ShouldRender {
45        match msg {
46            Msg::Clicked(mouse_event) => {
47                self.props.onclick_signal.emit(mouse_event);
48            }
49        };
50        true
51    }
52
53    fn change(&mut self, props: Self::Properties) -> ShouldRender {
54
55        true
56    }
57
58    fn view(&self) -> Html {
59        html! {
60            <Btn
61                onclick_signal=self.link.callback(Msg::Clicked)
62            > { self.props.children.clone() }
63            </Btn>
64        }
65    }
66}