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
/// Generate a Dioxus component rendering the specified image.
///
/// ### Example
///
/// ```no_run
/// # use freya::prelude::*;
///
/// // You can pass as many `image` attributes you need, and these will become the default values and also allowed to be overriden.
/// import_image!(RustLogo, "../../../examples/rust_logo.png", {
///     width: "auto",
///     height: "40%",
///     aspect_ratio: "min",
/// });
///
/// fn app() -> Element {
///     rsx!(RustLogo {
///         width: "150",
///     })
/// }
/// ```
#[macro_export]
macro_rules! import_image {
    ($component_name:ident, $path:expr, { $($key:ident : $value:expr),* $(,)? }) => {
        #[allow(non_snake_case)]
        #[dioxus::prelude::component]
        pub fn $component_name(
            $(#[props(default = $value.to_string())] $key: String,)*
        ) -> freya::prelude::Element {
            use freya::prelude::*;
            let image_data = static_bytes(include_bytes!($path));

            rsx!(image {
                $($key: $key,)*
                image_data,
            })
        }
    };
}