Created
March 28, 2017 13:11
-
-
Save eduard-tkv/2253777c24fec7be03c5b91a27ad4456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const STATUS = { | |
HOVERED: 'hovered', | |
NORMAL: 'normal', | |
}; | |
export default class Link extends React.Component { | |
constructor(props) { | |
super(props); | |
this._onMouseEnter = this._onMouseEnter.bind(this); | |
this._onMouseLeave = this._onMouseLeave.bind(this); | |
this.state = { | |
class: STATUS.NORMAL, | |
}; | |
} | |
_onMouseEnter() { | |
this.setState({class: STATUS.HOVERED}); | |
} | |
_onMouseLeave() { | |
this.setState({class: STATUS.NORMAL}); | |
} | |
render() { | |
return ( | |
<a | |
className={this.state.class} | |
href={this.props.page || '#'} | |
onMouseEnter={this._onMouseEnter} | |
onMouseLeave={this._onMouseLeave}> | |
{this.props.children} | |
</a> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment