From 5a77c874cd02d1b7a5f56c76b4225e553faae8f5 Mon Sep 17 00:00:00 2001 From: luoxiaozero <48741584+luoxiaozero@users.noreply.github.com> Date: Fri, 16 Aug 2024 23:09:09 +0800 Subject: [PATCH] Feat/demo site (#232) * fix: demo site error * fix: SwitchVersion label * fix: BackTop demo scrollbar --- demo/src/components/demo.css | 1 - demo/src/components/demo.rs | 67 +++++++++++++++++------- demo/src/components/switch_version.rs | 8 ++- demo/src/pages/components.rs | 8 +-- demo_markdown/src/markdown/code_block.rs | 6 ++- thaw/src/back_top/docs/mod.md | 6 +-- thaw/src/combobox/combobox.rs | 1 + 7 files changed, 67 insertions(+), 30 deletions(-) diff --git a/demo/src/components/demo.css b/demo/src/components/demo.css index ac8befe..521092a 100644 --- a/demo/src/components/demo.css +++ b/demo/src/components/demo.css @@ -34,6 +34,5 @@ font-size: 0.875em; line-height: 1.714; padding: 1rem; - overflow: auto; background-color: var(--demo-background-color); } diff --git a/demo/src/components/demo.rs b/demo/src/components/demo.rs index 7894665..c26cc8a 100644 --- a/demo/src/components/demo.rs +++ b/demo/src/components/demo.rs @@ -1,4 +1,4 @@ -use leptos::prelude::*; +use leptos::{either::Either, prelude::*}; use leptos_meta::Style; use thaw::*; @@ -11,7 +11,11 @@ pub struct DemoCode { } #[component] -pub fn Demo(demo_code: DemoCode, #[prop(optional)] children: Option) -> impl IntoView { +pub fn Demo( + #[prop(optional)] remove_scrollbar: bool, + demo_code: DemoCode, + #[prop(optional)] children: Option, +) -> impl IntoView { let theme = Theme::use_theme(Theme::light); let css_vars = Memo::new(move |_| { let mut css_vars = String::new(); @@ -34,19 +38,37 @@ pub fn Demo(demo_code: DemoCode, #[prop(optional)] children: Option) - let is_highlight = demo_code.is_highlight; let html = demo_code.text; + let styles = use_context::().is_none().then(|| { + view! { + + + } + }); + provide_context(DemoStyle); view! { - - + {styles}
{ if let Some(children) = children { view! { -
{children()}
+ { + if remove_scrollbar { + Either::Left(view! { +
{children()}
+ }) + } else { + Either::Right(view! { + +
{children()}
+
+ }) + } + }
) - None } } -
- { - if is_highlight { - view! { - - } - } else { - view! { - + +
+ { + if is_highlight { + view! { + + } + } else { + view! { + + } } } - } -
+
+
} } + +#[derive(Clone)] +pub struct DemoStyle; diff --git a/demo/src/components/switch_version.rs b/demo/src/components/switch_version.rs index 5781cd3..14b946c 100644 --- a/demo/src/components/switch_version.rs +++ b/demo/src/components/switch_version.rs @@ -14,10 +14,16 @@ pub fn SwitchVersion() -> impl IntoView { ]; let version = RwSignal::new(None::); + let label = RwSignal::new(String::new()); #[cfg(any(feature = "csr", feature = "hydrate"))] { let location = window().location(); let origin = location.origin().ok(); + if let Some(origin) = origin.as_ref() { + if let Some(item) = options.iter().find(|item| item.1 == origin) { + label.set(item.0.to_string()); + } + } version.set(origin); let _ = version.watch(move |origin| { if let Some(origin) = origin { @@ -29,7 +35,7 @@ pub fn SwitchVersion() -> impl IntoView { } view! { - + { options.into_iter().map(|option| view! { diff --git a/demo/src/pages/components.rs b/demo/src/pages/components.rs index 3b51467..f2eba34 100644 --- a/demo/src/pages/components.rs +++ b/demo/src/pages/components.rs @@ -29,10 +29,12 @@ pub fn ComponentsPage() -> impl IntoView { .demo-components__component { width: 896px; margin: 0 auto; + padding: 8px 12px 28px; + box-sizing: border-box; } .demo-components__toc { width: 190px; - margin: 12px 2px 12px 12px; + margin: 12px; } .demo-components__toc > .thaw-anchor { position: sticky; @@ -47,7 +49,7 @@ pub fn ComponentsPage() -> impl IntoView { display: none; } .demo-components__component { - width: 100%; + width: 100vw; } } " @@ -77,7 +79,7 @@ pub fn ComponentsPage() -> impl IntoView { }
- + diff --git a/demo_markdown/src/markdown/code_block.rs b/demo_markdown/src/markdown/code_block.rs index 133a05c..31bdeec 100644 --- a/demo_markdown/src/markdown/code_block.rs +++ b/demo_markdown/src/markdown/code_block.rs @@ -17,7 +17,7 @@ pub fn to_tokens(code_block: &NodeCodeBlock, demos: &mut Vec) -> TokenSt let mut is_highlight = true; let literal = langs .iter() - .find(|lang| lang != &&"demo") + .find(|lang| lang != &&"demo" && lang != &&"remove-scrollbar") .map(|lang| highlight_to_html(&code_block.literal, lang)) .flatten() .unwrap_or_else(|| { @@ -25,8 +25,10 @@ pub fn to_tokens(code_block: &NodeCodeBlock, demos: &mut Vec) -> TokenSt code_block.literal.clone() }); + let remove_scrollbar = langs.iter().any(|lang| lang == &"remove-scrollbar"); + quote! { - + <#demo /> diff --git a/thaw/src/back_top/docs/mod.md b/thaw/src/back_top/docs/mod.md index e82e374..c4bfb5e 100644 --- a/thaw/src/back_top/docs/mod.md +++ b/thaw/src/back_top/docs/mod.md @@ -2,7 +2,7 @@ BackTop will find its first scrollable ascendant element and listen scroll event on it. -```rust demo +```rust demo remove-scrollbar view! { } @@ -10,7 +10,7 @@ view! { ### Visibility height -```rust demo +```rust demo remove-scrollbar view! {
@@ -22,7 +22,7 @@ view! { ### Change position -```rust demo +```rust demo remove-scrollbar view! {
diff --git a/thaw/src/combobox/combobox.rs b/thaw/src/combobox/combobox.rs index ce5d8a7..3f3c328 100644 --- a/thaw/src/combobox/combobox.rs +++ b/thaw/src/combobox/combobox.rs @@ -285,6 +285,7 @@ impl ComboboxInjection { expect_context() } + /// value: (value, text, disabled) pub fn insert_option(&self, id: String, value: (String, String, MaybeSignal)) { self.options .update_value(|options| options.insert(id, value));