Simple header menu
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import HeaderMenu from './components/HeaderMenu';
|
||||
|
||||
import styles from './Layout.scss';
|
||||
|
||||
class Layout extends React.Component {
|
||||
@@ -13,9 +15,9 @@ class Layout extends React.Component {
|
||||
<div className={ styles.container }>
|
||||
<div className={ styles.header }>
|
||||
<div className={ styles.teamName }>Coinbase</div>
|
||||
<div className={ styles.user }>
|
||||
<HeaderMenu>
|
||||
<img src={ this.props.avatarUrl } />
|
||||
</div>
|
||||
</HeaderMenu>
|
||||
</div>
|
||||
<div className={ styles.content }>
|
||||
{ this.props.children }
|
||||
@@ -31,4 +33,6 @@ const mapStateToProps = (state) => {
|
||||
}
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(Layout);
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
)(Layout);
|
||||
@@ -21,15 +21,7 @@
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.user {
|
||||
|
||||
img {
|
||||
height: 24px;
|
||||
width: 24px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
}
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
63
src/components/Layout/components/HeaderMenu/HeaderMenu.js
Normal file
63
src/components/Layout/components/HeaderMenu/HeaderMenu.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { logoutUser } from 'actions/UserActions';
|
||||
|
||||
import styles from './HeaderMenu.scss';
|
||||
|
||||
class HeaderMenu extends React.Component {
|
||||
static propTypes = {
|
||||
children: React.PropTypes.node.isRequired,
|
||||
}
|
||||
|
||||
state = {
|
||||
menuVisible: false,
|
||||
}
|
||||
|
||||
onMouseEnter = () => {
|
||||
this.setState({ menuVisible: true });
|
||||
}
|
||||
|
||||
onMouseLeave = () => {
|
||||
this.setState({ menuVisible: false });
|
||||
}
|
||||
|
||||
logout = (event) => {
|
||||
event.preventDefault();
|
||||
this.props.logout();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div
|
||||
className={ styles.menu }
|
||||
onMouseEnter={ this.onMouseEnter }
|
||||
onMouseLeave={ this.onMouseLeave }
|
||||
>
|
||||
<div className={ styles.content }>
|
||||
{ this.props.children }
|
||||
</div>
|
||||
|
||||
{ this.state.menuVisible ? (
|
||||
<div className={ styles.menu }>
|
||||
<ul>
|
||||
<li>
|
||||
<a href='/' onClick={ this.logout }>Logout</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
) : null }
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
logout: () => {
|
||||
dispatch(logoutUser())
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export default connect(null, mapDispatchToProps)(HeaderMenu);
|
||||
50
src/components/Layout/components/HeaderMenu/HeaderMenu.scss
Normal file
50
src/components/Layout/components/HeaderMenu/HeaderMenu.scss
Normal file
@@ -0,0 +1,50 @@
|
||||
@import '../../../../utils/constants.scss';
|
||||
|
||||
.content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
min-height: 43px;
|
||||
min-width: 43px;
|
||||
}
|
||||
|
||||
.menu {
|
||||
position: relative;
|
||||
|
||||
img {
|
||||
height: 24px;
|
||||
width: 24px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.menu {
|
||||
position: absolute;
|
||||
top: 42px;
|
||||
right: 0;
|
||||
z-index: 1000;
|
||||
border: 1px solid #eee;
|
||||
|
||||
ul {
|
||||
margin: 0;
|
||||
padding: 5px 0;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
li {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style-type: none;
|
||||
|
||||
a {
|
||||
display: flex;
|
||||
margin: 0;
|
||||
padding: 5px 10px;
|
||||
min-width: 150px;
|
||||
|
||||
color: $textColor;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
src/components/Layout/components/HeaderMenu/index.js
Normal file
2
src/components/Layout/components/HeaderMenu/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
import HeaderMenu from './HeaderMenu';
|
||||
export default HeaderMenu;
|
||||
Reference in New Issue
Block a user