2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
|
|
|
import classNames from 'classnames';
|
2022-10-09 22:55:32 +09:00
|
|
|
import { NavLink } from 'react-router-dom';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
2024-01-15 06:41:16 +09:00
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
2016-12-12 22:27:52 +09:00
|
|
|
|
2024-01-15 06:41:16 +09:00
|
|
|
const ColumnLink = ({ icon, iconComponent, text, to, onClick, href, method, badge, transparent, ...other }) => {
|
2022-10-09 22:55:32 +09:00
|
|
|
const className = classNames('column-link', { 'column-link--transparent': transparent });
|
2018-01-23 10:05:13 +09:00
|
|
|
const badgeElement = typeof badge !== 'undefined' ? <span className='column-link__badge'>{badge}</span> : null;
|
2024-01-15 06:41:16 +09:00
|
|
|
const iconElement = (typeof icon === 'string' || iconComponent) ? <Icon id={icon} icon={iconComponent} className='column-link__icon' /> : icon;
|
2018-01-23 10:05:13 +09:00
|
|
|
|
2016-12-12 22:27:52 +09:00
|
|
|
if (href) {
|
|
|
|
return (
|
2022-10-09 22:55:32 +09:00
|
|
|
<a href={href} className={className} data-method={method} title={text} {...other}>
|
|
|
|
{iconElement}
|
2022-10-10 13:51:16 +09:00
|
|
|
<span>{text}</span>
|
2018-01-23 10:05:13 +09:00
|
|
|
{badgeElement}
|
2016-12-12 22:27:52 +09:00
|
|
|
</a>
|
|
|
|
);
|
2017-06-29 14:00:54 +09:00
|
|
|
} else if (to) {
|
2016-12-12 22:27:52 +09:00
|
|
|
return (
|
2022-10-09 22:55:32 +09:00
|
|
|
<NavLink to={to} className={className} title={text} {...other}>
|
|
|
|
{iconElement}
|
2022-10-10 13:51:16 +09:00
|
|
|
<span>{text}</span>
|
2018-01-23 10:05:13 +09:00
|
|
|
{badgeElement}
|
2022-10-09 22:55:32 +09:00
|
|
|
</NavLink>
|
2016-12-12 22:27:52 +09:00
|
|
|
);
|
2017-06-29 14:00:54 +09:00
|
|
|
} else {
|
2018-08-20 19:49:49 +09:00
|
|
|
const handleOnClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
return onClick(e);
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-06-29 14:00:54 +09:00
|
|
|
return (
|
2023-05-08 22:16:55 +09:00
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-is-valid -- intentional to have the same look and feel as other menu items
|
2023-04-04 23:33:44 +09:00
|
|
|
<a href='#' onClick={onClick && handleOnClick} className={className} title={text} {...other} tabIndex={0}>
|
2022-10-09 22:55:32 +09:00
|
|
|
{iconElement}
|
2022-11-05 16:12:04 +09:00
|
|
|
<span>{text}</span>
|
2018-01-23 10:05:13 +09:00
|
|
|
{badgeElement}
|
2017-06-29 14:00:54 +09:00
|
|
|
</a>
|
|
|
|
);
|
2016-12-12 22:27:52 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ColumnLink.propTypes = {
|
2022-10-09 22:55:32 +09:00
|
|
|
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
|
2024-01-15 06:41:16 +09:00
|
|
|
iconComponent: PropTypes.func,
|
2017-04-22 03:05:35 +09:00
|
|
|
text: PropTypes.string.isRequired,
|
|
|
|
to: PropTypes.string,
|
2017-06-29 14:00:54 +09:00
|
|
|
onClick: PropTypes.func,
|
2017-04-22 03:05:35 +09:00
|
|
|
href: PropTypes.string,
|
|
|
|
method: PropTypes.string,
|
2018-01-23 10:05:13 +09:00
|
|
|
badge: PropTypes.node,
|
2022-10-09 22:55:32 +09:00
|
|
|
transparent: PropTypes.bool,
|
2016-12-12 22:27:52 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ColumnLink;
|