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';
30 import { IconType } from '../../models/iconDefinition';
31 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
33 const styles = (theme: Theme) => createStyles({
35 backgroundColor: theme.palette.action.selected
39 export interface IListItemLinkProps extends WithStyles<typeof styles> {
40 icon: IconType | null;
41 primary: string | React.ComponentType;
42 secondary?: React.ComponentType;
48 export const ListItemLink = withStyles(styles)((props: IListItemLinkProps) => {
49 const { icon, primary: Primary, secondary: Secondary, classes, to, exact = false, external=false } = props;
50 const renderLink = (itemProps: any): JSX.Element => (
51 props.external ? <a target="_blank" href={to} { ...itemProps }></a> :
52 <NavLink exact={ exact } to={ to } activeClassName={ classes.active } { ...itemProps } />);
54 const customIconHeight = 22;
55 const ariaLabel = typeof Primary === 'string' ? toAriaLabel("link-to-"+Primary) : toAriaLabel("link-to-"+Primary.displayName);
57 //create menu icon, either using an faIcon or a link to a custom svg icon
58 //moved to one place for easier usage
59 const listItemIcon = icon && ( typeof icon === 'string' ? <img height={customIconHeight} src={icon} /> : <FontAwesomeIcon icon={icon} /> );
63 <ListItem button component={ renderLink } aria-label={ariaLabel}>
65 ? <ListItemIcon>{ listItemIcon }</ListItemIcon>
68 { typeof Primary === 'string'
69 ? <ListItemText primary={ Primary } style={{ padding: 0 }} />
74 ? <Route exact={ exact } path={ to } component={ Secondary } />
82 export default ListItemLink;