pub mod event; use sycamore::prelude::*; use web_sys::Event; #[derive(Prop)] pub struct PageProps<'a, G: Html> { pub children: Children<'a, G>, } #[component] pub fn Page<'a, G: Html>(cx: Scope<'a>, props: PageProps<'a, G>) -> View { let children = props.children.call(cx); view! { cx, div(class="max-w-7xl mx-auto") { (children) } } } #[derive(Prop)] pub struct Props { pub onclick: F, #[builder(default)] pub text: String, #[builder(default)] pub icon: String, } #[component] pub fn Button<'a, G: Html, F: 'a + FnMut(Event)>(cx: Scope<'a>, props: Props) -> View { let mut icon_class = String::from("mdi text-lg "); if !props.icon.is_empty() { icon_class.push_str(&props.icon); } view! { cx, button(class="bg-gray-700 hover:bg-gray-800 text-gray-400 font-bold py-2 px-2 rounded inline-flex items-center",on:click=props.onclick) { span(class=icon_class) span { (props.text) } } } } #[derive(Prop)] pub struct TableProps<'a, G: Html> { pub headers: Vec, pub children: Children<'a, G>, } #[component] pub fn Table<'a, G: Html>(cx: Scope<'a>, props: TableProps<'a, G>) -> View { let children = props.children.call(cx); view! { cx, div(class="inline-block min-w-full py-2 align-middle") { div(class="overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg") { table(class="min-w-full divide-y divide-gray-600") { thead(class="bg-gray-800") { tr { (View::new_fragment(props.headers.iter().cloned().map(|header| view! { cx, th( scope="col", class="px-3 py-3.5 text-left text-sm font-semibold text-gray-400" ) { (header) } }).collect())) } } tbody(class="divide-y divide-gray-600 bg-gray-700") { (children) } } } } } } #[derive(Prop)] pub struct BlockProps<'a, G: Html> { title: String, children: Children<'a, G>, } #[component] pub fn Block<'a, G: Html>(cx: Scope<'a>, props: BlockProps<'a, G>) -> View { let children = props.children.call(cx); let open = create_signal(cx, false); let class = create_memo(cx, || { if *open.get() { "overflow-hidden" } else { "overflow-hidden max-h-1" } }); view! { cx, div(class="px-3 py-3 rounded-lg border-solid border-gray-800 border-2 my-3") { p(class="cursor-pointer text-lg",on:click=move |_| open.set(!*open.get())) { (props.title) } div(class=class) { br {} div { (children) } } } } } /* #[function_component(Loading)] pub fn loading() -> Html { html! { } } */