nova_forms/components/
nova_form_wrapper.rs

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