Browse Source

header and option table

amenpunk 3 years ago
parent
commit
c7bf78531a
3 changed files with 679 additions and 280 deletions
  1. 9 0
      src/App.css
  2. 336 125
      src/Components/Register/temp.js
  3. 334 155
      src/Pages/Contras.jsx

+ 9 - 0
src/App.css

@@ -195,3 +195,12 @@
195 195
     margin-bottom: 20px;
196 196
     padding-bottom: 20px;
197 197
 }
198
+#pass_footer_row{
199
+    display: flex;
200
+}
201
+
202
+.css-11bfvty-MuiToolbar-root-MuiTablePagination-toolbar{
203
+    padding-top: 10px;
204
+    align-items: baseline !important;
205
+}
206
+

+ 336 - 125
src/Components/Register/temp.js

@@ -1,109 +1,272 @@
1 1
 import * as React from 'react';
2 2
 import PropTypes from 'prop-types';
3
-import { useTheme } from '@mui/material/styles';
3
+import { alpha } from '@mui/material/styles';
4 4
 import Box from '@mui/material/Box';
5 5
 import Table from '@mui/material/Table';
6 6
 import TableBody from '@mui/material/TableBody';
7 7
 import TableCell from '@mui/material/TableCell';
8 8
 import TableContainer from '@mui/material/TableContainer';
9
-import TableFooter from '@mui/material/TableFooter';
9
+import TableHead from '@mui/material/TableHead';
10 10
 import TablePagination from '@mui/material/TablePagination';
11 11
 import TableRow from '@mui/material/TableRow';
12
+import TableSortLabel from '@mui/material/TableSortLabel';
13
+import Toolbar from '@mui/material/Toolbar';
14
+import Typography from '@mui/material/Typography';
12 15
 import Paper from '@mui/material/Paper';
16
+import Checkbox from '@mui/material/Checkbox';
13 17
 import IconButton from '@mui/material/IconButton';
14
-import FirstPageIcon from '@mui/icons-material/FirstPage';
15
-import KeyboardArrowLeft from '@mui/icons-material/KeyboardArrowLeft';
16
-import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight';
17
-import LastPageIcon from '@mui/icons-material/LastPage';
18
+import Tooltip from '@mui/material/Tooltip';
19
+import FormControlLabel from '@mui/material/FormControlLabel';
20
+import Switch from '@mui/material/Switch';
21
+import DeleteIcon from '@mui/icons-material/Delete';
22
+import FilterListIcon from '@mui/icons-material/FilterList';
23
+import { visuallyHidden } from '@mui/utils';
18 24
 
19
-function TablePaginationActions(props) {
20
-  const theme = useTheme();
21
-  const { count, page, rowsPerPage, onPageChange } = props;
22
-
23
-  const handleFirstPageButtonClick = (event) => {
24
-    onPageChange(event, 0);
25
+function createData(name, calories, fat, carbs, protein) {
26
+  return {
27
+    name,
28
+    calories,
29
+    fat,
30
+    carbs,
31
+    protein,
25 32
   };
33
+}
26 34
 
27
-  const handleBackButtonClick = (event) => {
28
-    onPageChange(event, page - 1);
29
-  };
35
+const rows = [
36
+  createData('Cupcake', 305, 3.7, 67, 4.3),
37
+  createData('Donut', 452, 25.0, 51, 4.9),
38
+  createData('Eclair', 262, 16.0, 24, 6.0),
39
+  createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
40
+  createData('Gingerbread', 356, 16.0, 49, 3.9),
41
+  createData('Honeycomb', 408, 3.2, 87, 6.5),
42
+  createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
43
+  createData('Jelly Bean', 375, 0.0, 94, 0.0),
44
+  createData('KitKat', 518, 26.0, 65, 7.0),
45
+  createData('Lollipop', 392, 0.2, 98, 0.0),
46
+  createData('Marshmallow', 318, 0, 81, 2.0),
47
+  createData('Nougat', 360, 19.0, 9, 37.0),
48
+  createData('Oreo', 437, 18.0, 63, 4.0),
49
+];
30 50
 
31
-  const handleNextButtonClick = (event) => {
32
-    onPageChange(event, page + 1);
33
-  };
51
+function descendingComparator(a, b, orderBy) {
52
+  if (b[orderBy] < a[orderBy]) {
53
+    return -1;
54
+  }
55
+  if (b[orderBy] > a[orderBy]) {
56
+    return 1;
57
+  }
58
+  return 0;
59
+}
60
+
61
+function getComparator(order, orderBy) {
62
+  return order === 'desc'
63
+    ? (a, b) => descendingComparator(a, b, orderBy)
64
+    : (a, b) => -descendingComparator(a, b, orderBy);
65
+}
66
+
67
+// This method is created for cross-browser compatibility, if you don't
68
+// need to support IE11, you can use Array.prototype.sort() directly
69
+function stableSort(array, comparator) {
70
+  const stabilizedThis = array.map((el, index) => [el, index]);
71
+  stabilizedThis.sort((a, b) => {
72
+    const order = comparator(a[0], b[0]);
73
+    if (order !== 0) {
74
+      return order;
75
+    }
76
+    return a[1] - b[1];
77
+  });
78
+  return stabilizedThis.map((el) => el[0]);
79
+}
34 80
 
35
-  const handleLastPageButtonClick = (event) => {
36
-    onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
81
+const headCells = [
82
+  {
83
+    id: 'name',
84
+    numeric: false,
85
+    disablePadding: true,
86
+    label: 'Dessert (100g serving)',
87
+  },
88
+  {
89
+    id: 'calories',
90
+    numeric: true,
91
+    disablePadding: false,
92
+    label: 'Calories',
93
+  },
94
+  {
95
+    id: 'fat',
96
+    numeric: true,
97
+    disablePadding: false,
98
+    label: 'Fat (g)',
99
+  },
100
+  {
101
+    id: 'carbs',
102
+    numeric: true,
103
+    disablePadding: false,
104
+    label: 'Carbs (g)',
105
+  },
106
+  {
107
+    id: 'protein',
108
+    numeric: true,
109
+    disablePadding: false,
110
+    label: 'Protein (g)',
111
+  },
112
+];
113
+
114
+function EnhancedTableHead(props) {
115
+
116
+  const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } =
117
+    props;
118
+  const createSortHandler = (property) => (event) => {
119
+    onRequestSort(event, property);
37 120
   };
38 121
 
39 122
   return (
40
-    <Box sx={{ flexShrink: 0, ml: 2.5 }}>
41
-      <IconButton
42
-        onClick={handleFirstPageButtonClick}
43
-        disabled={page === 0}
44
-        aria-label="first page"
45
-      >
46
-        {theme.direction === 'rtl' ? <LastPageIcon /> : <FirstPageIcon />}
47
-      </IconButton>
48
-      <IconButton
49
-        onClick={handleBackButtonClick}
50
-        disabled={page === 0}
51
-        aria-label="previous page"
52
-      >
53
-        {theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
54
-      </IconButton>
55
-      <IconButton
56
-        onClick={handleNextButtonClick}
57
-        disabled={page >= Math.ceil(count / rowsPerPage) - 1}
58
-        aria-label="next page"
59
-      >
60
-        {theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
61
-      </IconButton>
62
-      <IconButton
63
-        onClick={handleLastPageButtonClick}
64
-        disabled={page >= Math.ceil(count / rowsPerPage) - 1}
65
-        aria-label="last page"
66
-      >
67
-        {theme.direction === 'rtl' ? <FirstPageIcon /> : <LastPageIcon />}
68
-      </IconButton>
69
-    </Box>
123
+    <TableHead>
124
+      <TableRow>
125
+        <TableCell padding="checkbox">
126
+          <Checkbox
127
+            color="primary"
128
+            indeterminate={numSelected > 0 && numSelected < rowCount}
129
+            checked={rowCount > 0 && numSelected === rowCount}
130
+            onChange={onSelectAllClick}
131
+            inputProps={{
132
+              'aria-label': 'select all desserts',
133
+            }}
134
+          />
135
+        </TableCell>
136
+        {headCells.map((headCell) => (
137
+          <TableCell
138
+            key={headCell.id}
139
+            align={headCell.numeric ? 'right' : 'left'}
140
+            padding={headCell.disablePadding ? 'none' : 'normal'}
141
+            sortDirection={orderBy === headCell.id ? order : false}
142
+          >
143
+            <TableSortLabel
144
+              active={orderBy === headCell.id}
145
+              direction={orderBy === headCell.id ? order : 'asc'}
146
+              onClick={createSortHandler(headCell.id)}
147
+            >
148
+              {headCell.label}
149
+              {orderBy === headCell.id ? (
150
+                <Box component="span" sx={visuallyHidden}>
151
+                  {order === 'desc' ? 'sorted descending' : 'sorted ascending'}
152
+                </Box>
153
+              ) : null}
154
+            </TableSortLabel>
155
+          </TableCell>
156
+        ))}
157
+      </TableRow>
158
+    </TableHead>
70 159
   );
71 160
 }
72 161
 
73
-TablePaginationActions.propTypes = {
74
-  count: PropTypes.number.isRequired,
75
-  onPageChange: PropTypes.func.isRequired,
76
-  page: PropTypes.number.isRequired,
77
-  rowsPerPage: PropTypes.number.isRequired,
162
+EnhancedTableHead.propTypes = {
163
+  numSelected: PropTypes.number.isRequired,
164
+  onRequestSort: PropTypes.func.isRequired,
165
+  onSelectAllClick: PropTypes.func.isRequired,
166
+  order: PropTypes.oneOf(['asc', 'desc']).isRequired,
167
+  orderBy: PropTypes.string.isRequired,
168
+  rowCount: PropTypes.number.isRequired,
78 169
 };
79 170
 
80
-function createData(name, calories, fat) {
81
-  return { name, calories, fat };
82
-}
171
+const EnhancedTableToolbar = (props) => {
83 172
 
84
-const rows = [
85
-  createData('Cupcake', 305, 3.7),
86
-  createData('Donut', 452, 25.0),
87
-  createData('Eclair', 262, 16.0),
88
-  createData('Frozen yoghurt', 159, 6.0),
89
-  createData('Gingerbread', 356, 16.0),
90
-  createData('Honeycomb', 408, 3.2),
91
-  createData('Ice cream sandwich', 237, 9.0),
92
-  createData('Jelly Bean', 375, 0.0),
93
-  createData('KitKat', 518, 26.0),
94
-  createData('Lollipop', 392, 0.2),
95
-  createData('Marshmallow', 318, 0),
96
-  createData('Nougat', 360, 19.0),
97
-  createData('Oreo', 437, 18.0),
98
-].sort((a, b) => (a.calories < b.calories ? -1 : 1));
99
-
100
-export default function CustomPaginationActionsTable() {
173
+  const { numSelected } = props;
174
+
175
+  return (
176
+    <Toolbar
177
+      sx={{
178
+        pl: { sm: 2 },
179
+        pr: { xs: 1, sm: 1 },
180
+        ...(numSelected > 0 && {
181
+          bgcolor: (theme) =>
182
+            alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity),
183
+        }),
184
+      }}
185
+    >
186
+      {numSelected > 0 ? (
187
+        <Typography
188
+          sx={{ flex: '1 1 100%' }}
189
+          color="inherit"
190
+          variant="subtitle1"
191
+          component="div"
192
+        >
193
+          {numSelected} selected
194
+        </Typography>
195
+      ) : (
196
+        <Typography
197
+          sx={{ flex: '1 1 100%' }}
198
+          variant="h6"
199
+          id="tableTitle"
200
+          component="div"
201
+        >
202
+          Nutrition
203
+        </Typography>
204
+      )}
205
+
206
+      {numSelected > 0 ? (
207
+        <Tooltip title="Delete">
208
+          <IconButton>
209
+            <DeleteIcon />
210
+          </IconButton>
211
+        </Tooltip>
212
+      ) : (
213
+        <Tooltip title="Filter list">
214
+          <IconButton>
215
+            <FilterListIcon />
216
+          </IconButton>
217
+        </Tooltip>
218
+      )}
219
+    </Toolbar>
220
+  );
221
+};
222
+
223
+EnhancedTableToolbar.propTypes = {
224
+  numSelected: PropTypes.number.isRequired,
225
+};
226
+
227
+export default function EnhancedTable() {
228
+
229
+  const [order, setOrder] = React.useState('asc');
230
+  const [orderBy, setOrderBy] = React.useState('calories');
231
+  const [selected, setSelected] = React.useState([]);
101 232
   const [page, setPage] = React.useState(0);
233
+  const [dense, setDense] = React.useState(false);
102 234
   const [rowsPerPage, setRowsPerPage] = React.useState(5);
103 235
 
104
-  // Avoid a layout jump when reaching the last page with empty rows.
105
-  const emptyRows =
106
-    page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
236
+  const handleRequestSort = (event, property) => {
237
+    const isAsc = orderBy === property && order === 'asc';
238
+    setOrder(isAsc ? 'desc' : 'asc');
239
+    setOrderBy(property);
240
+  };
241
+
242
+  const handleSelectAllClick = (event) => {
243
+    if (event.target.checked) {
244
+      const newSelecteds = rows.map((n) => n.name);
245
+      setSelected(newSelecteds);
246
+      return;
247
+    }
248
+    setSelected([]);
249
+  };
250
+
251
+  const handleClick = (event, name) => {
252
+    const selectedIndex = selected.indexOf(name);
253
+    let newSelected = [];
254
+
255
+    if (selectedIndex === -1) {
256
+      newSelected = newSelected.concat(selected, name);
257
+    } else if (selectedIndex === 0) {
258
+      newSelected = newSelected.concat(selected.slice(1));
259
+    } else if (selectedIndex === selected.length - 1) {
260
+      newSelected = newSelected.concat(selected.slice(0, -1));
261
+    } else if (selectedIndex > 0) {
262
+      newSelected = newSelected.concat(
263
+        selected.slice(0, selectedIndex),
264
+        selected.slice(selectedIndex + 1),
265
+      );
266
+    }
267
+
268
+    setSelected(newSelected);
269
+  };
107 270
 
108 271
   const handleChangePage = (event, newPage) => {
109 272
     setPage(newPage);
@@ -114,54 +277,102 @@ export default function CustomPaginationActionsTable() {
114 277
     setPage(0);
115 278
   };
116 279
 
280
+  const handleChangeDense = (event) => {
281
+    setDense(event.target.checked);
282
+  };
283
+
284
+  const isSelected = (name) => selected.indexOf(name) !== -1;
285
+
286
+  // Avoid a layout jump when reaching the last page with empty rows.
287
+  const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
288
+
117 289
   return (
118
-    <TableContainer component={Paper}>
119
-      <Table sx={{ minWidth: 500 }} aria-label="custom pagination table">
120
-        <TableBody>
121
-          {(rowsPerPage > 0
122
-            ? rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
123
-            : rows
124
-          ).map((row) => (
125
-            <TableRow key={row.name}>
126
-              <TableCell component="th" scope="row">
127
-                {row.name}
128
-              </TableCell>
129
-              <TableCell style={{ width: 160 }} align="right">
130
-                {row.calories}
131
-              </TableCell>
132
-              <TableCell style={{ width: 160 }} align="right">
133
-                {row.fat}
134
-              </TableCell>
135
-            </TableRow>
136
-          ))}
137
-
138
-          {emptyRows > 0 && (
139
-            <TableRow style={{ height: 53 * emptyRows }}>
140
-              <TableCell colSpan={6} />
141
-            </TableRow>
142
-          )}
143
-        </TableBody>
144
-        <TableFooter>
145
-          <TableRow>
146
-            <TablePagination
147
-              rowsPerPageOptions={[5, 10, 25, { label: 'All', value: -1 }]}
148
-              colSpan={3}
149
-              count={rows.length}
150
-              rowsPerPage={rowsPerPage}
151
-              page={page}
152
-              SelectProps={{
153
-                inputProps: {
154
-                  'aria-label': 'rows per page',
155
-                },
156
-                native: true,
157
-              }}
158
-              onPageChange={handleChangePage}
159
-              onRowsPerPageChange={handleChangeRowsPerPage}
160
-              ActionsComponent={TablePaginationActions}
290
+    <Box sx={{ width: '100%' }}>
291
+      <Paper sx={{ width: '100%', mb: 2 }}>
292
+        <EnhancedTableToolbar numSelected={selected.length} />
293
+        <TableContainer>
294
+          <Table
295
+            sx={{ minWidth: 750 }}
296
+            aria-labelledby="tableTitle"
297
+            size={dense ? 'small' : 'medium'}
298
+          >
299
+            <EnhancedTableHead
300
+              numSelected={selected.length}
301
+              order={order}
302
+              orderBy={orderBy}
303
+              onSelectAllClick={handleSelectAllClick}
304
+              onRequestSort={handleRequestSort}
305
+              rowCount={rows.length}
161 306
             />
162
-          </TableRow>
163
-        </TableFooter>
164
-      </Table>
165
-    </TableContainer>
307
+            <TableBody>
308
+              {/* if you don't need to support IE11, you can replace the `stableSort` call with:
309
+                 rows.slice().sort(getComparator(order, orderBy)) */}
310
+              {stableSort(rows, getComparator(order, orderBy))
311
+                .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
312
+                .map((row, index) => {
313
+                  const isItemSelected = isSelected(row.name);
314
+                  const labelId = `enhanced-table-checkbox-${index}`;
315
+
316
+                  return (
317
+                    <TableRow
318
+                      hover
319
+                      onClick={(event) => handleClick(event, row.name)}
320
+                      role="checkbox"
321
+                      aria-checked={isItemSelected}
322
+                      tabIndex={-1}
323
+                      key={row.name}
324
+                      selected={isItemSelected}
325
+                    >
326
+                      <TableCell padding="checkbox">
327
+                        <Checkbox
328
+                          color="primary"
329
+                          checked={isItemSelected}
330
+                          inputProps={{
331
+                            'aria-labelledby': labelId,
332
+                          }}
333
+                        />
334
+                      </TableCell>
335
+                      <TableCell
336
+                        component="th"
337
+                        id={labelId}
338
+                        scope="row"
339
+                        padding="none"
340
+                      >
341
+                        {row.name}
342
+                      </TableCell>
343
+                      <TableCell align="right">{row.calories}</TableCell>
344
+                      <TableCell align="right">{row.fat}</TableCell>
345
+                      <TableCell align="right">{row.carbs}</TableCell>
346
+                      <TableCell align="right">{row.protein}</TableCell>
347
+                    </TableRow>
348
+                  );
349
+                })}
350
+              {emptyRows > 0 && (
351
+                <TableRow
352
+                  style={{
353
+                    height: (dense ? 33 : 53) * emptyRows,
354
+                  }}
355
+                >
356
+                  <TableCell colSpan={6} />
357
+                </TableRow>
358
+              )}
359
+            </TableBody>
360
+          </Table>
361
+        </TableContainer>
362
+        <TablePagination
363
+          rowsPerPageOptions={[5, 10, 25]}
364
+          component="div"
365
+          count={rows.length}
366
+          rowsPerPage={rowsPerPage}
367
+          page={page}
368
+          onPageChange={handleChangePage}
369
+          onRowsPerPageChange={handleChangeRowsPerPage}
370
+        />
371
+      </Paper>
372
+      <FormControlLabel
373
+        control={<Switch checked={dense} onChange={handleChangeDense} />}
374
+        label="Dense padding"
375
+      />
376
+    </Box>
166 377
   );
167 378
 }

+ 334 - 155
src/Pages/Contras.jsx

@@ -1,192 +1,371 @@
1 1
 import * as React from 'react';
2
-import PropTypes from 'prop-types';
3
-import { useTheme } from '@mui/material/styles';
2
+// import { useTheme } from '@mui/material/styles';
4 3
 
5 4
 import { 
6
-    Table, TableBody, TableCell, TableContainer, TableFooter, TableRow, TablePagination,
7
-    IconButton, Paper, Box, Card
5
+    Table, TableBody, TableCell, TableContainer, 
6
+    TableRow, TablePagination,
7
+    IconButton, Paper, Box,
8
+    Switch, FormControlLabel,Tooltip,
9
+    Checkbox, Typography, Toolbar,
10
+    TableSortLabel,TableHead
8 11
 } from '@mui/material';
9 12
 
10
-import { Row, Col, Container } from 'react-bootstrap';
13
+import { visuallyHidden } from '@mui/utils';
14
+
15
+import { alpha } from '@mui/material/styles';
16
+
17
+// import { Row, Col, Container } from 'react-bootstrap';
11 18
 
12 19
 import {
13
-    LastPage as LastPageIcon, 
14
-    KeyboardArrowRight,
15
-    KeyboardArrowLeft,
16
-    FirstPage as FirstPageIcon
20
+    Delete as DeleteIcon,
21
+    FilterList as FilterListIcon,
22
+    // LastPage as LastPageIcon, FirstPage as FirstPageIcon, KeyboardArrowRight, KeyboardArrowLeft,
17 23
 } from '@mui/icons-material/'
18 24
 
19
-function createData(name, calories, fat) {
20
-  return { name, calories, fat };
25
+function createData(name, calories, fat, carbs, protein) {
26
+    return {
27
+        name,
28
+        calories,
29
+        fat,
30
+        carbs,
31
+        protein,
32
+    };
21 33
 }
22 34
 
23
-function TablePaginationActions(props) {
35
+const rows = [
36
+    createData('Cupcake', 305, 3.7, 67, 4.3),
37
+    createData('Donut', 452, 25.0, 51, 4.9),
38
+    createData('Eclair', 262, 16.0, 24, 6.0),
39
+    createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
40
+    createData('Gingerbread', 356, 16.0, 49, 3.9),
41
+    createData('Honeycomb', 408, 3.2, 87, 6.5),
42
+    createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
43
+    createData('Jelly Bean', 375, 0.0, 94, 0.0),
44
+    createData('KitKat', 518, 26.0, 65, 7.0),
45
+    createData('Lollipop', 392, 0.2, 98, 0.0),
46
+    createData('Marshmallow', 318, 0, 81, 2.0),
47
+    createData('Nougat', 360, 19.0, 9, 37.0),
48
+    createData('Oreo', 437, 18.0, 63, 4.0),
49
+];
50
+
51
+function descendingComparator(a, b, orderBy) {
52
+    if (b[orderBy] < a[orderBy]) {
53
+        return -1;
54
+    }
55
+    if (b[orderBy] > a[orderBy]) {
56
+        return 1;
57
+    }
58
+    return 0;
59
+}
24 60
 
25
-    const theme = useTheme();
26
-    const { count, page, rowsPerPage, onPageChange } = props;
61
+function getComparator(order, orderBy) {
62
+    return order === 'desc'
63
+        ? (a, b) => descendingComparator(a, b, orderBy)
64
+        : (a, b) => -descendingComparator(a, b, orderBy);
65
+}
27 66
 
28
-    const handleFirstPageButtonClick = (event) => {
29
-        onPageChange(event, 0);
30
-    };
67
+const EnhancedTableToolbar = (props) => {
31 68
 
32
-    const handleBackButtonClick = (event) => {
33
-        onPageChange(event, page - 1);
34
-    };
69
+    const { numSelected } = props;
70
+    return (
71
+        <Toolbar
72
+            sx={{
73
+                pl: { sm: 2 },
74
+                pr: { xs: 1, sm: 1 },
75
+                ...(numSelected > 0 && {
76
+                    bgcolor: (theme) =>
77
+                        alpha(theme.palette.primary.main, theme.palette.action.activatedOpacity),
78
+                }),
79
+            }}
80
+        >
81
+            {numSelected > 0 ? (
82
+                <Typography
83
+                    sx={{ flex: '1 1 100%' }}
84
+                    color="inherit"
85
+                    variant="subtitle1"
86
+                    component="div"
87
+                >
88
+                    {numSelected} selected
89
+                </Typography>
90
+            ) : (
91
+                    <Typography
92
+                        sx={{ flex: '1 1 100%' }}
93
+                        variant="h6"
94
+                        id="tableTitle"
95
+                        component="div"
96
+                    >
97
+                        Nutrition
98
+                    </Typography>
99
+                )}
100
+
101
+            {numSelected > 0 ? (
102
+                <Tooltip title="Delete">
103
+                    <IconButton>
104
+                        <DeleteIcon />
105
+                    </IconButton>
106
+                </Tooltip>
107
+            ) : (
108
+                    <Tooltip title="Filter list">
109
+                        <IconButton>
110
+                            <FilterListIcon />
111
+                        </IconButton>
112
+                    </Tooltip>
113
+                )}
114
+        </Toolbar>
115
+    );
35 116
 
36
-    const handleNextButtonClick = (event) => {
37
-        onPageChange(event, page + 1);
38
-    };
117
+}
39 118
 
40
-    const handleLastPageButtonClick = (event) => {
41
-        onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
119
+function EnhancedTableHead(props) {
120
+    const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } =
121
+        props;
122
+    const createSortHandler = (property) => (event) => {
123
+        onRequestSort(event, property);
42 124
     };
43 125
 
44 126
     return (
45
-        <Box sx={{ flexShrink: 0, ml: 2.5 }}>
46
-        <IconButton
47
-        onClick={handleFirstPageButtonClick}
48
-        disabled={page === 0}
49
-        aria-label="first page"
50
-        >
51
-        {theme.direction === 'rtl' ? <LastPageIcon /> : <FirstPageIcon />}
52
-        </IconButton>
53
-        <IconButton
54
-        onClick={handleBackButtonClick}
55
-        disabled={page === 0}
56
-        aria-label="previous page"
57
-        >
58
-        {theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
59
-        </IconButton>
60
-        <IconButton
61
-        onClick={handleNextButtonClick}
62
-        disabled={page >= Math.ceil(count / rowsPerPage) - 1}
63
-        aria-label="next page"
64
-        >
65
-        {theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
66
-        </IconButton>
67
-        <IconButton
68
-        onClick={handleLastPageButtonClick}
69
-        disabled={page >= Math.ceil(count / rowsPerPage) - 1}
70
-        aria-label="last page"
71
-        >
72
-        {theme.direction === 'rtl' ? <FirstPageIcon /> : <LastPageIcon />}
73
-        </IconButton>
74
-        </Box>
127
+        <TableHead>
128
+            <TableRow>
129
+                <TableCell padding="checkbox">
130
+                    <Checkbox
131
+                        color="primary"
132
+                        indeterminate={numSelected > 0 && numSelected < rowCount}
133
+                        checked={rowCount > 0 && numSelected === rowCount}
134
+                        onChange={onSelectAllClick}
135
+                        inputProps={{
136
+                            'aria-label': 'select all desserts',
137
+                        }}
138
+                        />
139
+                </TableCell>
140
+                {headCells.map((headCell) => (
141
+                    <TableCell
142
+                        key={headCell.id}
143
+                        align={headCell.numeric ? 'right' : 'left'}
144
+                        padding={headCell.disablePadding ? 'none' : 'normal'}
145
+                        sortDirection={orderBy === headCell.id ? order : false}
146
+                    >
147
+                        <TableSortLabel
148
+                            style={{ fontWeight:'bold' }}
149
+                            active={orderBy === headCell.id}
150
+                            direction={orderBy === headCell.id ? order : 'asc'}
151
+                            onClick={createSortHandler(headCell.id)}
152
+                        >
153
+                            {headCell.label}
154
+                            {orderBy === headCell.id ? (
155
+                                <Box component="span" sx={visuallyHidden}>
156
+                                    {order === 'desc' ? 'sorted descending' : 'sorted ascending'}
157
+                                </Box>
158
+                            ) : null}
159
+                        </TableSortLabel>
160
+                    </TableCell>
161
+                ))}
162
+            </TableRow>
163
+        </TableHead>
75 164
     );
76 165
 }
77 166
 
167
+function stableSort(array, comparator) {
168
+    const stabilizedThis = array.map((el, index) => [el, index]);
169
+    stabilizedThis.sort((a, b) => {
170
+        const order = comparator(a[0], b[0]);
171
+        if (order !== 0) {
172
+            return order;
173
+        }
174
+        return a[1] - b[1];
175
+    });
176
+    return stabilizedThis.map((el) => el[0]);
177
+}
78 178
 
179
+const headCells = [
180
+    {
181
+        id: 'name',
182
+        numeric: false,
183
+        disablePadding: true,
184
+        label: 'Dessert (100g serving)',
185
+    },
186
+    {
187
+        id: 'calories',
188
+        numeric: true,
189
+        disablePadding: false,
190
+        label: 'Calories',
191
+    },
192
+    {
193
+        id: 'fat',
194
+        numeric: true,
195
+        disablePadding: false,
196
+        label: 'Fat (g)',
197
+    },
198
+    {
199
+        id: 'carbs',
200
+        numeric: true,
201
+        disablePadding: false,
202
+        label: 'Carbs (g)',
203
+    },
204
+    {
205
+        id: 'protein',
206
+        numeric: true,
207
+        disablePadding: false,
208
+        label: 'Protein (g)',
209
+    },
210
+];
79 211
 
80
-const rows = [
81
-  createData('Cupcake', 305, 3.7),
82
-  createData('Donut', 452, 25.0),
83
-  createData('Eclair', 262, 16.0),
84
-  createData('Frozen yoghurt', 159, 6.0),
85
-  createData('Gingerbread', 356, 16.0),
86
-  createData('Honeycomb', 408, 3.2),
87
-  createData('Ice cream sandwich', 237, 9.0),
88
-  createData('Jelly Bean', 375, 0.0),
89
-  createData('KitKat', 518, 26.0),
90
-  createData('Lollipop', 392, 0.2),
91
-  createData('Marshmallow', 318, 0),
92
-  createData('Nougat', 360, 19.0),
93
-  createData('Oreo', 437, 18.0),
94
-].sort((a, b) => (a.calories < b.calories ? -1 : 1));
95
-
96
-export function Contras() {
97
-  const [page, setPage] = React.useState(0);
98
-  const [rowsPerPage, setRowsPerPage] = React.useState(5);
99
-
100
-  // Avoid a layout jump when reaching the last page with empty rows.
101
-  const emptyRows =
102
-    page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
103
-
104
-  const handleChangePage = (event, newPage) => {
105
-    setPage(newPage);
106
-  };
107 212
 
108
-  const handleChangeRowsPerPage = (event) => {
109
-    setRowsPerPage(parseInt(event.target.value, 10));
110
-    setPage(0);
111
-  };
112 213
 
113
-  return (
214
+export function Contras() {
114 215
 
115
-        <div className="content-section">
116
-            <div className="main">
216
+    const [order, setOrder] = React.useState('asc');
217
+    const [orderBy, setOrderBy] = React.useState('calories');
218
+    const [selected, setSelected] = React.useState([]);
219
+    const [page, setPage] = React.useState(0);
220
+    const [dense, setDense] = React.useState(false);
221
+    const [rowsPerPage, setRowsPerPage] = React.useState(5);
222
+
223
+    const handleRequestSort = (event, property) => {
224
+        const isAsc = orderBy === property && order === 'asc';
225
+        setOrder(isAsc ? 'desc' : 'asc');
226
+        setOrderBy(property);
227
+    };
117 228
 
118
-      <Container>
229
+    const handleSelectAllClick = (event) => {
230
+        if (event.target.checked) {
231
+            const newSelecteds = rows.map((n) => n.name);
232
+            setSelected(newSelecteds);
233
+            return;
234
+        }
235
+        setSelected([]);
236
+    };
119 237
 
120
-      <Row id="password_header">
121
-        <Col>
122
-          <Card>
123
-          <h1>Buscar Contrasena</h1>
124
-          </Card>
125
-        </Col>
126
-      </Row>
238
+    const handleClick = (event, name) => {
239
+        const selectedIndex = selected.indexOf(name);
240
+        let newSelected = [];
241
+
242
+        if (selectedIndex === -1) {
243
+            newSelected = newSelected.concat(selected, name);
244
+        } else if (selectedIndex === 0) {
245
+            newSelected = newSelected.concat(selected.slice(1));
246
+        } else if (selectedIndex === selected.length - 1) {
247
+            newSelected = newSelected.concat(selected.slice(0, -1));
248
+        } else if (selectedIndex > 0) {
249
+            newSelected = newSelected.concat(
250
+                selected.slice(0, selectedIndex),
251
+                selected.slice(selectedIndex + 1),
252
+            );
253
+        }
254
+
255
+        setSelected(newSelected);
256
+    };
127 257
 
258
+    const handleChangePage = (event, newPage) => {
259
+        setPage(newPage);
260
+    };
128 261
 
129
-      <Row>
130
-      <Col>
262
+    const handleChangeRowsPerPage = (event) => {
263
+        setRowsPerPage(parseInt(event.target.value, 10));
264
+        setPage(0);
265
+    };
131 266
 
267
+    const handleChangeDense = (event) => {
268
+        setDense(event.target.checked);
269
+    };
132 270
 
271
+    const isSelected = (name) => selected.indexOf(name) !== -1;
272
+  
273
+    const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;
133 274
 
275
+    return (
134 276
 
135
-    <TableContainer component={Paper}>
136
-      <Table sx={{ minWidth: 500 }} aria-label="custom pagination table">
137
-        <TableBody>
138
-          {(rowsPerPage > 0
139
-            ? rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
140
-            : rows
141
-          ).map((row) => (
142
-            <TableRow key={row.name}>
143
-              <TableCell component="th" scope="row">
144
-                {row.name}
145
-              </TableCell>
146
-              <TableCell style={{ width: 160 }} align="right">
147
-                {row.calories}
148
-              </TableCell>
149
-              <TableCell style={{ width: 160 }} align="right">
150
-                {row.fat}
151
-              </TableCell>
152
-            </TableRow>
153
-          ))}
277
+        <div className="content-section">
278
+            <div className="main">
154 279
 
155
-          {emptyRows > 0 && (
156
-            <TableRow style={{ height: 53 * emptyRows }}>
157
-              <TableCell colSpan={6} />
158
-            </TableRow>
159
-          )}
160
-        </TableBody>
161
-        <TableFooter>
162
-          <TableRow>
163
-            <TablePagination
164
-              rowsPerPageOptions={[5, 10, 25, { label: 'All', value: -1 }]}
165
-              colSpan={3}
166
-              count={rows.length}
167
-              rowsPerPage={rowsPerPage}
168
-              page={page}
169
-              SelectProps={{
170
-                inputProps: {
171
-                  'aria-label': 'rows per page',
172
-                },
173
-                native: true,
174
-              }}
175
-              onPageChange={handleChangePage}
176
-              onRowsPerPageChange={handleChangeRowsPerPage}
177
-              ActionsComponent={TablePaginationActions}
178
-            />
179
-          </TableRow>
180
-        </TableFooter>
181
-      </Table>
182
-    </TableContainer>
183
-
184
-      </Col>
185
-      </Row>
186
-
187
-      </Container>
188
-
189
-      </div>
190
-      </div>
191
-  );
280
+                <Box sx={{ width: '100%' }}>
281
+                    <Paper sx={{ width: '100%', mb: 2 }}>
282
+                        <EnhancedTableToolbar numSelected={selected.length} />
283
+                        <TableContainer>
284
+                            <Table
285
+                                sx={{ minWidth: 750 }}
286
+                                aria-labelledby="tableTitle"
287
+                                size={dense ? 'small' : 'medium'}
288
+                            >
289
+                                <EnhancedTableHead
290
+                                    numSelected={selected.length}
291
+                                    order={order}
292
+                                    orderBy={orderBy}
293
+                                    onSelectAllClick={handleSelectAllClick}
294
+                                    onRequestSort={handleRequestSort}
295
+                                    rowCount={rows.length}
296
+                                    />
297
+                                <TableBody>
298
+                                    {/* if you don't need to support IE11, you can replace the `stableSort` call with:
299
+rows.slice().sort(getComparator(order, orderBy)) */}
300
+                                    {stableSort(rows, getComparator(order, orderBy))
301
+                                    .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
302
+                                    .map((row, index) => {
303
+                                        const isItemSelected = isSelected(row.name);
304
+                                        const labelId = `enhanced-table-checkbox-${index}`;
305
+
306
+                                        return (
307
+                                            <TableRow
308
+                                                hover
309
+                                                onClick={(event) => handleClick(event, row.name)}
310
+                                                role="checkbox"
311
+                                                aria-checked={isItemSelected}
312
+                                                tabIndex={-1}
313
+                                                key={row.name}
314
+                                                selected={isItemSelected}
315
+                                            >
316
+                                                <TableCell padding="checkbox">
317
+                                                    <Checkbox
318
+                                                        color="primary"
319
+                                                        checked={isItemSelected}
320
+                                                        inputProps={{
321
+                                                            'aria-labelledby': labelId,
322
+                                                        }}
323
+                                                        />
324
+                                                </TableCell>
325
+                                                <TableCell
326
+                                                    component="th"
327
+                                                    id={labelId}
328
+                                                    scope="row"
329
+                                                    padding="none"
330
+                                                >
331
+                                                    {row.name}
332
+                                                </TableCell>
333
+                                                <TableCell align="right">{row.calories}</TableCell>
334
+                                                <TableCell align="right">{row.fat}</TableCell>
335
+                                                <TableCell align="right">{row.carbs}</TableCell>
336
+                                                <TableCell align="right">{row.protein}</TableCell>
337
+                                            </TableRow>
338
+                                        );
339
+                                    })}
340
+                                    {emptyRows > 0 && (
341
+                                        <TableRow
342
+                                            style={{
343
+                                                height: (dense ? 33 : 53) * emptyRows,
344
+                                            }}
345
+                                        >
346
+                                            <TableCell colSpan={6} />
347
+                                        </TableRow>
348
+                                    )}
349
+                                </TableBody>
350
+                            </Table>
351
+                        </TableContainer>
352
+                        <TablePagination
353
+                            rowsPerPageOptions={[5, 10, 25]}
354
+                            component="div"
355
+                            count={rows.length}
356
+                            rowsPerPage={rowsPerPage}
357
+                            page={page}
358
+                            onPageChange={handleChangePage}
359
+                            onRowsPerPageChange={handleChangeRowsPerPage}
360
+                            />
361
+                    </Paper>
362
+                    <FormControlLabel
363
+                        control={<Switch checked={dense} onChange={handleChangeDense} />}
364
+                        label="Dense padding"
365
+                        />
366
+                </Box>
367
+
368
+            </div>
369
+        </div>
370
+    );
192 371
 }