material_yew/
button.rs

1use crate::bool_to_option;
2use wasm_bindgen::prelude::*;
3use yew::prelude::*;
4use yew::virtual_dom::AttrValue;
5
6#[wasm_bindgen(module = "/build/mwc-button.js")]
7extern "C" {
8    #[derive(Debug)]
9    type Button;
10
11    // This needs to be added to each component
12    #[wasm_bindgen(getter, static_method_of = Button)]
13    fn _dummy_loader() -> JsValue;
14}
15
16// call the macro with the type
17loader_hack!(Button);
18
19/// Props for [`MatButton`]
20///
21/// [MWC Documentation for properties](https://github.com/material-components/material-components-web-components/tree/v0.27.0/packages/button#propertiesattributes)
22#[derive(Debug, Properties, PartialEq, Clone)]
23pub struct ButtonProps {
24    pub label: String,
25    #[prop_or_default]
26    pub icon: Option<AttrValue>,
27    #[prop_or_default]
28    pub raised: bool,
29    #[prop_or_default]
30    pub unelevated: bool,
31    #[prop_or_default]
32    pub outlined: bool,
33    #[prop_or_default]
34    pub dense: bool,
35    #[prop_or_default]
36    pub disabled: bool,
37    #[prop_or_default]
38    pub trailing_icon: bool,
39}
40
41component!(
42    MatButton,
43    ButtonProps,
44    |props: &ButtonProps| {
45        html! {
46             <mwc-button
47             icon={props.icon.clone()}
48             label={props.label.clone()}
49             disabled={props.disabled}
50             raised={bool_to_option(props.raised)}
51             unelevated={bool_to_option(props.unelevated)}
52             outlined={bool_to_option(props.outlined)}
53             dense={bool_to_option(props.dense)}
54             trailingIcon={bool_to_option(props.trailing_icon)}
55             ></mwc-button>
56        }
57    },
58    Button,
59    "button"
60);