Skip to content

Instantly share code, notes, and snippets.

@SugarDarius
Created January 31, 2018 13:52
Show Gist options
  • Save SugarDarius/4125362d19dc65e56ba443bf0ed8aff6 to your computer and use it in GitHub Desktop.
Save SugarDarius/4125362d19dc65e56ba443bf0ed8aff6 to your computer and use it in GitHub Desktop.
Independent Dropdown Index
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import IndependentDropdown from './independent-dropdown.jsx';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
dropdowns: {
products: {display: false}
}
};
}
displayDrowdown(id) {
const { dropdowns } = this.state;
dropdowns[id].display = !dropdowns[id].display;
this.setState({dropdowns: dropdowns});
}
render() {
return (
<div className='app'>
<header>
<div className='indepdent-dropdown-container-example'>
<a href='#' onClick={(e) => {e.preventDefault(); this.displayDrowdown('products')}}>
<span>Products</span>
</a>
<IndependentDropdown
id='dropdown'
display={this.state.dropdowns.products.display}
items={[...]}
onClickOutsideAction={(id) => {this.displayDrowdown(id)}}
/>
</div>
</header>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment