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';
|
2017-10-08 02:55:58 +02:00
|
|
|
import { Link } from 'react-router-dom';
|
2019-09-09 16:41:41 +02:00
|
|
|
import Icon from 'flavours/glitch/components/icon';
|
2016-12-12 14:27:52 +01:00
|
|
|
|
2018-01-23 02:05:13 +01:00
|
|
|
const ColumnLink = ({ icon, text, to, onClick, href, method, badge }) => {
|
|
|
|
const badgeElement = typeof badge !== 'undefined' ? <span className='column-link__badge'>{badge}</span> : null;
|
|
|
|
|
2016-12-12 14:27:52 +01:00
|
|
|
if (href) {
|
|
|
|
return (
|
2017-07-26 13:46:53 +02:00
|
|
|
<a href={href} className='column-link' data-method={method}>
|
2019-09-09 16:41:41 +02:00
|
|
|
<Icon id={icon} fixedWidth className='column-link__icon' />
|
2016-12-12 14:27:52 +01:00
|
|
|
{text}
|
2018-01-23 02:05:13 +01:00
|
|
|
{badgeElement}
|
2016-12-12 14:27:52 +01:00
|
|
|
</a>
|
|
|
|
);
|
2017-06-29 07:00:54 +02:00
|
|
|
} else if (to) {
|
2016-12-12 14:27:52 +01:00
|
|
|
return (
|
2017-07-26 13:46:53 +02:00
|
|
|
<Link to={to} className='column-link'>
|
2019-09-09 16:41:41 +02:00
|
|
|
<Icon id={icon} fixedWidth className='column-link__icon' />
|
2016-12-12 14:27:52 +01:00
|
|
|
{text}
|
2018-01-23 02:05:13 +01:00
|
|
|
{badgeElement}
|
2016-12-12 14:27:52 +01:00
|
|
|
</Link>
|
|
|
|
);
|
2017-06-29 07:00:54 +02:00
|
|
|
} else {
|
2018-08-20 12:49:49 +02:00
|
|
|
const handleOnClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
return onClick(e);
|
|
|
|
}
|
2017-06-29 07:00:54 +02:00
|
|
|
return (
|
2018-08-20 12:49:49 +02:00
|
|
|
<a href='#' onClick={onClick && handleOnClick} className='column-link' tabIndex='0'>
|
2019-09-09 16:41:41 +02:00
|
|
|
<Icon id={icon} fixedWidth className='column-link__icon' />
|
2017-06-29 07:00:54 +02:00
|
|
|
{text}
|
2018-01-23 02:05:13 +01:00
|
|
|
{badgeElement}
|
2017-06-29 07:00:54 +02:00
|
|
|
</a>
|
|
|
|
);
|
2016-12-12 14:27:52 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ColumnLink.propTypes = {
|
2017-04-21 20:05:35 +02:00
|
|
|
icon: PropTypes.string.isRequired,
|
|
|
|
text: PropTypes.string.isRequired,
|
|
|
|
to: PropTypes.string,
|
2017-06-29 07:00:54 +02:00
|
|
|
onClick: PropTypes.func,
|
2017-04-21 20:05:35 +02:00
|
|
|
href: PropTypes.string,
|
|
|
|
method: PropTypes.string,
|
2018-01-23 02:05:13 +01:00
|
|
|
badge: PropTypes.node,
|
2016-12-12 14:27:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ColumnLink;
|