File tree 7 files changed +143
-9
lines changed
7 files changed +143
-9
lines changed Original file line number Diff line number Diff line change
1
+
2
+ .dropdown {
3
+ position : relative ;
4
+ color : #fff ;
5
+ cursor : pointer ;
6
+
7
+ }
8
+
9
+ .dropdown-language {
10
+ width : 20px ;
11
+ height : 20px ;
12
+ vertical-align : middle ;
13
+ }
14
+
15
+ .dropdown-arrow {
16
+ vertical-align : middle ;
17
+
18
+ & :before {
19
+ display : inline-block ;
20
+ margin-left : 5px ;
21
+ content : " \25be " ;
22
+ }
23
+ }
24
+
25
+ .dropdown-list {
26
+ display : none ;
27
+ position : absolute ;
28
+ width : 100% ;
29
+ top : 45px ;
30
+ left : -12px ;
31
+ right : 0 ;
32
+ margin : auto ;
33
+ background-color : #2B3A42 ;
34
+ z-index : 1 ;
35
+ text-align : center ;
36
+
37
+ ul li {
38
+ list-style : none ;
39
+ color : #fff ;
40
+
41
+ a :link , a :visited , a :hover {
42
+ color : #fff ;
43
+ }
44
+
45
+ img {
46
+ width : 20px ;
47
+ height : 20px ;
48
+ // margin: 2px 0;
49
+ }
50
+ }
51
+ }
52
+
53
+ .dropdown-list-show {
54
+ display : inline-block ;
55
+ }
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ export default class Dropdown extends React . Component {
4
+
5
+ constructor ( props , context ) {
6
+ super ( props , context ) ;
7
+ this . state = {
8
+ isLanguageShow : false ,
9
+ defaultLanguage : 'english' ,
10
+ } ;
11
+ }
12
+
13
+ render ( ) {
14
+
15
+ let {
16
+ section,
17
+ activeMod
18
+ } = this . props ;
19
+
20
+ let activeList = ( this . state . isLanguageShow ) ? "dropdown-list-show" : "" ;
21
+
22
+ return (
23
+ < div
24
+ className = { `navigation__link ${ activeMod } dropdown` }
25
+ onMouseOver = { ( ) => {
26
+ this . setState ( {
27
+ isLanguageShow : true
28
+ } ) ;
29
+ } }
30
+ onMouseLeave = { ( ) => {
31
+ this . setState ( {
32
+ isLanguageShow : false
33
+ } ) ;
34
+ } }
35
+ >
36
+ < img className = "dropdown-language" src = { require ( "../../assets/language/" + this . state . defaultLanguage + ".png" ) } />
37
+ < i className = "dropdown-arrow" > </ i >
38
+ < div className = { `dropdown-list ${ activeList } ` } >
39
+ < ul >
40
+ {
41
+ section . children . map ( ( language ) => {
42
+ return (
43
+ < li key = { language . title } >
44
+ < a href = { language . url } >
45
+ < img src = { require ( "../../assets/language/" + language . title + ".png" ) } />
46
+ </ a >
47
+ </ li >
48
+ ) ;
49
+ } )
50
+ }
51
+ </ ul >
52
+ </ div >
53
+ </ div >
54
+ ) ;
55
+ }
56
+
57
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React from 'react';
2
2
import Link from '../link/link' ;
3
3
import Container from '../container/container' ;
4
4
import Logo from '../logo/logo' ;
5
+ import Dropdown from '../dropdown/dropdown' ;
5
6
6
7
// TODO: Maybe by updating the routing scheme later on we can avoid hardcoding this?
7
8
let Sections = [
@@ -36,6 +37,13 @@ let Sections = [
36
37
{
37
38
title : 'Support' ,
38
39
url : 'support'
40
+ } ,
41
+ {
42
+ title : 'Language' ,
43
+ children : [
44
+ { title : 'english' , url : 'https://webpack.js.org/' } ,
45
+ { title : 'chinese' , url : 'https://doc.webpack-china.org/' }
46
+ ]
39
47
}
40
48
] ;
41
49
@@ -61,14 +69,27 @@ export default class Navigation extends React.Component {
61
69
let active = this . _isActive ( section ) ;
62
70
let activeMod = active ? 'navigation__link--active' : '' ;
63
71
64
- return (
65
- < Link
66
- key = { `navigation__link-${ section . title } ` }
67
- className = { `navigation__link ${ activeMod } ` }
68
- to = { `/${ section . url } ` } >
69
- { section . title }
70
- </ Link >
71
- ) ;
72
+ if ( section . title === 'Language' ) {
73
+ return (
74
+ < Dropdown
75
+ key = { `navigation__link-${ section . title } ` }
76
+ section = { section }
77
+ activeMod = { activeMod }
78
+ className = { `navigation__link ${ activeMod } ` }
79
+ >
80
+ </ Dropdown >
81
+ ) ;
82
+ }
83
+ else {
84
+ return (
85
+ < Link
86
+ key = { `navigation__link-${ section . title } ` }
87
+ className = { `navigation__link ${ activeMod } ` }
88
+ to = { `/${ section . url } ` } >
89
+ { section . title }
90
+ </ Link >
91
+ ) ;
92
+ }
72
93
} )
73
94
}
74
95
</ nav >
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import '../navigation/search-style';
17
17
import '../sidebar-mobile/sidebar-mobile-style' ;
18
18
import '../sidebar-item/sidebar-item-style' ;
19
19
import '../logo/logo-style' ;
20
+ import '../dropdown/dropdown-style.scss' ;
20
21
21
22
export default props => {
22
23
// Retrieve section data
@@ -29,7 +30,7 @@ export default props => {
29
30
url
30
31
} ) )
31
32
} ) ) ;
32
-
33
+
33
34
// Rename the root section ("webpack" => "Other") and push it to the end
34
35
let rootIndex = sections . findIndex ( section => section . title === 'webpack' ) ;
35
36
let rootSection = sections . splice ( rootIndex , 1 ) [ 0 ] ;
You can’t perform that action at this time.
0 commit comments