actions_modal.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import IconButton from '../../../components/icon_button';
  6. import classNames from 'classnames';
  7. export default class ActionsModal extends ImmutablePureComponent {
  8. static propTypes = {
  9. status: ImmutablePropTypes.map,
  10. actions: PropTypes.array,
  11. onClick: PropTypes.func,
  12. };
  13. renderAction = (action, i) => {
  14. if (action === null) {
  15. return <li key={`sep-${i}`} className='dropdown-menu__separator' />;
  16. }
  17. const { icon = null, text, meta = null, active = false, href = '#' } = action;
  18. return (
  19. <li key={`${text}-${i}`}>
  20. <a href={href} target='_blank' rel='noopener noreferrer' onClick={this.props.onClick} data-index={i} className={classNames({ active })}>
  21. {icon && <IconButton title={text} icon={icon} role='presentation' tabIndex='-1' inverted />}
  22. <div>
  23. <div className={classNames({ 'actions-modal__item-label': !!meta })}>{text}</div>
  24. <div>{meta}</div>
  25. </div>
  26. </a>
  27. </li>
  28. );
  29. }
  30. render () {
  31. return (
  32. <div className='modal-root__modal actions-modal'>
  33. <ul className={classNames({ 'with-status': !!status })}>
  34. {this.props.actions.map(this.renderAction)}
  35. </ul>
  36. </div>
  37. );
  38. }
  39. }