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

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

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

loader_hack!(Formfield);

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

fn render<'a>(cx: Scope<'a, FormfieldProps<'a>>) -> Element<'a> {
    render! {
        mwc-formfield {
            "label": optional_string_attr!(cx.props.label),
            "alignEnd": bool_attr!(cx.props.align_end),
            "spaceBetween": bool_attr!(cx.props.space_between),
            "nowrap": bool_attr!(cx.props.nowrap),
            &cx.props.children
        }
    }
}

component!('a, MatFormfield, FormfieldProps, render, Formfield, "formfield");