1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles';
import DeleteIcon from '@material-ui/icons/Delete';
import ArchiveIcon from '@material-ui/icons/Archive';
import BookmarkIcon from '@material-ui/icons/Bookmark';
import FilterListIcon from '@material-ui/icons/FilterList';
import SearchIcon from '@material-ui/icons/Search';
import {
Toolbar,
Typography,
IconButton,
Tooltip,
FormControl,
Input,
InputAdornment,
} from '@material-ui/core';
import styles from './tableStyle-jss';
class TableToolbar extends React.Component {
state = {
showSearch: false,
}
toggleSearch() {
this.setState({ showSearch: !this.state.showSearch });
}
handleChange(event) {
event.persist();
this.props.onUserInput(event.target.value);
}
render() {
const { numSelected, classes, filterText } = this.props;
const { showSearch } = this.state;
return (
<Toolbar
className={classNames(classes.root, {
[classes.highlight]: numSelected > 0,
})}
>
<div className={classes.titleToolbar}>
{numSelected > 0 ? (
<Typography color="inherit" variant="subtitle1">
{numSelected}
{' '}
selected
</Typography>
) : (
<Typography variant="h6">Nutrition</Typography>
)}
</div>
<div className={classes.spacer} />
<div className={classes.actionsToolbar}>
{numSelected > 0 ? (
<div>
<Tooltip title="Bookmark">
<IconButton aria-label="Bookmark">
<BookmarkIcon />
</IconButton>
</Tooltip>
<Tooltip title="Archive">
<IconButton aria-label="Archive">
<ArchiveIcon />
</IconButton>
</Tooltip>
<Tooltip title="Delete">
<IconButton aria-label="Delete">
<DeleteIcon />
</IconButton>
</Tooltip>
</div>
) : (
<div className={classes.actions}>
{showSearch
&& (
<FormControl className={classNames(classes.textField)}>
<Input
id="search_filter"
type="text"
placeholder="Search Desert"
value={filterText}
onChange={(event) => this.handleChange(event)}
endAdornment={(
<InputAdornment position="end">
<IconButton aria-label="Search filter">
<SearchIcon />
</IconButton>
</InputAdornment>
)}
/>
</FormControl>
)
}
<Tooltip title="Filter list">
<IconButton
aria-label="Filter list"
className={classes.filterBtn}
onClick={() => this.toggleSearch()}
>
<FilterListIcon />
</IconButton>
</Tooltip>
</div>
)}
</div>
</Toolbar>
);
}
}
TableToolbar.propTypes = {
classes: PropTypes.object.isRequired,
filterText: PropTypes.string.isRequired,
onUserInput: PropTypes.func.isRequired,
numSelected: PropTypes.number.isRequired,
};
export default withStyles(styles)(TableToolbar);
|