material_dioxus/
fab.rs

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