57 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-08-24 15:09:42 +02:00
/**
2017-03-18 17:34:00 +01:00
*
* LeftMenuLink
*
*/
2016-08-24 15:09:42 +02:00
import React from 'react';
import { startsWith } from 'lodash';
import PropTypes from 'prop-types';
2017-08-17 15:39:09 +02:00
import { FormattedMessage } from 'react-intl';
2017-08-21 15:12:53 +02:00
import { Link } from 'react-router-dom';
2017-08-17 15:39:09 +02:00
import styles from './styles.scss';
2016-08-24 15:09:42 +02:00
class LeftMenuLink extends React.Component { // eslint-disable-line react/prefer-stateless-function
render() {
2017-07-21 18:15:43 +02:00
// We need to create our own active url checker,
// because of the two levels router.
const isLinkActive = startsWith(window.location.pathname.replace('/admin', ''), this.props.destination);
2017-07-21 18:15:43 +02:00
2016-08-24 15:09:42 +02:00
return (
2017-08-17 15:03:03 +02:00
<li className={styles.item}>
2017-11-27 17:27:16 +01:00
<Link
className={`${styles.link} ${isLinkActive ? styles.linkActive : ''}`}
to={{
pathname: this.props.destination,
search: this.props.source ? `?source=${this.props.source}` : '',
2017-11-27 17:27:16 +01:00
}}
>
2017-07-21 18:15:43 +02:00
<i className={`${styles.linkIcon} fa-${this.props.icon} fa`}></i>
<FormattedMessage
id={this.props.label}
defaultMessage='{label}'
values={{
label: this.props.label,
}}
className={styles.linkLabel}
/>
2016-08-25 10:47:15 +02:00
</Link>
2016-08-24 15:09:42 +02:00
</li>
);
}
}
LeftMenuLink.propTypes = {
destination: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
2017-11-27 17:27:16 +01:00
source: PropTypes.string,
};
LeftMenuLink.defaultProps = {
source: '',
2016-08-24 15:09:42 +02:00
};
export default LeftMenuLink;