use rscx::{component, html, props, MapFragmentExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = app().await;
println!("{}", app);
Ok(())
}
async fn app() -> String {
let s = "ul { color: red; }";
html! {
<!DOCTYPE html>
<html>
<head>
<style>{s}</style>
</head>
<body>
<Section />
<Section title="Hello">
<Items />
</Section>
</body>
</html>
}
}
#[props]
struct SectionProps {
#[builder(setter(into), default = "Default Title".to_string())]
title: String,
#[builder(default)]
children: String,
}
#[component]
fn Section(props: SectionProps) -> String {
html! {
<div>
<h1>{ props.title }</h1>
{ props.children }
</div>
}
}
#[component]
async fn Items() -> String {
let data = load_data_async().await;
html! {
<ul>
{
data
.into_iter()
.map_fragment(|item| html! { <li>{ item }</li> })
}
</ul>
}
}
async fn load_data_async() -> Vec<String> {
vec!["a".to_string(), "b".to_string(), "c".to_string()]
}