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 { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/styles';
21 import IconButton from '@material-ui/core/IconButton';
22 import Tooltip from '@material-ui/core/Tooltip';
23 import Toolbar from '@material-ui/core/Toolbar';
24 import Typography from '@material-ui/core/Typography';
25 import DeleteIcon from '@material-ui/icons/Delete';
26 import MoreIcon from '@material-ui/icons/MoreVert';
27 import FilterListIcon from '@material-ui/icons/FilterList';
28 import MenuItem from '@material-ui/core/MenuItem';
29 import Menu from '@material-ui/core/Menu';
30 import { lighten } from '@material-ui/core/styles/colorManipulator';
31 import { SvgIconProps } from '@material-ui/core/SvgIcon/SvgIcon';
33 const styles = (theme: Theme) => createStyles({
35 paddingRight: theme.spacing(1),
38 theme.palette.type === 'light'
40 color: theme.palette.secondary.main,
41 backgroundColor: lighten(theme.palette.secondary.light, 0.85),
44 color: theme.palette.text.primary,
45 backgroundColor: theme.palette.secondary.dark,
51 color: theme.palette.text.secondary,
65 interface ITableToolbarComponentProps extends WithStyles<typeof styles> {
66 numSelected: number | null;
69 customActionButtons?: { icon: React.ComponentType<SvgIconProps>, tooltip?: string, onClick: () => void }[];
70 onToggleFilter: () => void;
71 onExportToCsv: () => void;
74 class TableToolbarComponent extends React.Component<ITableToolbarComponentProps, { anchorEl: EventTarget & HTMLElement | null }> {
75 constructor(props: ITableToolbarComponentProps) {
83 private handleMenu = (event: React.MouseEvent<HTMLElement>) => {
84 this.setState({ anchorEl: event.currentTarget });
87 private handleClose = () => {
88 this.setState({ anchorEl: null });
91 const { numSelected, classes } = this.props;
92 const open = !!this.state.anchorEl;
93 const buttonPrefix = this.props.tableId !== undefined ? this.props.tableId + '-' : '';
95 <Toolbar className={`${classes.root} ${numSelected && numSelected > 0 ? classes.highlight : ''} `} >
96 <div className={classes.title}>
97 {numSelected && numSelected > 0 ? (
98 <Typography color="inherit" variant="subtitle1">
99 {numSelected} selected
102 <Typography variant="h5" id="tableTitle">
103 {this.props.title || null}
107 <div className={classes.spacer} />
108 <div className={classes.actions}>
109 {this.props.customActionButtons
110 ? this.props.customActionButtons.map((action, ind) => (
111 <Tooltip key={`custom-action-${ind}`} title={action.tooltip}>
112 <IconButton aria-label={buttonPrefix + `custom-action-${ind}`} onClick={() => action.onClick()}>
118 {numSelected && numSelected > 0 ? (
119 <Tooltip title="Delete">
120 <IconButton aria-label={buttonPrefix + "delete"}>
125 <Tooltip title="Filter list">
126 <IconButton aria-label={buttonPrefix + "filter-list"} onClick={() => { this.props.onToggleFilter && this.props.onToggleFilter() }}>
131 <Tooltip title="Actions">
132 <IconButton color="inherit"
133 aria-owns={open ? 'menu-appbar' : undefined}
135 onClick={this.handleMenu} >
139 <Menu id="menu-appbar" anchorEl={this.state.anchorEl} anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
140 transformOrigin={{ vertical: 'top', horizontal: 'right' }} open={open} onClose={this.handleClose} >
141 <MenuItem onClick={this.props.onExportToCsv}>Export as CSV</MenuItem>
149 export const TableToolbar = withStyles(styles)(TableToolbarComponent);