summary refs log tree commit diff stats
path: root/src/components/container.rs
blob: 7a4a64f39a475b6163314e392b4189fe86ffd1ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use leptos::{
    IntoView, component,
    prelude::{Children, ClassAttribute, ElementChild, OnAttribute},
    view,
};
use leptos_router::{NavigateOptions, hooks::use_navigate};

#[component]
pub fn Container(
    header: impl IntoView,
    buttons: Vec<(impl IntoView, &'static str)>,
    children: Children,
) -> impl IntoView {
    view! {
        <div class="p-4 mt-4 mr-4 ml-4 md-2 rounded-lg border-gray-600 border">
            <p class="text-lg text-bold">{header}</p>
            {children()}

            <ul class="flex flex-row gap-1 pt-2 overflow-x-auto">
                {buttons
                    .into_iter()
                    .map(|(name, path)| {
                        view! {
                            <li class="bg-green-400/40 p-2 first:rounded-l-full last:rounded-r-full">
                                <button on:click=move |_| {
                                    use_navigate()(path, NavigateOptions::default());
                                }>{name}</button>
                            </li>
                        }
                    })
                    .collect::<Vec<_>>()}
            </ul>
        </div>
    }
}