summary refs log tree commit diff stats
path: root/src/components/container.rs
blob: d6d2f03779267c780c41029cf4ae20cde652e558 (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
36
37
38
39
40
41
42
43
44
45
46
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 {
    assert!(!buttons.is_empty());

    let first_button_path = buttons.first().expect("Should have at least on button").1;

    view! {
        <button
            type="button"
            on:click=|_| {
                use_navigate()(first_button_path, NavigateOptions::default());
            }
        >
            <div class="p-4 mt-4 mr-4 ml-4 md-2 text-justify 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 text-nowrap first:rounded-l-full last:rounded-r-full">
                                    <button on:click=move |_| {
                                        use_navigate()(path, NavigateOptions::default());
                                    }>{name}</button>
                                </li>
                            }
                        })
                        .collect::<Vec<_>>()}
                </ul>
            </div>
        </button>
    }
}