This commit is contained in:
Florian Scholdei
2019-01-23 17:01:12 +01:00
19 changed files with 92 additions and 32 deletions

View File

@@ -2,16 +2,23 @@
import React from "react";
type Props = {
icon?: string,
label: string,
action: () => void
};
class NavAction extends React.Component<Props> {
render() {
const { label, action } = this.props;
const { label, icon, action } = this.props;
let showIcon = null;
if (icon) {
showIcon = (<><i className={icon}></i>{" "}</>);
}
return (
<li>
<a onClick={action}>{label}</a>
<a onClick={action}>{showIcon}{label}</a>
</li>
);
}

View File

@@ -6,6 +6,7 @@ import {Link, Route} from "react-router-dom";
type Props = {
to: string,
icon?: string,
label: string,
activeOnlyWhenExact?: boolean,
activeWhenMatch?: (route: any) => boolean
@@ -23,10 +24,17 @@ class NavLink extends React.Component<Props> {
}
renderLink = (route: any) => {
const { to, label } = this.props;
const { to, icon, label } = this.props;
let showIcon = null;
if (icon) {
showIcon = (<><i className={icon}></i>{" "}</>);
}
return (
<li>
<Link className={this.isActive(route) ? "is-active" : ""} to={to}>
{showIcon}
{label}
</Link>
</li>
@@ -35,6 +43,7 @@ class NavLink extends React.Component<Props> {
render() {
const { to, activeOnlyWhenExact } = this.props;
return (
<Route path={to} exact={activeOnlyWhenExact} children={this.renderLink} />
);