material_dioxus/
icon_button.rs

1use dioxus::prelude::*;
2use wasm_bindgen::prelude::*;
3
4#[wasm_bindgen(module = "/build/mwc-icon-button.js")]
5extern "C" {
6    #[derive(Debug)]
7    type IconButton;
8
9    #[wasm_bindgen(getter, static_method_of = IconButton)]
10    fn _dummy_loader() -> JsValue;
11}
12
13loader_hack!(IconButton);
14
15/// Props for [`MatIconButton`]
16///
17/// [MWC Documentation for properties](https://github.com/material-components/material-components-web-components/tree/v0.27.0/packages/icon-button#propertiesattributes)
18#[derive(Props)]
19pub struct IconButtonProps<'a> {
20    #[props(into)]
21    pub label: Option<String>,
22    #[props(into)]
23    pub icon: Option<String>,
24    #[props(default)]
25    pub disabled: bool,
26    #[props(default)]
27    pub children: Element<'a>,
28
29    #[props(into, default)]
30    pub style: String,
31    #[props(into, default)]
32    pub class: String,
33    #[props(into)]
34    pub slot: Option<String>,
35    #[props(default)]
36    pub dialog_initial_focus: bool,
37}
38
39fn render<'a>(cx: Scope<'a, IconButtonProps<'a>>) -> Element<'a> {
40    match &cx.props.children {
41        Some(children) => {
42            render! {
43                mwc-icon-button {
44                    label: optional_string_attr!(cx.props.label),
45                    icon: optional_string_attr!(cx.props.icon),
46                    disabled: bool_attr!(cx.props.disabled),
47
48                    style: string_attr!(cx.props.style),
49                    class: string_attr!(cx.props.class),
50                    slot: optional_string_attr!(cx.props.slot),
51                    dialogInitialFocus: bool_attr!(cx.props.dialog_initial_focus),
52
53                    children
54                }
55            }
56        }
57        None => {
58            render! {
59                mwc-icon-button {
60                    label: optional_string_attr!(cx.props.label),
61                    icon: optional_string_attr!(cx.props.icon),
62                    disabled: bool_attr!(cx.props.disabled),
63
64                    style: string_attr!(cx.props.style),
65                    class: string_attr!(cx.props.class),
66                    slot: optional_string_attr!(cx.props.slot),
67                    dialogInitialFocus: bool_attr!(cx.props.dialog_initial_focus),
68                }
69            }
70        }
71    }
72}
73
74component!('a, MatIconButton, IconButtonProps, render, IconButton, "icon-button");