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
50
51
52
53
54
55
56
57
58
59
60
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: i64,
    #[props(default)]
    pub closed: bool,

    #[props(into, default)]
    pub style: String,
    #[props(into, default)]
    pub class: String,
    #[props(into)]
    pub slot: Option<String>,
}

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),
            closed: bool_attr!(cx.props.closed),

            style: string_attr!(cx.props.style),
            class: string_attr!(cx.props.class),
            slot: optional_string_attr!(cx.props.slot),
        }
    }
}

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