From 10152a2fc2b3de942b9f08d81c81d6566003d336 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 2 Oct 2025 13:16:37 +0200 Subject: feat(buy): Add the framework for the /buy page --- src/components/buy.rs | 38 ++++++++++++++++++ src/components/input_placeholder.rs | 77 +++++++++++++++++++++++++++++++++++++ src/components/mod.rs | 2 + src/components/product_overview.rs | 5 ++- 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/components/buy.rs create mode 100644 src/components/input_placeholder.rs (limited to 'src/components') diff --git a/src/components/buy.rs b/src/components/buy.rs new file mode 100644 index 0000000..86e9952 --- /dev/null +++ b/src/components/buy.rs @@ -0,0 +1,38 @@ +use leptos::{ + IntoView, component, + html::Input, + prelude::{ClassAttribute, ElementChild, Get, NodeRef, OnAttribute, Set, signal}, + view, + web_sys::SubmitEvent, +}; + +use crate::components::{input_placeholder::InputPlaceholder, site_header::SiteHeader}; + +#[component] +pub fn Buy() -> impl IntoView { + let (product_barcode, set_product_barcode) = signal(String::new()); + + let input_element: NodeRef = NodeRef::new(); + + let on_submit = move |ev: SubmitEvent| { + // stop the page from reloading! + ev.prevent_default(); + + let value = input_element + .get() + // event handlers can only fire after the view + // is mounted to the DOM, so the `NodeRef` will be `Some` + .expect(" to exist") + .value(); + set_product_barcode.set(value); + }; + + view! { + +
+ + + +

"Name is: " {product_barcode}

+ } +} diff --git a/src/components/input_placeholder.rs b/src/components/input_placeholder.rs new file mode 100644 index 0000000..92f9926 --- /dev/null +++ b/src/components/input_placeholder.rs @@ -0,0 +1,77 @@ +use leptos::{ + IntoView, component, + html::Input, + prelude::{ClassAttribute, ElementChild, GlobalAttributes, NodeRef, NodeRefAttribute}, + view, +}; +use uuid::Uuid; + +#[component] +pub fn InputPlaceholder( + input_type: &'static str, + label: &'static str, + node_ref: NodeRef, + #[prop(default = None)] initial_value: Option, +) -> impl IntoView { + let id = Uuid::new_v4(); + + view! { +
+ + + // TODO: Reference `var(--tw-border-2)` instead of the `2 px` <2025-10-01> +
+ + +
+ } +} diff --git a/src/components/mod.rs b/src/components/mod.rs index 7174ad8..55e4397 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -2,8 +2,10 @@ pub mod async_fetch; pub mod container; pub mod icon_p; +pub mod input_placeholder; // Specific +pub mod buy; pub mod inventory; pub mod product_overview; pub mod recipies; diff --git a/src/components/product_overview.rs b/src/components/product_overview.rs index ae2eaf2..d86c04d 100644 --- a/src/components/product_overview.rs +++ b/src/components/product_overview.rs @@ -11,7 +11,10 @@ pub fn ProductOverview() -> impl IntoView { }, "inventory"), + ( + view! { }, + "inventory", + ), (view! { }, "consume"), (view! { }, "buy"), ] -- cgit 1.4.1