2018-09-03 16:17:36 +02:00
|
|
|
//@flow
|
|
|
|
|
import * as React from "react";
|
|
|
|
|
import { Route, Link } from "react-router-dom";
|
|
|
|
|
|
|
|
|
|
// TODO mostly copy of PrimaryNavigationLink
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
to: string,
|
|
|
|
|
label: string,
|
2018-10-09 11:53:06 +02:00
|
|
|
activeOnlyWhenExact?: boolean,
|
|
|
|
|
activeWhenMatch?: (route: any) => boolean
|
2018-09-03 16:17:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NavLink extends React.Component<Props> {
|
|
|
|
|
static defaultProps = {
|
|
|
|
|
activeOnlyWhenExact: true
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-09 11:53:06 +02:00
|
|
|
|
|
|
|
|
isActive(route: any) {
|
|
|
|
|
const { activeWhenMatch } = this.props;
|
|
|
|
|
return route.match || (activeWhenMatch && activeWhenMatch(route));
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:17:36 +02:00
|
|
|
renderLink = (route: any) => {
|
|
|
|
|
const { to, label } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<li>
|
2018-10-09 11:53:06 +02:00
|
|
|
<Link className={this.isActive(route) ? "is-active" : ""} to={to}>
|
2018-09-03 16:17:36 +02:00
|
|
|
{label}
|
|
|
|
|
</Link>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { to, activeOnlyWhenExact } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<Route path={to} exact={activeOnlyWhenExact} children={this.renderLink} />
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default NavLink;
|