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
use dioxus::{core::AttributeValue, prelude::*};
use wasm_bindgen::prelude::*;

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

    // This needs to be added to each component
    #[wasm_bindgen(getter, static_method_of = CircularProgress)]
    fn _dummy_loader() -> JsValue;
}

// call the macro with the type
loader_hack!(CircularProgress);

/// Props for [`MatCircularProgress`]
///
/// [MWC Documentation for properties](https://github.com/material-components/material-components-web-components/tree/v0.27.0/packages/circular-progress#propertiesattributes)
#[derive(Props, PartialEq)]
pub struct CircularProgressProps {
    #[props(default)]
    pub indeterminate: bool,
    #[props(default)]
    pub progress: f32,
    #[props(default)]
    pub density: u32,
    #[props(default)]
    pub closed: bool,
}

fn render(cx: Scope<CircularProgressProps>) -> Element {
    render! {
        mwc-circular-progress {
            "indeterminate": bool_attr!(cx.props.indeterminate),
            "progress": AttributeValue::Float(cx.props.progress.into()),
            "density": AttributeValue::Int(cx.props.density.into()),
            "closed": bool_attr!(cx.props.closed),
        }
    }
}

component!(
    MatCircularProgress,
    CircularProgressProps,
    render,
    CircularProgress,
    "circular-progress"
);