use yew::prelude::*;
use crate::vdom::{comp_with, tag};
pub struct Table;
impl Table {
pub fn render(columns: Children, rows: Children) -> Html {
comp_with::<Table>(TableProps {
columns,
children: rows,
})
.to_vnode()
}
}
#[derive(PartialEq, Properties)]
pub struct TableProps {
pub columns: Children,
pub children: Children,
}
impl Component for Table {
type Message = ();
type Properties = TableProps;
fn create(_ctx: &Context<Self>) -> Self {
Self
}
fn view(&self, ctx: &Context<Self>) -> Html {
let columns = &ctx.props().columns;
let children = &ctx.props().children;
tag("table")
.class("mui-table")
.append(
tag("thead").append(
tag("tr").append_all(
columns
.iter()
.enumerate()
.map(|(i, node)| tag("th").append(node).key(i.to_string())),
),
),
)
.append(tag("tbody").append_all(children.iter()))
.to_vnode()
}
}