create component library for shared components

This commit is contained in:
Liam Fitzpatrick 2024-12-13 08:17:06 -05:00
parent 80ff760388
commit 840829e47a
5 changed files with 36 additions and 0 deletions

15
leptos_components/.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
node_modules/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

View File

@ -0,0 +1,7 @@
[package]
name = "leptos_components"
version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { version = "0.7.0", features = ["csr", "ssr", "hydrate"] }

View File

@ -0,0 +1,11 @@
use leptos::prelude::*;
#[component]
pub fn Button(
children: Children,
) -> impl IntoView {
view! {
<button>{children()}</button>
}
}

View File

@ -19,6 +19,7 @@ tower-http = { version = "0.5", features = ["fs"], optional = true }
wasm-bindgen = "=0.2.99"
thiserror = "1"
http = "1"
leptos_components = {path="../leptos_components"}
[features]
hydrate = ["leptos/hydrate"]

View File

@ -4,6 +4,7 @@ use leptos_router::{
components::{Route, Router, Routes},
StaticSegment,
};
use leptos_components::Button;
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
@ -57,5 +58,6 @@ fn HomePage() -> impl IntoView {
view! {
<h1>"Welcome to Leptos!"</h1>
<button on:click=on_click>"Click Me: " {count}</button>
<Button on:click=on_click>"Click Me: " {count}</Button>
}
}