Skip to main content

kayrx_ui/widget/
button.rs

1use web_sys::MouseEvent;
2use crate::fabric::html;
3use crate::fabric::callback::Callback;
4use crate::fabric::html::{Html, ComponentLink, ShouldRender, Renderable, Component, Children};
5
6pub struct Button {
7    props: Props,
8}
9
10pub enum Msg {
11    Clicked,
12}
13
14#[derive(Clone, Properties)]
15pub struct Props {
16    #[prop_or_else(Callback::noop)]
17    pub onclick: Callback<MouseEvent>,
18    #[prop_or_default]
19    pub children: Children,
20    #[prop_or_default]
21    pub disabled: bool,
22}
23
24impl Component for Button {
25    type Message = Msg;
26    type Properties = Props;
27
28    fn create(props: Self::Properties, _: ComponentLink<Self>) -> Self {
29        Button { props }
30    }
31
32    fn update(&mut self, _: Self::Message) -> ShouldRender {
33        false
34    }
35
36    fn change(&mut self, props: Self::Properties) -> ShouldRender {
37        self.props.onclick = props.onclick;
38        true
39    }
40
41    fn view(&self) -> Html {
42        html! {
43            <button
44                disabled=self.props.disabled
45                class="bow-button"
46                onclick=self.props.onclick.reform(|e| e)>
47                { self.props.children.render() }
48
49            </button>
50        }
51    }
52}