/**
 * Copyright (c) 2018 Dell Inc., or its subsidiaries. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 */ import * as React from "react" ; import * as utils from "../../utils" ; import { ReactElement } from "react" ; import { NavLink } from "./NavLink" ; param { navLevel } for param { navType } for param { dataqa } for export type NavProps = { navLevel : NavLevel ; navType : NavType ; dataqa ? : string ; } ; export enum NavLevel { PRIMARY = "1" , SECONDARY = "2" } export enum NavType { HEADER = "NAV_TYPE_HEADER" , SIDE = "NAV_TYPE_SIDE" , SUB = "NAV_TYPE_SUB" } export class Nav extends React . PureComponent < NavProps > { private static classForNavType ( navType ) { switch ( navType ) { case NavType . HEADER : return "header-nav" ; case NavType . SIDE : return "sidenav" ; case NavType . SUB : return "subnav" ; default : return "header-nav" ; } } private static classForNavLevel ( navLevel ) { return "clr-nav-level-" + navLevel ; } private static maybeWrapInList ( navType , children ) { if ( navType === NavType . SUB ) { const wrappedChildren = React . Children . map ( children , child => { const childEl = child as ReactElement ; if ( childEl . type === NavLink ) return < li className = "nav-item" > { child } < /li>; return child ; } ) ; return < ul className = { "nav" } > { wrappedChildren } < /ul>; } return children ; } render ( ) { const { children , navLevel , navType , dataqa } = this . props ; const classList = [ Nav . classForNavType ( navType ) , Nav . classForNavLevel ( navLevel ) ] ; return ( < nav className = { utils . classNames ( classList ) } data - qa = { dataqa } > { Nav . maybeWrapInList ( navType , children ) } < /nav>); } }