2017-05-03 02:04:16 +02:00
|
|
|
import React from 'react';
|
2017-04-21 20:05:35 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2022-10-09 15:55:32 +02:00
|
|
|
import { NavLink } from 'react-router-dom';
|
2019-02-01 00:14:05 +01:00
|
|
|
import Icon from 'mastodon/components/icon';
|
2022-10-09 15:55:32 +02:00
|
|
|
import classNames from 'classnames';
|
2016-12-12 14:27:52 +01:00
|
|
|
|
2022-10-09 15:55:32 +02:00
|
|
|
const ColumnLink = ({ icon, text, to, href, method, badge, transparent, ...other }) => {
|
|
|
|
const className = classNames('column-link', { 'column-link--transparent': transparent });
|
2018-01-21 13:20:20 +01:00
|
|
|
const badgeElement = typeof badge !== 'undefined' ? <span className='column-link__badge'>{badge}</span> : null;
|
2022-10-09 15:55:32 +02:00
|
|
|
const iconElement = typeof icon === 'string' ? <Icon id={icon} fixedWidth className='column-link__icon' /> : icon;
|
2018-01-21 13:20:20 +01:00
|
|
|
|
2016-12-12 14:27:52 +01:00
|
|
|
if (href) {
|
|
|
|
return (
|
2022-10-09 15:55:32 +02:00
|
|
|
<a href={href} className={className} data-method={method} title={text} {...other}>
|
|
|
|
{iconElement}
|
2022-10-10 06:51:16 +02:00
|
|
|
<span>{text}</span>
|
2018-01-21 13:20:20 +01:00
|
|
|
{badgeElement}
|
2016-12-12 14:27:52 +01:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2022-10-09 15:55:32 +02:00
|
|
|
<NavLink to={to} className={className} title={text} {...other}>
|
|
|
|
{iconElement}
|
2022-10-10 06:51:16 +02:00
|
|
|
<span>{text}</span>
|
2018-01-21 13:20:20 +01:00
|
|
|
{badgeElement}
|
2022-10-09 15:55:32 +02:00
|
|
|
</NavLink>
|
2016-12-12 14:27:52 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ColumnLink.propTypes = {
|
2022-10-09 15:55:32 +02:00
|
|
|
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
|
2017-04-21 20:05:35 +02:00
|
|
|
text: PropTypes.string.isRequired,
|
|
|
|
to: PropTypes.string,
|
|
|
|
href: PropTypes.string,
|
|
|
|
method: PropTypes.string,
|
2018-01-21 13:20:20 +01:00
|
|
|
badge: PropTypes.node,
|
2022-10-09 15:55:32 +02:00
|
|
|
transparent: PropTypes.bool,
|
2016-12-12 14:27:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ColumnLink;
|