Created
May 19, 2017 03:05
-
-
Save goper-leo/f4d78a1a8ad5f0604c7888720bfc6bb1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { Component } from 'react'; | |
import ReactDom from 'react-dom'; | |
export default class Price extends Component { | |
state = {open : false}; | |
handleClick = (e) => { | |
let value = false; | |
if(ReactDom.findDOMNode(this).contains(e.target)) { | |
value = true; | |
} | |
this.setState((prevState) => ({open: value})); | |
} | |
componentDidMount = () => { | |
window.addEventListener('click', this.handleClick, false); | |
} | |
componentWillUnmount() { | |
// make sure you remove the listener when the component is destroyed | |
document.removeEventListener('click', this.handleClick, false); | |
} | |
render() { | |
return ( | |
<li className={'dropdown ' + (this.state.open == true ? 'open' : '')} onClick={this.handleClick}> | |
<a> | |
Price range | |
<span className="caret"></span> | |
</a> | |
<div className="dropdown-menu"> | |
Price range filter | |
</div> | |
</li> | |
); | |
} | |
} |
This file contains hidden or 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, { Component } from 'react'; | |
import ReactDom from 'react-dom'; | |
export default class Room extends Component { | |
state = {open : false}; | |
handleClick = (e) => { | |
let value = false; | |
if(ReactDom.findDOMNode(this).contains(e.target)) { | |
value = true; | |
} | |
this.setState((prevState) => ({open: value})); | |
}; | |
componentDidMount = () => { | |
window.addEventListener('click', this.handleClick, false); | |
}; | |
componentWillUnmount() { | |
// make sure you remove the listener when the component is destroyed | |
document.removeEventListener('click', this.handleClick, false); | |
}; | |
render() { | |
return ( | |
<li className={'dropdown ' + (this.state.open == true ? 'open' : '')} onClick={this.handleClick}> | |
<a> | |
Room Type | |
<span className="caret"></span> | |
</a> | |
<div className="dropdown-menu"> | |
Room type filter | |
</div> | |
</li> | |
); | |
} | |
} |
This file contains hidden or 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, { Component } from 'react'; | |
import ReactDom from 'react-dom'; | |
import Room from './components/Room'; | |
import Price from './components/Price'; | |
class Navheader extends Component { | |
handleClick = (e) => { | |
}; | |
render() { | |
return ( | |
<ul className="nav navbar-nav navbar-left"> | |
<Room /> | |
<Price /> | |
</ul> | |
); | |
} | |
} | |
ReactDom.render(<Navheader />, document.getElementById('third-layer')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import React, { Component } from 'react';
import ReactDom from 'react-dom';
export default class Price extends Component {
state = {open : false}
render() {
const { state } = this
const { open } = state
}
}