leptos-template
This commit is contained in:
15
src/components/counter_btn.rs
Normal file
15
src/components/counter_btn.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use leptos::prelude::*;
|
||||
|
||||
/// A parameterized incrementing button
|
||||
#[component]
|
||||
pub fn Button(#[prop(default = 1)] increment: i32) -> impl IntoView {
|
||||
let (count, set_count) = signal(0);
|
||||
view! {
|
||||
<button on:click=move |_| {
|
||||
set_count.set(count.get() + increment)
|
||||
}>
|
||||
|
||||
"Click me: " {count}
|
||||
</button>
|
||||
}
|
||||
}
|
||||
1
src/components/mod.rs
Normal file
1
src/components/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod counter_btn;
|
||||
34
src/lib.rs
Normal file
34
src/lib.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use leptos::prelude::*;
|
||||
use leptos_meta::*;
|
||||
use leptos_router::{components::*, path};
|
||||
|
||||
// Modules
|
||||
mod components;
|
||||
mod pages;
|
||||
|
||||
// Top-Level pages
|
||||
use crate::pages::home::Home;
|
||||
|
||||
/// An app router which renders the homepage and handles 404's
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
// Provides context that manages stylesheets, titles, meta tags, etc.
|
||||
provide_meta_context();
|
||||
|
||||
view! {
|
||||
<Html attr:lang="en" attr:dir="ltr" attr:data-theme="light" />
|
||||
|
||||
// sets the document title
|
||||
<Title text="Welcome to Leptos CSR" />
|
||||
|
||||
// injects metadata in the <head> of the page
|
||||
<Meta charset="UTF-8" />
|
||||
<Meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<Router>
|
||||
<Routes fallback=|| view! { NotFound }>
|
||||
<Route path=path!("/") view=Home />
|
||||
</Routes>
|
||||
</Router>
|
||||
}
|
||||
}
|
||||
14
src/main.rs
Normal file
14
src/main.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use leptos::prelude::*;
|
||||
use py_leptos::App;
|
||||
|
||||
fn main() {
|
||||
// set up logging
|
||||
_ = console_log::init_with_level(log::Level::Debug);
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
mount_to_body(|| {
|
||||
view! {
|
||||
<App />
|
||||
}
|
||||
})
|
||||
}
|
||||
52
src/pages/home.rs
Normal file
52
src/pages/home.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use crate::components::counter_btn::Button;
|
||||
use leptos::prelude::*;
|
||||
|
||||
/// Default Home Page
|
||||
#[component]
|
||||
pub fn Home() -> impl IntoView {
|
||||
view! {
|
||||
<ErrorBoundary fallback=|errors| {
|
||||
view! {
|
||||
<h1>"Uh oh! Something went wrong!"</h1>
|
||||
|
||||
<p>"Errors: "</p>
|
||||
// Render a list of errors as strings - good for development purposes
|
||||
<ul>
|
||||
{move || {
|
||||
errors
|
||||
.get()
|
||||
.into_iter()
|
||||
.map(|(_, e)| view! { <li>{e.to_string()}</li> })
|
||||
.collect_view()
|
||||
}}
|
||||
|
||||
</ul>
|
||||
}
|
||||
}>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<picture>
|
||||
<source
|
||||
srcset="https://raw.githubusercontent.com/leptos-rs/leptos/main/docs/logos/Leptos_logo_pref_dark_RGB.svg"
|
||||
media="(prefers-color-scheme: dark)"
|
||||
/>
|
||||
<img
|
||||
src="https://raw.githubusercontent.com/leptos-rs/leptos/main/docs/logos/Leptos_logo_RGB.svg"
|
||||
alt="Leptos Logo"
|
||||
height="200"
|
||||
width="400"
|
||||
/>
|
||||
</picture>
|
||||
|
||||
<h1>"Welcome to Leptos"</h1>
|
||||
|
||||
<div class="buttons">
|
||||
<Button />
|
||||
<Button increment=5 />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</ErrorBoundary>
|
||||
}
|
||||
}
|
||||
2
src/pages/mod.rs
Normal file
2
src/pages/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod home;
|
||||
pub mod not_found;
|
||||
7
src/pages/not_found.rs
Normal file
7
src/pages/not_found.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use leptos::prelude::*;
|
||||
|
||||
/// 404 Not Found Page
|
||||
#[component]
|
||||
pub fn NotFound() -> impl IntoView {
|
||||
view! { <h1>"Uh oh!" <br /> "We couldn't find that page!"</h1> }
|
||||
}
|
||||
Reference in New Issue
Block a user