| 1 |
import React, { useEffect, useState } from "react"; |
| 2 |
import Route from "../inc/Route"; |
| 3 |
import NavigationHeaderButton from "./NavigationHeaderButton"; |
| 4 |
|
| 5 |
/** |
| 6 |
* Navigation component. |
| 7 |
* |
| 8 |
* @param {Object} props component properties |
| 9 |
* @param {Array<Route>} props.routes routes array |
| 10 |
* @param {string | null} props.currentRoutePath current route path |
| 11 |
* @param {Function} props.setRoute set route path |
| 12 |
* @class |
| 13 |
*/ |
| 14 |
function Navigation({ routes, currentRoutePath, setRoute }) { |
| 15 |
const [calculatedStyle, setCalculatedStyles] = useState({}); |
| 16 |
|
| 17 |
/** |
| 18 |
* useEffect hook. |
| 19 |
*/ |
| 20 |
useEffect(() => { |
| 21 |
const style = { |
| 22 |
gridTemplateColumns: `repeat(${routes.length}, minmax(0,1fr))`, |
| 23 |
}; |
| 24 |
setCalculatedStyles(style); |
| 25 |
}, [routes]); |
| 26 |
|
| 27 |
return ( |
| 28 |
<div style={calculatedStyle} className={"tableberg-menu-navigation"}> |
| 29 |
{routes.map(routeObj => { |
| 30 |
return ( |
| 31 |
<NavigationHeaderButton |
| 32 |
key={routeObj.getPath()} |
| 33 |
title={routeObj.getTitle()} |
| 34 |
targetPath={routeObj.getPath()} |
| 35 |
isActive={currentRoutePath === routeObj.getPath()} |
| 36 |
onClickHandler={setRoute} |
| 37 |
/> |
| 38 |
); |
| 39 |
})} |
| 40 |
</div> |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @module Navigation |
| 46 |
*/ |
| 47 |
export default Navigation; |
| 48 |
|