ExplorerToggle.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import * as actions from './actions';
  4. import Button from '../../components/Button/Button';
  5. /**
  6. * A Button which toggles the explorer, and doubles as a loading indicator.
  7. */
  8. // TODO isVisible should not be used here, but at the moment there is a click
  9. // binding problem between this and the ExplorerPanel clickOutside.
  10. const ExplorerToggle = ({ isVisible, isFetching, children, onToggle }) => (
  11. <Button
  12. icon="folder-open-inverse"
  13. isLoading={isFetching}
  14. onClick={isVisible ? null : onToggle}
  15. >
  16. {children}
  17. </Button>
  18. );
  19. ExplorerToggle.propTypes = {
  20. isVisible: React.PropTypes.bool,
  21. isFetching: React.PropTypes.bool,
  22. onToggle: React.PropTypes.func,
  23. children: React.PropTypes.node,
  24. };
  25. const mapStateToProps = (store) => ({
  26. isFetching: store.explorer.isFetching,
  27. isVisible: store.explorer.isVisible,
  28. });
  29. const mapDispatchToProps = (dispatch) => ({
  30. onToggle() {
  31. dispatch(actions.toggleExplorer());
  32. },
  33. });
  34. export default connect(mapStateToProps, mapDispatchToProps)(ExplorerToggle);