mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-02 16:44:15 -05:00
feat: Demo switch version (#152)
This commit is contained in:
parent
9459812159
commit
c3fdf5fcb0
4 changed files with 45 additions and 1 deletions
|
@ -16,6 +16,7 @@ demo_markdown = { path = "../demo_markdown" }
|
||||||
icondata = "0.3.0"
|
icondata = "0.3.0"
|
||||||
palette = "0.7.4"
|
palette = "0.7.4"
|
||||||
chrono = "0.4.33"
|
chrono = "0.4.33"
|
||||||
|
cfg-if = "1.0.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["csr"]
|
default = ["csr"]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
mod demo;
|
mod demo;
|
||||||
mod site_header;
|
mod site_header;
|
||||||
|
mod switch_version;
|
||||||
|
|
||||||
pub use demo::{Demo, DemoCode};
|
pub use demo::{Demo, DemoCode};
|
||||||
pub use site_header::*;
|
pub use site_header::*;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use super::switch_version::SwitchVersion;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_meta::Style;
|
use leptos_meta::Style;
|
||||||
use leptos_router::{use_location, use_navigate};
|
use leptos_router::{use_location, use_navigate};
|
||||||
|
@ -102,6 +103,9 @@ pub fn SiteHeader() -> impl IntoView {
|
||||||
.demo-header__menu-popover-mobile {
|
.demo-header__menu-popover-mobile {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
.demo-header__right-btn .thaw-select {
|
||||||
|
width: 60px;
|
||||||
|
}
|
||||||
@media screen and (max-width: 600px) {
|
@media screen and (max-width: 600px) {
|
||||||
.demo-header {
|
.demo-header {
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
|
@ -167,7 +171,7 @@ pub fn SiteHeader() -> impl IntoView {
|
||||||
</Menu>
|
</Menu>
|
||||||
</div>
|
</div>
|
||||||
</Popover>
|
</Popover>
|
||||||
<Space class="demo-header__right-btn">
|
<Space class="demo-header__right-btn" align=SpaceAlign::Center>
|
||||||
<Button
|
<Button
|
||||||
variant=ButtonVariant::Text
|
variant=ButtonVariant::Text
|
||||||
on_click=move |_| {
|
on_click=move |_| {
|
||||||
|
@ -191,6 +195,7 @@ pub fn SiteHeader() -> impl IntoView {
|
||||||
<Button variant=ButtonVariant::Text on_click=Callback::new(move |_| change_theme.call(()))>
|
<Button variant=ButtonVariant::Text on_click=Callback::new(move |_| change_theme.call(()))>
|
||||||
{move || theme_name.get()}
|
{move || theme_name.get()}
|
||||||
</Button>
|
</Button>
|
||||||
|
<SwitchVersion />
|
||||||
<Button
|
<Button
|
||||||
variant=ButtonVariant::Text
|
variant=ButtonVariant::Text
|
||||||
icon=icondata::AiGithubOutlined
|
icon=icondata::AiGithubOutlined
|
||||||
|
|
37
demo/src/components/switch_version.rs
Normal file
37
demo/src/components/switch_version.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
use leptos::*;
|
||||||
|
use thaw::*;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn SwitchVersion() -> impl IntoView {
|
||||||
|
let options = vec![
|
||||||
|
SelectOption {
|
||||||
|
label: "main".into(),
|
||||||
|
value: "https://thawui.vercel.app".into(),
|
||||||
|
},
|
||||||
|
SelectOption {
|
||||||
|
label: "0.2.5".into(),
|
||||||
|
value: "https://thaw-8og1kv8zs-thaw.vercel.app".into(),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
cfg_if::cfg_if! {
|
||||||
|
if #[cfg(any(feature = "csr", feature = "hydrate"))] {
|
||||||
|
let location = window().location();
|
||||||
|
let host = location.host().ok();
|
||||||
|
let version = RwSignal::new(host);
|
||||||
|
let _ = version.watch(move |host| {
|
||||||
|
if let Some(host) = host {
|
||||||
|
let pathname = location.pathname().unwrap_or_default();
|
||||||
|
let href = format!("{}{}", host, pathname);
|
||||||
|
let _ = location.set_href(&href);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let version = RwSignal::new(None::<String>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<Select value=version options/>
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue