nova_forms/components/
nova_form_wrapper.rs

1use leptos::*;
2use leptos_meta::*;
3
4use crate::AppContext;
5
6/// A container for a form.
7/// Adds a header with a logo, title, and subtitle, as well as a footer with the title.
8#[component]
9pub fn NovaFormWrapper(
10    /// The URL of the logo to display in the header.
11    #[prop(into)] logo: String,
12    /// The title to display in the header and footer.
13    #[prop(into)] title: TextProp,
14    /// The subtitle to display in the header.
15    #[prop(into, optional)] subtitle: Option<TextProp>,
16    /// The footer to display at the bottom of the form.
17    /// By default, there is no footer.
18    #[prop(into, optional)] footer: Option<Children>,
19    /// The nova form goes here.
20    children: Children,
21) -> impl IntoView {
22    let base_context = expect_context::<AppContext>();
23
24    view! {
25        <Title text={title.clone()} />
26
27        <header>
28            <div class="content">  
29                <img id="logo" src=base_context.resolve_path(logo) />
30                <div id="name">
31                    <span id="title">{title.clone()}</span>
32                    {if let Some(subtitle) = subtitle {
33                        view! { 
34                            <br />
35                            <span id="subtitle">{subtitle}</span>
36                        }.into_view()
37                    } else {
38                        View::default()
39                    }}
40                </div>
41            </div>
42        </header>
43        <main>
44            <div class="content">
45                {children()}
46            </div>
47        </main>
48        {
49            if let Some(footer) = footer {
50                view! { 
51                    <footer>
52                        <div class="content">
53                            <span>{footer()}</span>
54                        </div>
55                    </footer>
56                }.into_view()
57            } else {
58                View::default()
59            }
60        }
61        
62    }
63}