From be7614df9d2ca0ba7cd7cf700c82f155d1627eb2 Mon Sep 17 00:00:00 2001 From: Yohan Boogaert Date: Mon, 21 Sep 2020 18:59:46 +0200 Subject: [PATCH] Split doc (#6) * i have split the doc about collapse * splited the doc about Switch * splited doc about icon * splited the doc about buttons --- src/app.rs | 76 +++++++------------------------------------ src/buttons.rs | 45 +++++++++++++++++++++++++ src/collapse.rs | 70 +++++++++++++++++++++++++++++++++++++++ src/forms/controls.rs | 44 +++++++++++++++++++++++++ src/icon.rs | 29 +++++++++++++++++ 5 files changed, 200 insertions(+), 64 deletions(-) diff --git a/src/app.rs b/src/app.rs index 3fbf4b9..dc2b587 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,7 +1,7 @@ -use crate::buttons::Button; -use crate::collapse::Collapse; -use crate::forms::controls::Switch; -use crate::icon::*; +use crate::buttons::doc::*; +use crate::collapse::doc::*; +use crate::forms::controls::doc::SwitchDoc; +use crate::icon::doc::*; use crate::menu::*; use crate::tree::doc::*; use yew::prelude::*; @@ -13,16 +13,12 @@ const LIGHT_FG_COLOR: &str = "#182026"; pub struct App { link: ComponentLink, - counter: i64, - dark_theme: bool, - collapsed: bool, doc_menu: DocMenu, + dark_theme: bool, } pub enum Msg { - AddOne, ToggleLight, - ToggleCollapse, GoToMenu(DocMenu), } @@ -32,9 +28,7 @@ impl Component for App { fn create(_: Self::Properties, link: ComponentLink) -> Self { App { - counter: 0, dark_theme: true, - collapsed: true, doc_menu: DocMenu::Tree, link, } @@ -42,9 +36,7 @@ impl Component for App { fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { - Msg::AddOne => self.counter += 1, Msg::ToggleLight => self.dark_theme ^= true, - Msg::ToggleCollapse => self.collapsed ^= true, Msg::GoToMenu(doc_menu) => { self.doc_menu = doc_menu; } @@ -82,58 +74,14 @@ impl Component for App { { match self.doc_menu { - DocMenu::Button => html! { -
-

{"Counter: "} { self.counter }

-
- -
-
- }, - DocMenu::Switch => html! { -
- -
- }, - DocMenu::Collapse => html! { -
- - -
-                                        
{"[INFO]: Installing wasm-bindgen..."}
-
{"[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended"}
-
{"[INFO]: :-) Done in 0.69s"}
-
{"[INFO]: :-) Your wasm pkg is ready to publish at /home/cecile/repos/blueprint-rs/./static."}
-
{" Index: enabled, Upload: disabled, Cache: disabled, Cors: enabled, Range: enabled, Sort: enabled, Threads: 3"}
-
{" Auth: disabled, Compression: disabled"}
-
{" https: disabled, Cert: , Cert-Password: "}
-
{" Root: /home/cecile/repos/blueprint-rs,"}
-
{" TryFile404: "}
-
{" Address: http://0.0.0.0:8000"}
-
{" ======== [2020-09-07 20:39:46] ========"}
-
{"[2020-09-07 20:39:46] - 127.0.0.1 - 200 - GET /"}
-
{"[2020-09-07 20:39:46] - 127.0.0.1 - 200 - GET /static/blueprint.css"}
-
{"[2020-09-07 20:39:46] - 127.0.0.1 - 200 - GET /static/wasm.js"}
-
{"[2020-09-07 20:39:46] - 127.0.0.1 - 200 - GET /static/wasm_bg.wasm"}
-
-
-
- }, + DocMenu::Button => html! (), + DocMenu::Switch => html! (), + DocMenu::Collapse => html!(), DocMenu::Tree => html!(), - DocMenu::Icon => html! { -
- -
- }, + DocMenu::Icon => html!(), DocMenu::Menu => html!(), } } diff --git a/src/buttons.rs b/src/buttons.rs index 6321666..5f53c17 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -42,3 +42,48 @@ impl Component for Button { } } } + +#[cfg(feature = "dev")] +pub mod doc { + use super::*; + + pub struct ButtonDoc { + link: ComponentLink, + counter: i64, + } + + pub enum Msg { + AddOne, + } + + impl Component for ButtonDoc { + type Message = Msg; + type Properties = (); + + fn create(_: Self::Properties, link: ComponentLink) -> Self { + ButtonDoc { counter: 0, link } + } + + fn update(&mut self, msg: Self::Message) -> ShouldRender { + match msg { + Msg::AddOne => self.counter += 1, + } + true + } + + fn change(&mut self, _props: Self::Properties) -> ShouldRender { + true + } + + fn view(&self) -> Html { + html! { +
+

{"Counter: "} { self.counter }

+
+ +
+
+ } + } + } +} diff --git a/src/collapse.rs b/src/collapse.rs index 9c7726a..e4e7784 100644 --- a/src/collapse.rs +++ b/src/collapse.rs @@ -196,3 +196,73 @@ impl Component for Collapse { } } } + +#[cfg(feature = "dev")] +pub mod doc { + use super::*; + use crate::buttons::Button; + + pub struct CollapseDoc { + link: ComponentLink, + collapsed: bool, + } + + pub enum Msg { + ToggleCollapse, + } + + impl Component for CollapseDoc { + type Message = Msg; + type Properties = (); + + fn create(_: Self::Properties, link: ComponentLink) -> Self { + CollapseDoc { + collapsed: true, + link, + } + } + + fn update(&mut self, msg: Self::Message) -> ShouldRender { + match msg { + Msg::ToggleCollapse => self.collapsed ^= true, + } + true + } + + fn change(&mut self, _props: Self::Properties) -> ShouldRender { + true + } + + fn view(&self) -> Html { + html! { +
+ + +
+                            
{"[INFO]: Installing wasm-bindgen..."}
+
{"[INFO]: Optional fields missing from Cargo.toml: 'description', 'repository', and 'license'. These are not necessary, but recommended"}
+
{"[INFO]: :-) Done in 0.69s"}
+
{"[INFO]: :-) Your wasm pkg is ready to publish at /home/cecile/repos/blueprint-rs/./static."}
+
{" Index: enabled, Upload: disabled, Cache: disabled, Cors: enabled, Range: enabled, Sort: enabled, Threads: 3"}
+
{" Auth: disabled, Compression: disabled"}
+
{" https: disabled, Cert: , Cert-Password: "}
+
{" Root: /home/cecile/repos/blueprint-rs,"}
+
{" TryFile404: "}
+
{" Address: http://0.0.0.0:8000"}
+
{" ======== [2020-09-07 20:39:46] ========"}
+
{"[2020-09-07 20:39:46] - 127.0.0.1 - 200 - GET /"}
+
{"[2020-09-07 20:39:46] - 127.0.0.1 - 200 - GET /static/blueprint.css"}
+
{"[2020-09-07 20:39:46] - 127.0.0.1 - 200 - GET /static/wasm.js"}
+
{"[2020-09-07 20:39:46] - 127.0.0.1 - 200 - GET /static/wasm_bg.wasm"}
+
+
+
+ } + } + } +} diff --git a/src/forms/controls.rs b/src/forms/controls.rs index f9ef6bf..af6409c 100644 --- a/src/forms/controls.rs +++ b/src/forms/controls.rs @@ -52,3 +52,47 @@ impl Component for Switch { } } } + +#[cfg(feature = "dev")] +pub mod doc { + use super::*; + + pub struct SwitchDoc { + props: Props, + } + + #[derive(Clone, PartialEq, Properties)] + pub struct Props { + pub dark_theme: bool, + pub onclick: Callback, + } + + impl Component for SwitchDoc { + type Message = (); + type Properties = Props; + + fn create(props: Self::Properties, _link: ComponentLink) -> Self { + SwitchDoc { props } + } + + fn update(&mut self, _msg: Self::Message) -> ShouldRender { + true + } + + fn change(&mut self, _props: Self::Properties) -> ShouldRender { + true + } + + fn view(&self) -> Html { + html! { +
+ +
+ } + } + } +} diff --git a/src/icon.rs b/src/icon.rs index 16aac18..b4cf9e6 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -93,3 +93,32 @@ impl Component for Icon { } } } + +#[cfg(feature = "dev")] +pub mod doc { + use super::*; + + pub struct IconDoc {} + + impl Component for IconDoc { + type Message = (); + type Properties = (); + + fn create(_: Self::Properties, _link: ComponentLink) -> Self { + IconDoc {} + } + fn update(&mut self, _msg: Self::Message) -> ShouldRender { + true + } + fn change(&mut self, _props: Self::Properties) -> ShouldRender { + true + } + fn view(&self) -> Html { + html! { +
+ +
+ } + } + } +}