lan-party-backend/web/src/components/mod.rs

66 lines
1.5 KiB
Rust

pub mod messages;
pub use lan_party_core::components::Button;
use sycamore::{builder::prelude::*, prelude::*};
use web_sys::Event;
#[derive(Prop)]
pub struct TableProps<'a, G: Html> {
pub headers: Vec<String>,
pub children: Children<'a, G>,
}
#[component]
pub fn Table<'a, G: Html>(cx: Scope<'a>, props: TableProps<'a, G>) -> View<G> {
let children = props.children.call(cx);
view! { cx,
table {
thead {
tr {
(View::new_fragment(props.headers.iter().cloned().map(|header| view! { cx,
th(scope="col") {
(header)
}
}).collect()))
}
}
tbody {
(children)
}
}
}
}
#[derive(Prop)]
pub struct ModalProps<'a, G: Html> {
pub open: &'a Signal<bool>,
pub title: String,
pub children: Children<'a, G>,
}
#[component]
pub fn Modal<'a, G: Html>(cx: Scope<'a>, props: ModalProps<'a, G>) -> View<G> {
let children = props.children.call(cx);
let class = create_memo(cx, || {
if *props.open.get() {
"modal"
} else {
"modal hidden"
}
});
view! { cx,
div(class=class) {
h4 { (props.title) }
div(class="modal-close") {
Button(icon="mdi-close".into(), onclick=move |_| props.open.set(false))
}
(children)
}
}
}