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
61
62
use crate::{function_component, html, Classes, Html, Paper, Properties};

/// Properties for Image component
#[derive(Properties, PartialEq)]
pub struct ImageProps {
    #[prop_or_default]
    pub elevation: u8,
    #[prop_or_default]
    pub class: String,
    #[prop_or_default]
    pub alt: String,
    #[prop_or_default]
    pub src: String,
    #[prop_or_default]
    pub style: String,
}

/// Component for displaying an image
///
/// Basic example displaying image with classes
/// ```rust
/// use webui::*;
///
/// fn page() -> Html {
/// 	html! {
/// 		<Image src="Logo.svg" alt="" class="d-flex flex-column" />
/// 	}
/// }
/// ```
///
/// Apply elevetation
///
/// Elevation applies a box shadow to the Image component.
/// Valid ranges range from 0 ro 25.
/// ```rust
/// use webui::*;
///
/// fn page() -> Html {
/// 	html! {
/// 		<Image src="Logo.svg" elevation={10} />
/// 	}
/// }
/// ```
#[function_component(Image)]
pub fn image(props: &ImageProps) -> Html {
    let classes = &mut Classes::new();
    classes.push("image");

    if props.elevation > 0 {
        classes.push(format!("elevation-{}", props.elevation));
    }

    if !props.class.is_empty() {
        classes.push(&props.class);
    }

    html! {
        <Paper class={classes.to_string()} style={props.style.to_owned()}>
            <img src={props.src.to_string()} alt={props.alt.to_string()} title={props.alt.to_string()} />
        </Paper>
    }
}