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
use dioxus::prelude::*;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(module = "/build/mwc-icon-button.js")]
extern "C" {
    #[derive(Debug)]
    type IconButton;

    #[wasm_bindgen(getter, static_method_of = IconButton)]
    fn _dummy_loader() -> JsValue;
}

loader_hack!(IconButton);

/// Props for [`MatIconButton`]
///
/// [MWC Documentation for properties](https://github.com/material-components/material-components-web-components/tree/v0.27.0/packages/icon-button#propertiesattributes)
#[derive(Props)]
pub struct IconButtonProps<'a> {
    #[props(into)]
    pub label: Option<String>,
    #[props(into)]
    pub icon: Option<String>,
    #[props(default)]
    pub disabled: bool,
    #[props(default)]
    pub children: Element<'a>,
}

fn render<'a>(cx: Scope<'a, IconButtonProps<'a>>) -> Element<'a> {
    match &cx.props.children {
        Some(children) => {
            render! {
                mwc-icon-button {
                    "label": optional_string_attr!(cx.props.label),
                    "icon": optional_string_attr!(cx.props.icon),
                    "disabled": bool_attr!(cx.props.disabled),
                    children
                }
            }
        }
        None => {
            render! {
                mwc-icon-button {
                    "label": optional_string_attr!(cx.props.label),
                    "icon": optional_string_attr!(cx.props.icon),
                    "disabled": bool_attr!(cx.props.disabled),
                }
            }
        }
    }
}

component!('a, MatIconButton, IconButtonProps, render, IconButton, "icon-button");