#![doc = include_str!("../DIOXUS.md")]
use crate::common::{
Ingredient, SushiData, SushiOuterSheet, SushiShape, SushiSize, SushiState, SushiView,
TopEdgeDecoration,
};
use crate::svg::render_sushi;
use dioxus::prelude::*;
#[derive(Props, PartialEq, Clone)]
pub struct SushiProps {
#[props(default = "sushi".to_string())]
pub id: String,
#[props(default = "Custom Roll".to_string())]
pub name: String,
#[props(default)]
pub shape: SushiShape,
#[props(default)]
pub state: SushiState,
#[props(default)]
pub view: SushiView,
#[props(default = vec![Ingredient::Salmon])]
pub ingredients: Vec<Ingredient>,
#[props(default)]
pub outer_sheet: SushiOuterSheet,
#[props(default)]
pub size: SushiSize,
#[props(default)]
pub rice_color: Option<String>,
#[props(default)]
pub top_edge: Option<TopEdgeDecoration>,
#[props(default = 1.0)]
pub scale: f64,
#[props(default = "")]
pub class: &'static str,
#[props(default = "display:inline-block;")]
pub style: &'static str,
#[props(default)]
pub description: Option<String>,
}
#[component]
pub fn Sushi(props: SushiProps) -> Element {
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);
rsx! {
div {
class: "{full_class}",
style: "{props.style}",
role: "figure",
aria_label: "{props.name}",
tabindex: "0",
dangerous_inner_html: "{svg}",
}
}
}
#[derive(Props, PartialEq, Clone)]
pub struct SushiGalleryProps {
#[props(default)]
pub items: Vec<SushiData>,
#[props(default = "sushi-gallery")]
pub class: &'static str,
#[props(default = "display:flex;flex-wrap:wrap;gap:16px;align-items:center;")]
pub style: &'static str,
#[props(default = "Sushi Gallery")]
pub aria_label: &'static str,
}
#[component]
pub fn SushiGallery(props: SushiGalleryProps) -> Element {
rsx! {
section {
class: "{props.class}",
style: "{props.style}",
role: "region",
aria_label: "{props.aria_label}",
for item in props.items.iter() {
{
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
);
rsx! {
div {
key: "{item.id}",
dangerous_inner_html: "{card}",
}
}
}
}
}
}
}