{icon}
{text}
diff --git a/src/renderer/components/layout/tab-layout.tsx b/src/renderer/components/layout/tab-layout.tsx
index 7369399627..6f00b13f7f 100644
--- a/src/renderer/components/layout/tab-layout.tsx
+++ b/src/renderer/components/layout/tab-layout.tsx
@@ -1,38 +1,55 @@
import "./tab-layout.scss";
+
import React, { ReactNode } from "react";
-import { matchPath, RouteProps } from "react-router-dom";
+import { matchPath, Redirect, Route, Switch } from "react-router";
import { observer } from "mobx-react";
-import { cssNames } from "../../utils";
+import { cssNames, IClassName } from "../../utils";
import { Tab, Tabs } from "../tabs";
import { ErrorBoundary } from "../error-boundary";
import { navigate, navigation } from "../../navigation";
-export interface TabRoute extends RouteProps {
- title: React.ReactNode;
- url: string;
-}
-
export interface TabLayoutProps {
- children: ReactNode;
- className?: any;
- tabs?: TabRoute[];
- contentClass?: string;
+ className?: IClassName;
+ contentClass?: IClassName;
+ tabs?: TabLayoutRoute[];
+ children?: ReactNode;
}
-export const TabLayout = observer(({ className, contentClass, tabs, children }: TabLayoutProps) => {
- const routePath = navigation.location.pathname;
+export interface TabLayoutRoute {
+ routePath: string;
+ title: React.ReactNode;
+ component: React.ComponentType
;
+ url?: string; // page-url, if not provided `routePath` is used (doesn't work when path has some :placeholder(s))
+ exact?: boolean; // route-path matching rule
+ default?: boolean; // initial tab to open with provided `url, by default tabs[0] is used
+}
+
+export const TabLayout = observer(({ className, contentClass, tabs = [], children }: TabLayoutProps) => {
+ const currentLocation = navigation.location.pathname;
+ const hasTabs = tabs.length > 0;
+ const startTabUrl = hasTabs ? (tabs.find(tab => tab.default) || tabs[0])?.url : null;
return (
- {tabs && (
+ {hasTabs && (
navigate(url)}>
- {tabs.map(({ title, path, url, ...routeProps }) => {
- const isActive = !!matchPath(routePath, { path, ...routeProps });
+ {tabs.map(({ title, routePath, url = routePath, exact }) => {
+ const isActive = !!matchPath(currentLocation, { path: routePath, exact });
return ;
})}
)}
-
- {children}
+
+
+ {hasTabs && (
+
+ {tabs.map(({ routePath, exact, component }) => {
+ return ;
+ })}
+
+
+ )}
+ {children}
+
);