feat(components): build item form component
This commit is contained in:
parent
02a888be57
commit
b692c12e7e
1 changed files with 23 additions and 0 deletions
23
src/components/item_form.rs
Normal file
23
src/components/item_form.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use leptos::*;
|
||||
|
||||
#[component]
|
||||
pub fn ItemForm(cx: Scope, on_submit: Box<dyn Fn(String, String, Vec<(String, String)>)>) -> impl IntoView {
|
||||
let name = create_signal(cx, String::new());
|
||||
let description = create_signal(cx, String::new());
|
||||
let tags = create_signal(cx, vec![]);
|
||||
|
||||
let handle_submit = move |_| {
|
||||
on_submit(name.get().clone(), description.get().clone(), tags.get().clone());
|
||||
name.set(String::new());
|
||||
description.set(String::new());
|
||||
tags.set(vec![]);
|
||||
};
|
||||
|
||||
view! { cx,
|
||||
<form on:submit=handle_submit>
|
||||
<input type="text" placeholder="Name" value=name.clone() on:input=move |e| name.set(event_target_value(&e)) />
|
||||
<textarea placeholder="Description" value=description.clone() on:input=move |e| description.set(event_target_value(&e)) />
|
||||
<button type="submit">{ "Add Item" }</button>
|
||||
</form>
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue