column_link.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { NavLink } from 'react-router-dom';
  4. import Icon from 'mastodon/components/icon';
  5. import classNames from 'classnames';
  6. const ColumnLink = ({ icon, text, to, href, method, badge, transparent, ...other }) => {
  7. const className = classNames('column-link', { 'column-link--transparent': transparent });
  8. const badgeElement = typeof badge !== 'undefined' ? <span className='column-link__badge'>{badge}</span> : null;
  9. const iconElement = typeof icon === 'string' ? <Icon id={icon} fixedWidth className='column-link__icon' /> : icon;
  10. if (href) {
  11. return (
  12. <a href={href} className={className} data-method={method} title={text} {...other}>
  13. {iconElement}
  14. <span>{text}</span>
  15. {badgeElement}
  16. </a>
  17. );
  18. } else {
  19. return (
  20. <NavLink to={to} className={className} title={text} {...other}>
  21. {iconElement}
  22. <span>{text}</span>
  23. {badgeElement}
  24. </NavLink>
  25. );
  26. }
  27. };
  28. ColumnLink.propTypes = {
  29. icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
  30. text: PropTypes.string.isRequired,
  31. to: PropTypes.string,
  32. href: PropTypes.string,
  33. method: PropTypes.string,
  34. badge: PropTypes.node,
  35. transparent: PropTypes.bool,
  36. };
  37. export default ColumnLink;