Skip to content

Commit c3fdf5f

Browse files
authored
feat: Demo switch version (#152)
1 parent 9459812 commit c3fdf5f

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

demo/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ demo_markdown = { path = "../demo_markdown" }
1616
icondata = "0.3.0"
1717
palette = "0.7.4"
1818
chrono = "0.4.33"
19+
cfg-if = "1.0.0"
1920

2021
[features]
2122
default = ["csr"]

demo/src/components/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod demo;
22
mod site_header;
3+
mod switch_version;
34

45
pub use demo::{Demo, DemoCode};
56
pub use site_header::*;

demo/src/components/site_header.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::switch_version::SwitchVersion;
12
use leptos::*;
23
use leptos_meta::Style;
34
use leptos_router::{use_location, use_navigate};
@@ -102,6 +103,9 @@ pub fn SiteHeader() -> impl IntoView {
102103
.demo-header__menu-popover-mobile {
103104
padding: 0;
104105
}
106+
.demo-header__right-btn .thaw-select {
107+
width: 60px;
108+
}
105109
@media screen and (max-width: 600px) {
106110
.demo-header {
107111
padding: 0 8px;
@@ -167,7 +171,7 @@ pub fn SiteHeader() -> impl IntoView {
167171
</Menu>
168172
</div>
169173
</Popover>
170-
<Space class="demo-header__right-btn">
174+
<Space class="demo-header__right-btn" align=SpaceAlign::Center>
171175
<Button
172176
variant=ButtonVariant::Text
173177
on_click=move |_| {
@@ -191,6 +195,7 @@ pub fn SiteHeader() -> impl IntoView {
191195
<Button variant=ButtonVariant::Text on_click=Callback::new(move |_| change_theme.call(()))>
192196
{move || theme_name.get()}
193197
</Button>
198+
<SwitchVersion />
194199
<Button
195200
variant=ButtonVariant::Text
196201
icon=icondata::AiGithubOutlined

demo/src/components/switch_version.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use leptos::*;
2+
use thaw::*;
3+
4+
#[component]
5+
pub fn SwitchVersion() -> impl IntoView {
6+
let options = vec![
7+
SelectOption {
8+
label: "main".into(),
9+
value: "https://thawui.vercel.app".into(),
10+
},
11+
SelectOption {
12+
label: "0.2.5".into(),
13+
value: "https://thaw-8og1kv8zs-thaw.vercel.app".into(),
14+
},
15+
];
16+
17+
cfg_if::cfg_if! {
18+
if #[cfg(any(feature = "csr", feature = "hydrate"))] {
19+
let location = window().location();
20+
let host = location.host().ok();
21+
let version = RwSignal::new(host);
22+
let _ = version.watch(move |host| {
23+
if let Some(host) = host {
24+
let pathname = location.pathname().unwrap_or_default();
25+
let href = format!("{}{}", host, pathname);
26+
let _ = location.set_href(&href);
27+
}
28+
});
29+
} else {
30+
let version = RwSignal::new(None::<String>);
31+
}
32+
}
33+
34+
view! {
35+
<Select value=version options/>
36+
}
37+
}

0 commit comments

Comments
 (0)