Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| import { autobind } from 'core-decorators'; | |
| import PropTypes from 'prop-types'; | |
| import { Component, Children, cloneElement } from 'react'; | |
| import ModalWrapper from './ModalWrapper'; | |
| const propTypes = { | |
| children: PropTypes.object | |
| }; | |
| export default class ModalTrigger extends Component { | |
| state = { | |
| toggled: false | |
| } | |
| @autobind | |
| open(e) { | |
| e.stopPropagation(); | |
| e.preventDefault(); | |
| this.setState({ toggled: true }); | |
| } | |
| @autobind | |
| close() { | |
| this.setState({ toggled: false }); | |
| } | |
| render() { | |
| const { children } = this.props; | |
| // ensure that we have only one child (control element) | |
| let child = cloneElement(Children.only(children), { onClick: this.open, key: 'modal-control' }); | |
| return [ | |
| child, | |
| <ModalWrapper {...this.props} show={this.state.toggled} onHide={this.close} key="modal-dialog" /> | |
| ]; | |
| } | |
| } | |
| ModalTrigger.propTypes = propTypes; |