Skip to content

add multiple language selection #1148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/language/.DS_Store
Binary file not shown.
Binary file added assets/language/chinese.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/language/english.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions components/dropdown/dropdown-style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

.dropdown {
position: relative;
color: #fff;
cursor: pointer;

}

.dropdown-language {
width: 20px;
height: 20px;
vertical-align: middle;
}

.dropdown-arrow {
vertical-align: middle;

&:before {
display: inline-block;
margin-left: 5px;
content: "\25be";
}
}

.dropdown-list {
display: none;
position: absolute;
width: 100%;
top: 45px;
left: -12px;
right: 0;
margin: auto;
background-color: #2B3A42;
z-index: 1;
text-align: center;

ul li {
list-style: none;
color: #fff;

a:link, a:visited, a:hover {
color: #fff;
}

img {
width: 20px;
height: 20px;
// margin: 2px 0;
}
}
}

.dropdown-list-show {
display: inline-block;
}
57 changes: 57 additions & 0 deletions components/dropdown/dropdown.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';

export default class Dropdown extends React.Component {

constructor(props, context) {
super(props, context);
this.state = {
isLanguageShow: false,
defaultLanguage: 'english',
};
}

render() {

let {
section,
activeMod
} = this.props;

let activeList = (this.state.isLanguageShow) ? "dropdown-list-show" : "";

return (
<div
className={ `navigation__link ${activeMod} dropdown` }
onMouseOver={() => {
this.setState({
isLanguageShow: true
});
}}
onMouseLeave={() => {
this.setState({
isLanguageShow: false
});
}}
>
<img className="dropdown-language" src={require("../../assets/language/" + this.state.defaultLanguage + ".png")}/>
<i className="dropdown-arrow"></i>
<div className={`dropdown-list ${activeList}`}>
<ul>
{
section.children.map((language) => {
return (
<li key={language.title}>
<a href={language.url}>
<img src={require("../../assets/language/" + language.title + ".png")}/>
</a>
</li>
);
})
}
</ul>
</div>
</div>
);
}

}
37 changes: 29 additions & 8 deletions components/navigation/navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import Link from '../link/link';
import Container from '../container/container';
import Logo from '../logo/logo';
import Dropdown from '../dropdown/dropdown';

// TODO: Maybe by updating the routing scheme later on we can avoid hardcoding this?
let Sections = [
Expand Down Expand Up @@ -36,6 +37,13 @@ let Sections = [
{
title: 'Support',
url: 'support'
},
{
title: 'Language',
children: [
{ title: 'english', url: 'https://webpack.js.org/' },
{ title: 'chinese', url: 'https://doc.webpack-china.org/' }
]
}
];

Expand All @@ -61,14 +69,27 @@ export default class Navigation extends React.Component {
let active = this._isActive(section);
let activeMod = active ? 'navigation__link--active' : '';

return (
<Link
key={ `navigation__link-${section.title}` }
className={ `navigation__link ${activeMod}` }
to={ `/${section.url}` }>
{ section.title }
</Link>
);
if (section.title === 'Language') {
return (
<Dropdown
key={ `navigation__link-${section.title}` }
section={section}
activeMod={activeMod}
className={ `navigation__link ${activeMod}` }
>
</Dropdown>
);
}
else {
return (
<Link
key={ `navigation__link-${section.title}` }
className={ `navigation__link ${activeMod}` }
to={ `/${section.url}` }>
{ section.title }
</Link>
);
}
})
}
</nav>
Expand Down
3 changes: 2 additions & 1 deletion components/site/site.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import '../navigation/search-style';
import '../sidebar-mobile/sidebar-mobile-style';
import '../sidebar-item/sidebar-item-style';
import '../logo/logo-style';
import '../dropdown/dropdown-style.scss';

export default props => {
// Retrieve section data
Expand All @@ -29,7 +30,7 @@ export default props => {
url
}))
}));

// Rename the root section ("webpack" => "Other") and push it to the end
let rootIndex = sections.findIndex(section => section.title === 'webpack');
let rootSection = sections.splice(rootIndex, 1)[0];
Expand Down