#![doc = include_str!("../LEPTOS.md")]
#![allow(unused)]
use crate::common::{
Ingredient, NORI_COLOR, RICE_COLOR, SushiData, SushiOuterSheet, SushiShape, SushiSize,
SushiState, SushiView, TopEdgeDecoration,
};
use crate::svg::render_sushi;
use leptos::prelude::*;
#[component]
pub fn Sushi(
#[prop(into, default = "sushi".to_string())]
id: String,
#[prop(into, default = "Custom Roll".to_string())]
name: String,
#[prop(default = SushiShape::Circular)]
shape: SushiShape,
#[prop(default = SushiState::Rolled)]
state: SushiState,
#[prop(default = SushiView::Top)]
view: SushiView,
#[prop(default = vec![Ingredient::Salmon])]
ingredients: Vec<Ingredient>,
#[prop(default = SushiOuterSheet::default())]
outer_sheet: SushiOuterSheet,
#[prop(default = SushiSize::default())]
size: SushiSize,
#[prop(default = None)]
rice_color: Option<String>,
#[prop(default = None)]
top_edge: Option<TopEdgeDecoration>,
#[prop(default = 1.0)]
scale: f64,
#[prop(default = "")]
class: &'static str,
#[prop(default = "display:inline-block;")]
style: &'static str,
#[prop(default = None)]
description: Option<String>,
) -> impl IntoView {
let data = SushiData {
id,
name: name.clone(),
shape,
state,
view,
ingredients,
outer_sheet,
size,
rice_color,
top_edge,
description,
};
let svg = render_sushi(&data, scale);
let full_class = format!("sushi-wrapper {class}");
let label = name;
view! {
<div
class={full_class}
style={style}
role="figure"
aria-label={label}
tabindex="0"
inner_html={svg}
/>
}
}
#[component]
pub fn SushiGallery(
#[prop(default = vec![])]
items: Vec<SushiData>,
#[prop(default = "sushi-gallery")]
class: &'static str,
#[prop(default = "display:flex;flex-wrap:wrap;gap:16px;align-items:center;")]
style: &'static str,
#[prop(default = "Sushi Gallery")]
aria_label: &'static str,
) -> impl IntoView {
view! {
<section class={class} style={style} role="region" aria-label={aria_label}>
<For
each=move || items.clone()
key=|item| item.id.clone()
let:item
>
{move || {
let svg = render_sushi(&item, 1.0);
let name = item.name.clone();
let card = 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
);
view! { <div inner_html={card}/> }
}}
</For>
</section>
}
}