#![doc = include_str!("../YEW.md")]
use crate::common::{
Ingredient, SushiData, SushiOuterSheet, SushiShape, SushiSize, SushiState, SushiView,
TopEdgeDecoration,
};
use crate::svg::render_sushi;
use yew::prelude::*;
#[derive(Properties, PartialEq, Clone)]
pub struct SushiProps {
#[prop_or("sushi".to_string())]
pub id: String,
#[prop_or("Custom Roll".to_string())]
pub name: String,
#[prop_or_default]
pub shape: SushiShape,
#[prop_or_default]
pub state: SushiState,
#[prop_or_default]
pub view: SushiView,
#[prop_or(vec![Ingredient::Salmon])]
pub ingredients: Vec<Ingredient>,
#[prop_or_default]
pub outer_sheet: SushiOuterSheet,
#[prop_or_default]
pub size: SushiSize,
#[prop_or_default]
pub rice_color: Option<String>,
#[prop_or_default]
pub top_edge: Option<TopEdgeDecoration>,
#[prop_or(1.0)]
pub scale: f64,
#[prop_or_default]
pub class: &'static str,
#[prop_or("display:inline-block;")]
pub style: &'static str,
#[prop_or_default]
pub description: Option<String>,
}
#[function_component(Sushi)]
pub fn sushi(props: &SushiProps) -> Html {
let data = SushiData {
id: props.id.clone(),
name: props.name.clone(),
shape: props.shape,
state: props.state,
view: props.view,
ingredients: props.ingredients.clone(),
outer_sheet: props.outer_sheet.clone(),
size: props.size.clone(),
rice_color: props.rice_color.clone(),
top_edge: props.top_edge.clone(),
description: props.description.clone(),
};
let svg = render_sushi(&data, props.scale);
let full_class = format!("sushi-wrapper {}", props.class);
Html::from_html_unchecked(
format!(
r#"<div class="{}" style="{}" role="figure" aria-label="{}" tabindex="0">{}</div>"#,
full_class, props.style, props.name, svg
)
.into(),
)
}
#[derive(Properties, PartialEq, Clone)]
pub struct SushiGalleryProps {
#[prop_or_default]
pub items: Vec<SushiData>,
#[prop_or("sushi-gallery")]
pub class: &'static str,
#[prop_or("display:flex;flex-wrap:wrap;gap:16px;align-items:center;")]
pub style: &'static str,
#[prop_or("Sushi Gallery")]
pub aria_label: &'static str,
}
#[function_component(SushiGallery)]
pub fn sushi_gallery(props: &SushiGalleryProps) -> Html {
html! {
<section
class={props.class}
style={props.style}
role="region"
aria-label={props.aria_label}
>
{ for props.items.iter().map(|item| {
let name = item.name.clone();
let svg = render_sushi(item, 1.0);
let card_html = format!(
r#"<figure class="sushi-card" tabindex="0" role="figure" aria-label="{name}">
{svg}
<figcaption class="sushi-card-caption">{name}</figcaption>
</figure>"#,
name = name, svg = svg
);
Html::from_html_unchecked(card_html.into())
}) }
</section>
}
}