Commit c3fdf5f 1 parent 9459812 commit c3fdf5f Copy full SHA for c3fdf5f
File tree 4 files changed +45
-1
lines changed
4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ demo_markdown = { path = "../demo_markdown" }
16
16
icondata = " 0.3.0"
17
17
palette = " 0.7.4"
18
18
chrono = " 0.4.33"
19
+ cfg-if = " 1.0.0"
19
20
20
21
[features ]
21
22
default = [" csr" ]
Original file line number Diff line number Diff line change 1
1
mod demo;
2
2
mod site_header;
3
+ mod switch_version;
3
4
4
5
pub use demo:: { Demo , DemoCode } ;
5
6
pub use site_header:: * ;
Original file line number Diff line number Diff line change
1
+ use super :: switch_version:: SwitchVersion ;
1
2
use leptos:: * ;
2
3
use leptos_meta:: Style ;
3
4
use leptos_router:: { use_location, use_navigate} ;
@@ -102,6 +103,9 @@ pub fn SiteHeader() -> impl IntoView {
102
103
.demo-header__menu-popover-mobile {
103
104
padding: 0;
104
105
}
106
+ .demo-header__right-btn .thaw-select {
107
+ width: 60px;
108
+ }
105
109
@media screen and (max-width: 600px) {
106
110
.demo-header {
107
111
padding: 0 8px;
@@ -167,7 +171,7 @@ pub fn SiteHeader() -> impl IntoView {
167
171
</Menu >
168
172
</div>
169
173
</Popover >
170
- <Space class="demo-header__right-btn" >
174
+ <Space class="demo-header__right-btn" align= SpaceAlign :: Center >
171
175
<Button
172
176
variant=ButtonVariant :: Text
173
177
on_click=move |_| {
@@ -191,6 +195,7 @@ pub fn SiteHeader() -> impl IntoView {
191
195
<Button variant=ButtonVariant :: Text on_click=Callback :: new( move |_| change_theme. call( ( ) ) ) >
192
196
{ move || theme_name. get( ) }
193
197
</Button >
198
+ <SwitchVersion />
194
199
<Button
195
200
variant=ButtonVariant :: Text
196
201
icon=icondata:: AiGithubOutlined
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments