You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Link } from 'react-router-dom';
  4. const ColumnLink = ({ icon, text, to, onClick, href, method, badge }) => {
  5. const badgeElement = typeof badge !== 'undefined' ? <span className='column-link__badge'>{badge}</span> : null;
  6. if (href) {
  7. return (
  8. <a href={href} className='column-link' data-method={method}>
  9. <i className={`fa fa-fw fa-${icon} column-link__icon`} />
  10. {text}
  11. {badgeElement}
  12. </a>
  13. );
  14. } else if (to) {
  15. return (
  16. <Link to={to} className='column-link'>
  17. <i className={`fa fa-fw fa-${icon} column-link__icon`} />
  18. {text}
  19. {badgeElement}
  20. </Link>
  21. );
  22. } else {
  23. const handleOnClick = (e) => {
  24. e.preventDefault();
  25. e.stopPropagation();
  26. return onClick(e);
  27. }
  28. return (
  29. <a href='#' onClick={onClick && handleOnClick} className='column-link' tabIndex='0'>
  30. <i className={`fa fa-fw fa-${icon} column-link__icon`} />
  31. {text}
  32. {badgeElement}
  33. </a>
  34. );
  35. }
  36. };
  37. ColumnLink.propTypes = {
  38. icon: PropTypes.string.isRequired,
  39. text: PropTypes.string.isRequired,
  40. to: PropTypes.string,
  41. onClick: PropTypes.func,
  42. href: PropTypes.string,
  43. method: PropTypes.string,
  44. badge: PropTypes.node,
  45. };
  46. export default ColumnLink;