UNPKG

terriajs

Version:

Geospatial data visualization platform.

58 lines (49 loc) 1.61 kB
import PropTypes from 'prop-types'; export default { propTypes: { theme: PropTypes.object, children: PropTypes.any, btnTitle: PropTypes.string, btnText: PropTypes.string, onOpenChanged: PropTypes.func, isOpen: PropTypes.bool, forceClosed: PropTypes.bool }, getDefaultProps() { return { theme: {}, onOpenChanged: undefined }; }, changeOpenState(newValue) { if (this.props.onOpenChanged !== undefined) { this.props.onOpenChanged(newValue); } else { this.setState({ localIsOpen: newValue }); } }, onDismissed() { this.changeOpenState(false); }, isOpen() { if (this.props.isOpen !== undefined && this.props.onOpenChanged !== undefined) { return this.props.isOpen; } else { return this.state.localIsOpen; } }, openPanel(e) { if (!this.isOpen()) { // Tag this event so that we know not to react to it when it hits the window. // We could just set stopPropagation on it, but this would mean that clicks on other buttons that stopPropagation // would cause the panel not to close. e.nativeEvent[this.getDoNotCloseFlag()] = true; this.changeOpenState(true); } }, getDoNotCloseFlag() { return `do-not-react-${this.props.btnText}-${this.props.btnTitle}-${this.props.theme.btn}`; } };