mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-02 08:34:15 -05:00
Feat/demo site (#232)
* fix: demo site error * fix: SwitchVersion label * fix: BackTop demo scrollbar
This commit is contained in:
parent
cfe4804046
commit
5a77c874cd
7 changed files with 67 additions and 30 deletions
|
@ -34,6 +34,5 @@
|
||||||
font-size: 0.875em;
|
font-size: 0.875em;
|
||||||
line-height: 1.714;
|
line-height: 1.714;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
overflow: auto;
|
|
||||||
background-color: var(--demo-background-color);
|
background-color: var(--demo-background-color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use leptos::prelude::*;
|
use leptos::{either::Either, prelude::*};
|
||||||
use leptos_meta::Style;
|
use leptos_meta::Style;
|
||||||
use thaw::*;
|
use thaw::*;
|
||||||
|
|
||||||
|
@ -11,7 +11,11 @@ pub struct DemoCode {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Demo(demo_code: DemoCode, #[prop(optional)] children: Option<Children>) -> impl IntoView {
|
pub fn Demo(
|
||||||
|
#[prop(optional)] remove_scrollbar: bool,
|
||||||
|
demo_code: DemoCode,
|
||||||
|
#[prop(optional)] children: Option<Children>,
|
||||||
|
) -> impl IntoView {
|
||||||
let theme = Theme::use_theme(Theme::light);
|
let theme = Theme::use_theme(Theme::light);
|
||||||
let css_vars = Memo::new(move |_| {
|
let css_vars = Memo::new(move |_| {
|
||||||
let mut css_vars = String::new();
|
let mut css_vars = String::new();
|
||||||
|
@ -34,19 +38,37 @@ pub fn Demo(demo_code: DemoCode, #[prop(optional)] children: Option<Children>) -
|
||||||
|
|
||||||
let is_highlight = demo_code.is_highlight;
|
let is_highlight = demo_code.is_highlight;
|
||||||
let html = demo_code.text;
|
let html = demo_code.text;
|
||||||
|
let styles = use_context::<DemoStyle>().is_none().then(|| {
|
||||||
|
view! {
|
||||||
|
<Style id="leptos-thaw-syntect-css">
|
||||||
|
{include_str!("./syntect-css.css")}
|
||||||
|
</Style>
|
||||||
|
<Style id="demo-demo">
|
||||||
|
{include_str!("./demo.css")}
|
||||||
|
</Style>
|
||||||
|
}
|
||||||
|
});
|
||||||
|
provide_context(DemoStyle);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Style id="leptos-thaw-syntect-css">
|
{styles}
|
||||||
{include_str!("./syntect-css.css")}
|
|
||||||
</Style>
|
|
||||||
<Style id="demo-demo">
|
|
||||||
{include_str!("./demo.css")}
|
|
||||||
</Style>
|
|
||||||
<div class="demo-demo" style=move || css_vars.get()>
|
<div class="demo-demo" style=move || css_vars.get()>
|
||||||
{
|
{
|
||||||
if let Some(children) = children {
|
if let Some(children) = children {
|
||||||
view! {
|
view! {
|
||||||
<div class="demo-demo__view">{children()}</div>
|
{
|
||||||
|
if remove_scrollbar {
|
||||||
|
Either::Left(view! {
|
||||||
|
<div class="demo-demo__view">{children()}</div>
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Either::Right(view! {
|
||||||
|
<Scrollbar>
|
||||||
|
<div class="demo-demo__view">{children()}</div>
|
||||||
|
</Scrollbar>
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
<div class="demo-demo__toolbar" class=("demo-demo__toolbar--code", move || !is_show_code.get())>
|
<div class="demo-demo__toolbar" class=("demo-demo__toolbar--code", move || !is_show_code.get())>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content=MaybeSignal::derive(move || if is_show_code.get() {
|
content=MaybeSignal::derive(move || if is_show_code.get() {
|
||||||
|
@ -72,19 +94,24 @@ pub fn Demo(demo_code: DemoCode, #[prop(optional)] children: Option<Children>) -
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
<div class=move || code_class.get() style:display=move || (!is_show_code.get()).then_some("none").unwrap_or_default()>
|
<Scrollbar>
|
||||||
{
|
<div class=move || code_class.get() style:display=move || (!is_show_code.get()).then_some("none").unwrap_or_default()>
|
||||||
if is_highlight {
|
{
|
||||||
view! {
|
if is_highlight {
|
||||||
<Code inner_html=html />
|
view! {
|
||||||
}
|
<Code inner_html=html />
|
||||||
} else {
|
}
|
||||||
view! {
|
} else {
|
||||||
<Code text=html />
|
view! {
|
||||||
|
<Code text=html />
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
</div>
|
||||||
</div>
|
</Scrollbar>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct DemoStyle;
|
||||||
|
|
|
@ -14,10 +14,16 @@ pub fn SwitchVersion() -> impl IntoView {
|
||||||
];
|
];
|
||||||
|
|
||||||
let version = RwSignal::new(None::<String>);
|
let version = RwSignal::new(None::<String>);
|
||||||
|
let label = RwSignal::new(String::new());
|
||||||
#[cfg(any(feature = "csr", feature = "hydrate"))]
|
#[cfg(any(feature = "csr", feature = "hydrate"))]
|
||||||
{
|
{
|
||||||
let location = window().location();
|
let location = window().location();
|
||||||
let origin = location.origin().ok();
|
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);
|
version.set(origin);
|
||||||
let _ = version.watch(move |origin| {
|
let _ = version.watch(move |origin| {
|
||||||
if let Some(origin) = origin {
|
if let Some(origin) = origin {
|
||||||
|
@ -29,7 +35,7 @@ pub fn SwitchVersion() -> impl IntoView {
|
||||||
}
|
}
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Combobox selected_options=version placeholder="Switch version">
|
<Combobox value=label selected_options=version placeholder="Switch version">
|
||||||
{
|
{
|
||||||
options.into_iter().map(|option| view! {
|
options.into_iter().map(|option| view! {
|
||||||
<ComboboxOption value=option.1 text=option.0 />
|
<ComboboxOption value=option.1 text=option.0 />
|
||||||
|
|
|
@ -29,10 +29,12 @@ pub fn ComponentsPage() -> impl IntoView {
|
||||||
.demo-components__component {
|
.demo-components__component {
|
||||||
width: 896px;
|
width: 896px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
padding: 8px 12px 28px;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
.demo-components__toc {
|
.demo-components__toc {
|
||||||
width: 190px;
|
width: 190px;
|
||||||
margin: 12px 2px 12px 12px;
|
margin: 12px;
|
||||||
}
|
}
|
||||||
.demo-components__toc > .thaw-anchor {
|
.demo-components__toc > .thaw-anchor {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
|
@ -47,7 +49,7 @@ pub fn ComponentsPage() -> impl IntoView {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.demo-components__component {
|
.demo-components__component {
|
||||||
width: 100%;
|
width: 100vw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
@ -77,7 +79,7 @@ pub fn ComponentsPage() -> impl IntoView {
|
||||||
}
|
}
|
||||||
</NavDrawer>
|
</NavDrawer>
|
||||||
</div>
|
</div>
|
||||||
<Layout content_style="padding: 8px 12px 28px; display: flex;" attr:class=("doc-content", true)>
|
<Layout content_style="display: flex" attr:class=("doc-content", true)>
|
||||||
<Outlet/>
|
<Outlet/>
|
||||||
</Layout>
|
</Layout>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub fn to_tokens(code_block: &NodeCodeBlock, demos: &mut Vec<String>) -> TokenSt
|
||||||
let mut is_highlight = true;
|
let mut is_highlight = true;
|
||||||
let literal = langs
|
let literal = langs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|lang| lang != &&"demo")
|
.find(|lang| lang != &&"demo" && lang != &&"remove-scrollbar")
|
||||||
.map(|lang| highlight_to_html(&code_block.literal, lang))
|
.map(|lang| highlight_to_html(&code_block.literal, lang))
|
||||||
.flatten()
|
.flatten()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
|
@ -25,8 +25,10 @@ pub fn to_tokens(code_block: &NodeCodeBlock, demos: &mut Vec<String>) -> TokenSt
|
||||||
code_block.literal.clone()
|
code_block.literal.clone()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let remove_scrollbar = langs.iter().any(|lang| lang == &"remove-scrollbar");
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
<Demo>
|
<Demo remove_scrollbar=#remove_scrollbar>
|
||||||
<#demo />
|
<#demo />
|
||||||
<DemoCode slot is_highlight=#is_highlight text=#literal>
|
<DemoCode slot is_highlight=#is_highlight text=#literal>
|
||||||
</DemoCode>
|
</DemoCode>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
BackTop will find its first scrollable ascendant element and listen scroll event on it.
|
BackTop will find its first scrollable ascendant element and listen scroll event on it.
|
||||||
|
|
||||||
```rust demo
|
```rust demo remove-scrollbar
|
||||||
view! {
|
view! {
|
||||||
<BackTop />
|
<BackTop />
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ view! {
|
||||||
|
|
||||||
### Visibility height
|
### Visibility height
|
||||||
|
|
||||||
```rust demo
|
```rust demo remove-scrollbar
|
||||||
view! {
|
view! {
|
||||||
<BackTop bottom=100 visibility_height=280>
|
<BackTop bottom=100 visibility_height=280>
|
||||||
<div style="width: 200px; text-align: center;">
|
<div style="width: 200px; text-align: center;">
|
||||||
|
@ -22,7 +22,7 @@ view! {
|
||||||
|
|
||||||
### Change position
|
### Change position
|
||||||
|
|
||||||
```rust demo
|
```rust demo remove-scrollbar
|
||||||
view! {
|
view! {
|
||||||
<BackTop right=40 bottom=160>
|
<BackTop right=40 bottom=160>
|
||||||
<div style="width: 200px; text-align: center;">
|
<div style="width: 200px; text-align: center;">
|
||||||
|
|
|
@ -285,6 +285,7 @@ impl ComboboxInjection {
|
||||||
expect_context()
|
expect_context()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// value: (value, text, disabled)
|
||||||
pub fn insert_option(&self, id: String, value: (String, String, MaybeSignal<bool>)) {
|
pub fn insert_option(&self, id: String, value: (String, String, MaybeSignal<bool>)) {
|
||||||
self.options
|
self.options
|
||||||
.update_value(|options| options.insert(id, value));
|
.update_value(|options| options.insert(id, value));
|
||||||
|
|
Loading…
Add table
Reference in a new issue