material_yew/
form_field.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-formfield.js")]
7extern "C" {
8    #[derive(Debug)]
9    type Formfield;
10
11    #[wasm_bindgen(getter, static_method_of = Formfield)]
12    fn _dummy_loader() -> JsValue;
13}
14
15loader_hack!(Formfield);
16
17/// Props for [`MatFormfield`]
18///
19/// [MWC Documentation for properties](https://github.com/material-components/material-components-web-components/tree/v0.27.0/packages/formfield#propertiesattributes)
20#[derive(Properties, PartialEq, Clone)]
21pub struct FormfieldProps {
22    pub children: Children,
23    #[prop_or_default]
24    pub label: Option<AttrValue>,
25    #[prop_or_default]
26    pub align_end: bool,
27    #[prop_or_default]
28    pub space_between: bool,
29    #[prop_or_default]
30    pub nowrap: bool,
31}
32
33component!(
34    MatFormfield,
35    FormfieldProps,
36    |props: &FormfieldProps| {
37        html! {
38             <mwc-formfield
39                 label={props.label.clone()}
40                 alignEnd={bool_to_option(props.align_end)}
41                 spaceBetween={bool_to_option(props.space_between)}
42                 nowrap={bool_to_option(props.nowrap)}
43             >{props.children.clone()}</mwc-formfield>
44        }
45    },
46    Formfield,
47    "formfield"
48);