From f59928fdb20b3ed2c63e78fd6f3bc4e7be929569 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Wed, 8 Nov 2023 11:02:38 +0800 Subject: [PATCH 1/3] feat: add guide --- demo/Cargo.toml | 1 + demo/gh-pages | 1 - demo/src/app.rs | 4 ++ demo/src/components/site_header.rs | 23 ++++++- demo/src/pages/guide/installation.rs | 22 +++++++ demo/src/pages/guide/mod.rs | 97 ++++++++++++++++++++++++++++ demo/src/pages/guide/usage.rs | 58 +++++++++++++++++ demo/src/pages/home.rs | 2 +- demo/src/pages/mod.rs | 2 + 9 files changed, 206 insertions(+), 4 deletions(-) delete mode 160000 demo/gh-pages create mode 100644 demo/src/pages/guide/installation.rs create mode 100644 demo/src/pages/guide/mod.rs create mode 100644 demo/src/pages/guide/usage.rs diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 26db529..fcdca8e 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -12,6 +12,7 @@ thaw = { path = "../" } icondata = { version = "0.1.0", features = [ "AiCloseOutlined", "AiCheckOutlined", + "AiGithubOutlined", ] } leptos_router = { version = "0.5.1", features = ["csr"] } leptos_devtools = "0.0.1" diff --git a/demo/gh-pages b/demo/gh-pages deleted file mode 160000 index faaa4df..0000000 --- a/demo/gh-pages +++ /dev/null @@ -1 +0,0 @@ -Subproject commit faaa4dfa5547b4c3e117999f4ed4cf2332006f2b diff --git a/demo/src/app.rs b/demo/src/app.rs index c61b815..f33f870 100644 --- a/demo/src/app.rs +++ b/demo/src/app.rs @@ -43,6 +43,10 @@ fn TheRouter() -> impl IntoView { + + + + diff --git a/demo/src/components/site_header.rs b/demo/src/components/site_header.rs index 7fbfa76..b42388d 100644 --- a/demo/src/components/site_header.rs +++ b/demo/src/components/site_header.rs @@ -42,6 +42,24 @@ pub fn SiteHeader() -> impl IntoView { + + diff --git a/demo/src/pages/guide/installation.rs b/demo/src/pages/guide/installation.rs new file mode 100644 index 0000000..d202b36 --- /dev/null +++ b/demo/src/pages/guide/installation.rs @@ -0,0 +1,22 @@ +use crate::components::{Demo, DemoCode}; +use leptos::*; + +#[component] +pub fn InstallationPage() -> impl IntoView { + view! { +
+

"Installation"

+

"Installation thaw"

+ + "" + + + "" + + +
+ } +} diff --git a/demo/src/pages/guide/mod.rs b/demo/src/pages/guide/mod.rs new file mode 100644 index 0000000..d5d90e3 --- /dev/null +++ b/demo/src/pages/guide/mod.rs @@ -0,0 +1,97 @@ +mod installation; +mod usage; + +use crate::components::SiteHeader; +pub use installation::*; +use leptos::*; +use leptos_router::{use_location, use_navigate, Outlet}; +use thaw::*; +pub use usage::*; + +#[component] +pub fn GuidePage() -> impl IntoView { + let navigate = use_navigate(); + let selected = create_rw_signal({ + let loaction = use_location(); + let mut pathname = loaction.pathname.get_untracked(); + + if pathname.starts_with("/thaw/guide/") { + pathname.drain(12..).collect() + } else { + String::new() + } + }); + + create_effect(move |value| { + let selected = selected.get(); + if value.is_some() { + navigate(&format!("/guide/{selected}"), Default::default()); + } + selected + }); + view! { + + + + + + { + gen_menu_data().into_view() + } + + + + + + + + } +} + +struct MenuGroupOption { + label: String, + children: Vec, +} + +impl IntoView for MenuGroupOption { + fn into_view(self) -> View { + let Self { label, children } = self; + view! { + + { + children.into_iter().map(|v| v.into_view()).collect_view() + } + + } + } +} + +struct MenuItemOption { + label: String, + value: String, +} + +impl IntoView for MenuItemOption { + fn into_view(self) -> View { + let Self { label, value } = self; + view! { + + } + } +} + +fn gen_menu_data() -> Vec { + vec![MenuGroupOption { + label: "Getting Started".into(), + children: vec![ + MenuItemOption { + value: "installation".into(), + label: "Installation".into(), + }, + MenuItemOption { + value: "usage".into(), + label: "Usage".into(), + }, + ], + }] +} diff --git a/demo/src/pages/guide/usage.rs b/demo/src/pages/guide/usage.rs new file mode 100644 index 0000000..3b54ddf --- /dev/null +++ b/demo/src/pages/guide/usage.rs @@ -0,0 +1,58 @@ +use crate::components::{Demo, DemoCode}; +use leptos::*; +use prisms::highlight_str; + +#[component] +pub fn UsagePage() -> impl IntoView { + view! { +
+

"Usage"

+

"You just need to import thaw and use it."

+ + "" + + + "" + + +

"A small example:"

+ + "" + impl IntoView { + view! { + + } + } + "#, + "rust" + ) + > + + "" + + +
+ } +} diff --git a/demo/src/pages/home.rs b/demo/src/pages/home.rs index 010510d..5bc7575 100644 --- a/demo/src/pages/home.rs +++ b/demo/src/pages/home.rs @@ -20,7 +20,7 @@ pub fn Home() -> impl IntoView {