2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import * as React from 'react';
19 import { NavLink, Link, Route } from 'react-router-dom';
21 import ListItem from '@mui/material/ListItem';
22 import ListItemIcon from '@mui/material/ListItemIcon';
23 import ListItemText from '@mui/material/ListItemText';
25 import { Theme } from '@mui/material/styles';
26 import { WithStyles } from '@mui/styles';
27 import withStyles from '@mui/styles/withStyles';
28 import createStyles from '@mui/styles/createStyles';
29 import { toAriaLabel } from '../../utilities/yangHelper';
31 const styles = (theme: Theme) => createStyles({
33 backgroundColor: theme.palette.action.selected
37 export interface IListItemLinkProps extends WithStyles<typeof styles> {
38 icon: JSX.Element | null;
39 primary: string | React.ComponentType;
40 secondary?: React.ComponentType;
46 export const ListItemLink = withStyles(styles)((props: IListItemLinkProps) => {
47 const { icon, primary: Primary, secondary: Secondary, classes, to, exact = false, external=false } = props;
48 const renderLink = (itemProps: any): JSX.Element => (
49 props.external ? <a target="_blank" href={to} { ...itemProps }></a> :
50 <NavLink exact={ exact } to={ to } activeClassName={ classes.active } { ...itemProps } />);
52 const ariaLabel = typeof Primary === 'string' ? toAriaLabel("link-to-"+Primary) : toAriaLabel("link-to-"+Primary.displayName);
55 <ListItem button component={ renderLink } aria-label={ariaLabel}>
57 ? <ListItemIcon>{ icon }</ListItemIcon>
60 { typeof Primary === 'string'
61 ? <ListItemText primary={ Primary } style={{ padding: 0 }} />
66 ? <Route exact={ exact } path={ to } component={ Secondary } />
74 export default ListItemLink;