use std::fmt::Write;
use crate::prelude::{Breakpoint, WithBreakpoints, wrap::wrapper_div_with_attributes};
use yew::prelude::*;
use yew::virtual_dom::AttributeOrProperty;
#[derive(Clone, PartialEq, Properties)]
pub struct GalleryProperties {
pub children: Children,
#[prop_or_default]
pub gutter: bool,
#[prop_or_default]
pub style: AttrValue,
#[prop_or_default]
pub min_widths: WithBreakpoints<AttrValue>,
#[prop_or_default]
pub max_widths: WithBreakpoints<AttrValue>,
}
const MIN: &str = "--pf-v6-l-gallery--GridTemplateColumns--min";
const MAX: &str = "--pf-v6-l-gallery--GridTemplateColumns--max";
impl Breakpoint {
fn suffix(&self) -> &'static str {
match self {
Breakpoint::None => "",
Breakpoint::Small => "-on-sm",
Breakpoint::Medium => "-on-md",
Breakpoint::Large => "-on-lg",
Breakpoint::XLarge => "-on-xl",
Breakpoint::XXLarge => "-on-2xl",
}
}
}
#[function_component(Gallery)]
pub fn gallery(props: &GalleryProperties) -> Html {
let mut classes = classes!("pf-v6-l-gallery");
if props.gutter {
classes.push(classes!("pf-m-gutter"));
}
let mut style = String::new();
for (property, widths) in [(MIN, &props.min_widths), (MAX, &props.max_widths)] {
for x in widths.iter() {
let _ = write!(style, "{property}{}: {};", x.on.suffix(), x.modifier);
}
}
style.push_str(&props.style);
html! (
<div class={classes} style={style}>
{ for props.children.iter().map(|child|{
wrapper_div_with_attributes(child, &[("class", AttributeOrProperty::Static("pf-v6-l-gallery__item"))])
}) }
</div>
)
}