Work on the TextEntry component

This commit is contained in:
Savanni D'Gerinel 2025-04-09 00:46:22 -04:00
parent 9ae2325cbe
commit d106cbe1d2
5 changed files with 91 additions and 9 deletions

View File

@ -3,15 +3,6 @@
--spacing-m: 8px;
--spacing-l: 16px;
--shadow-shallow: 2px 2px 1px;
--border-light: 1px solid black;
--radius-s: 4px;
--radius-m: 8px;
--radius-l: 16px;
--background-color: var(--grey-2);
--grey-1: hsl(0, 0%, 95%);
--grey-2: hsl(0, 0%, 85%);
--grey-3: hsl(0, 0%, 60%);
@ -36,6 +27,17 @@
--red-4: hsl(0, 75%, 35%);
--red-5: hsl(0, 75%, 25%);
--shadow-shallow: 2px 2px 1px;
--border-light: 1px solid var(--grey-3);
--border-activated: 2px solid var(--blue-3);
--radius-s: 4px;
--radius-m: 8px;
--radius-l: 16px;
--background-color: var(--grey-2);
--text-normal: var(--grey-5);
--text-light: var(--grey-3);
--text-inverse: var(--grey-1);
@ -200,3 +202,16 @@ body {
margin: var(--spacing-s);
}
.text-entry {
padding: var(--spacing-m);
padding-left: var(--spacing-l);
padding-right: var(--spacing-l);
border: var(--border-light);
border-radius: var(--radius-l);
background-color: var(--highlight-background);
}
.text-entry__placeholder {
color: var(--text-light);
}

View File

@ -9,3 +9,6 @@ pub use row::Row;
mod swatch;
pub use swatch::Swatch;
mod text_entry;
pub use text_entry::TextEntry;

View File

@ -0,0 +1,33 @@
use wasm_bindgen::JsCast;
use web_sys::HtmlInputElement;
use yew::{function_component, html, use_node_ref, use_state, AttrValue, Callback, Event, Html, Properties};
#[derive(Properties, PartialEq)]
pub struct TextEntryProps {
#[prop_or(AttrValue::from(""))]
pub value: AttrValue,
#[prop_or(AttrValue::from("placeholder"))]
pub placeholder: AttrValue,
#[prop_or(None)]
pub on_changed: Option<Callback<String>>,
}
#[function_component]
pub fn TextEntry(TextEntryProps { value, placeholder, on_changed }: &TextEntryProps) -> Html {
let on_changed_ = {
let on_changed = on_changed.clone();
Callback::from(move |event: Event| {
let input = event.target().and_then(|t| t.dyn_into::<HtmlInputElement>().ok());
if let Some(input) = input {
if let Some(ref on_changed) = on_changed {
on_changed.emit(input.value());
}
}
})
};
html! {
<input class="text-entry" type="text" placeholder={placeholder} onchange={on_changed_} value={value} />
}
}

View File

@ -48,6 +48,11 @@ pub fn Design(DesignProps { }: &DesignProps) -> Html {
<Label text="editable label" placeholder="empty" editable=true />
</Row>
<Row>
<TextEntry placeholder="username" />
<TextEntry value="vakarian" placeholder="username" />
</Row>
<Row>
<Card title="Card Title">
<p>{"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."}</p>

View File

@ -2,6 +2,8 @@ use wasm_bindgen::JsCast;
use web_sys::HtmlInputElement;
use yew::{function_component, html, use_state, Callback, Event, Html, Properties};
use crate::components::TextEntry;
#[derive(Properties, PartialEq)]
pub struct LoginProps {
pub on_login: Callback<(String, String)>,
@ -19,6 +21,17 @@ pub fn Login(LoginProps { on_login }: &LoginProps) -> Html {
Callback::from(move |_| on_login.emit((username.to_string(), password.to_string())))
};
let on_username_changed = {
let username = username.clone();
Callback::from(move |text: String| username.set(text))
};
let on_password_changed = {
let username = username.clone();
Callback::from(move |text: String| username.set(text))
};
/*
let on_username_changed = {
let username = username.clone();
Callback::from(move |event: Event| {
@ -42,7 +55,9 @@ pub fn Login(LoginProps { on_login }: &LoginProps) -> Html {
}
})
};
*/
/*
html! {
<div class="login-form">
<div class="card">
@ -53,6 +68,17 @@ pub fn Login(LoginProps { on_login }: &LoginProps) -> Html {
</div>
</div>
}
*/
html! {
<div class="login-form">
<div class="card">
<h1>{"Welcome to Visions VTT"}</h1>
<TextEntry placeholder="username" on_changed={on_username_changed} />
<TextEntry placeholder="password" on_changed={on_password_changed} />
<button onclick={on_click}>{"Login"}</button>
</div>
</div>
}
}