From 1f03a04a23ffe7e163db84c3c178b7e21a8c313a Mon Sep 17 00:00:00 2001 From: Philip Peterson Date: Sat, 20 Nov 2021 14:43:30 -0500 Subject: [PATCH] Replace `crm` example with `password strength` to show controlled components (#1706) * Remove crm example * Add password_strength example * Update README * Remove .DS_Store * Update README * Cargo fmt * Apply suggestions from code review * Update list of examples * update the pr to work with latest master * fix readme * add newline Co-authored-by: Simon Co-authored-by: Julius Lungys <32368314+voidpumpkin@users.noreply.github.com> --- Cargo.toml | 2 +- examples/README.md | 50 ++++---- examples/crm/Cargo.toml | 19 --- examples/crm/README.md | 28 ----- examples/crm/index.html | 9 -- examples/crm/src/add_client.rs | 109 ----------------- examples/crm/src/main.rs | 120 ------------------- examples/password_strength/Cargo.toml | 14 +++ examples/password_strength/README.md | 21 ++++ examples/password_strength/index.html | 11 ++ examples/password_strength/index.scss | 52 ++++++++ examples/password_strength/src/app.rs | 86 +++++++++++++ examples/password_strength/src/main.rs | 12 ++ examples/password_strength/src/password.rs | 27 +++++ examples/password_strength/src/text_input.rs | 34 ++++++ 15 files changed, 283 insertions(+), 311 deletions(-) delete mode 100644 examples/crm/Cargo.toml delete mode 100644 examples/crm/README.md delete mode 100644 examples/crm/index.html delete mode 100644 examples/crm/src/add_client.rs delete mode 100644 examples/crm/src/main.rs create mode 100644 examples/password_strength/Cargo.toml create mode 100644 examples/password_strength/README.md create mode 100644 examples/password_strength/index.html create mode 100644 examples/password_strength/index.scss create mode 100644 examples/password_strength/src/app.rs create mode 100644 examples/password_strength/src/main.rs create mode 100644 examples/password_strength/src/password.rs create mode 100644 examples/password_strength/src/text_input.rs diff --git a/Cargo.toml b/Cargo.toml index 402b7fef213..2bab65a51a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ members = [ # Examples "examples/boids", "examples/counter", - "examples/crm", "examples/dyn_create_destroy_apps", "examples/file_upload", "examples/function_todomvc", @@ -25,6 +24,7 @@ members = [ "examples/multi_thread", "examples/nested_list", "examples/node_refs", + "examples/password_strength", "examples/portals", "examples/pub_sub", "examples/router", diff --git a/examples/README.md b/examples/README.md index 4789e7da3b9..8f533f61dfa 100644 --- a/examples/README.md +++ b/examples/README.md @@ -26,34 +26,34 @@ As an example, check out the TodoMVC example here: "] -edition = "2018" -license = "MIT OR Apache-2.0" - -[dependencies] -serde = "1" -serde_derive = "1" -yew = { path = "../../packages/yew" } -gloo = "0.4" - -[dependencies.web-sys] -version = "0.3" -features = [ - "HtmlInputElement", - "HtmlTextAreaElement", -] diff --git a/examples/crm/README.md b/examples/crm/README.md deleted file mode 100644 index bb0f9f0ef72..00000000000 --- a/examples/crm/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# CRM Example - -[![Demo](https://img.shields.io/website?label=demo&url=https%3A%2F%2Fexamples.yew.rs%2Fcrm)](https://examples.yew.rs/crm) - -A very shallow customer relationship management tool. -It consists of a list of clients with an associated name and description. -It's possible to create new clients and clear the list entirely. - -## Concepts - -This example features multiple views ("scenes") which the user can switch between. - -For a much more sophisticated approach check out [`yew-router`](https://yew.rs/concepts/router/). -One major flaw with the implementation used by this example is that the scenes aren't tied to the URL. -Reloading the page always brings the user back to the initial scene. - -The example also uses the [`gloo::storage`](https://gloo-rs.web.app/docs/storage) -to persist the clients across sessions. - -## Improvements - -- Improve the presentation of the example with CSS. - -### Features - -- Edit a client -- Remove individual clients from the list -- Pagination diff --git a/examples/crm/index.html b/examples/crm/index.html deleted file mode 100644 index f61332518e7..00000000000 --- a/examples/crm/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - Yew • CRM - - - - diff --git a/examples/crm/src/add_client.rs b/examples/crm/src/add_client.rs deleted file mode 100644 index 1d6c0e12065..00000000000 --- a/examples/crm/src/add_client.rs +++ /dev/null @@ -1,109 +0,0 @@ -use crate::Client; -use web_sys::{HtmlInputElement, HtmlTextAreaElement}; -use yew::{ - classes, events::Event, html, Callback, Component, Context, Html, Properties, TargetCast, -}; - -#[derive(Debug)] -pub enum Msg { - UpdateFirstName(String), - UpdateLastName(String), - UpdateDescription(String), - Add, - Abort, -} - -#[derive(Clone, Debug, PartialEq, Properties)] -pub struct Props { - pub on_add: Callback, - pub on_abort: Callback<()>, -} - -pub struct AddClientForm { - client: Client, -} -impl Component for AddClientForm { - type Message = Msg; - type Properties = Props; - - fn create(_ctx: &Context) -> Self { - Self { - client: Client::default(), - } - } - - fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool { - let client = &mut self.client; - match msg { - Msg::UpdateFirstName(value) => { - client.first_name = value; - true - } - Msg::UpdateLastName(value) => { - client.last_name = value; - true - } - Msg::UpdateDescription(value) => { - client.description = value; - true - } - Msg::Add => { - ctx.props().on_add.emit(std::mem::take(client)); - true - } - Msg::Abort => { - ctx.props().on_abort.emit(()); - false - } - } - } - - fn view(&self, ctx: &Context) -> Html { - let link = ctx.link(); - let Self { client, .. } = self; - - let update_name = |f: fn(String) -> Msg| { - link.callback(move |e: Event| { - let input: HtmlInputElement = e.target_unchecked_into(); - f(input.value()) - }) - }; - - let update_desc = link.callback(|e: Event| { - let textarea: HtmlTextAreaElement = e.target_unchecked_into(); - Msg::UpdateDescription(textarea.value()) - }); - - html! { - <> -
- - -