File tree 2 files changed +48
-0
lines changed
packages/site/src/app/routes/layout
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ import { DCustomIcon, GithubOutlined } from '@react-devui/icons';
10
10
import { DDropdown , DMenu , DSeparator } from '@react-devui/ui' ;
11
11
import { getClassName } from '@react-devui/utils' ;
12
12
13
+ import { environment } from '../../../environments/environment' ;
14
+ import { AppVersions } from './Versions' ;
15
+
13
16
export interface AppHeaderProps {
14
17
menuOpen : boolean ;
15
18
onMenuOpenChange : ( open : boolean ) => void ;
@@ -46,6 +49,7 @@ export function AppHeader(props: AppHeaderProps): JSX.Element | null {
46
49
< div > </ div >
47
50
</ div >
48
51
</ button >
52
+ { environment . production && < AppVersions /> }
49
53
< DMenu
50
54
className = "d-none d-md-inline-block app-layout-header__menu"
51
55
dList = { [
Original file line number Diff line number Diff line change
1
+ import axios from 'axios' ;
2
+ import { useState } from 'react' ;
3
+ import { useLocation } from 'react-router-dom' ;
4
+
5
+ import { useMount } from '@react-devui/hooks' ;
6
+ import { DownOutlined } from '@react-devui/icons' ;
7
+ import { DButton , DDropdown } from '@react-devui/ui' ;
8
+
9
+ export function AppVersions ( ) : JSX . Element | null {
10
+ const location = useLocation ( ) ;
11
+
12
+ const version = ( ( ) => {
13
+ const v = window . location . host . match ( / ^ v [ 0 - 9 ] + / ) ;
14
+ return v ? v [ 0 ] : 'main' ;
15
+ } ) ( ) ;
16
+ const [ versions , setVersions ] = useState < string [ ] > ( ( ) => {
17
+ if ( version === 'main' ) {
18
+ return [ 'main' ] ;
19
+ } else {
20
+ return [ 'main' , version ] ;
21
+ }
22
+ } ) ;
23
+ useMount ( ( ) => {
24
+ axios . get ( '/api/versions' ) . then ( ( response ) => {
25
+ setVersions ( [ 'main' , ...( response . data as number [ ] ) . map ( ( v ) => `v${ v } ` ) ] ) ;
26
+ } ) ;
27
+ } ) ;
28
+
29
+ return (
30
+ < DDropdown
31
+ dList = { versions . map ( ( v ) => ( { id : v , label : v , type : 'item' } ) ) }
32
+ onItemClick = { ( id ) => {
33
+ window . location = ( ( id === 'main' ? 'https://react-devui.com' : `https://${ id } .react-devui.com` ) + location . pathname ) as any ;
34
+ } }
35
+ >
36
+ < DButton dType = "text" >
37
+ < div className = "d-flex align-items-center" >
38
+ { version }
39
+ < DownOutlined style = { { position : 'relative' , top : 2 , marginLeft : 2 } } dSize = { 12 } />
40
+ </ div >
41
+ </ DButton >
42
+ </ DDropdown >
43
+ ) ;
44
+ }
You can’t perform that action at this time.
0 commit comments