forked from TutulDevs/mui-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { | ||
Checkbox, | ||
TableCell, | ||
TableHead, | ||
TableRow, | ||
TableSortLabel, | ||
} from "@material-ui/core"; | ||
import { Box } from "@mui/system"; | ||
import { visuallyHidden } from "@mui/utils"; | ||
|
||
const headCells = [ | ||
{ | ||
id: "name", | ||
numeric: false, | ||
disablePadding: true, | ||
label: "Dessert (100g serving)", | ||
}, | ||
{ | ||
id: "calories", | ||
numeric: true, | ||
disablePadding: false, | ||
label: "Calories", | ||
}, | ||
{ | ||
id: "fat", | ||
numeric: true, | ||
disablePadding: false, | ||
label: "Fat (g)", | ||
}, | ||
{ | ||
id: "carbs", | ||
numeric: true, | ||
disablePadding: false, | ||
label: "Carbs (g)", | ||
}, | ||
{ | ||
id: "protein", | ||
numeric: true, | ||
disablePadding: false, | ||
label: "Protein (g)", | ||
}, | ||
]; | ||
|
||
const UserTableHead = (props) => { | ||
const { | ||
onSelectAllClick, | ||
order, | ||
orderBy, | ||
numSelected, | ||
rowCount, | ||
onRequestSort, | ||
} = props; | ||
|
||
// sort | ||
const createSortHandler = (property) => (e) => onRequestSort(e, property); | ||
|
||
return ( | ||
<TableHead> | ||
<TableRow> | ||
{/* ck box */} | ||
<TableCell padding="checkbox"> | ||
<Checkbox | ||
color="primary" | ||
indeterminate={numSelected > 0 && numSelected < rowCount} | ||
checked={rowCount > 0 && numSelected === rowCount} | ||
onChange={onSelectAllClick} | ||
inputProps={{ | ||
"aria-label": "select all users", | ||
}} | ||
/> | ||
</TableCell> | ||
|
||
{/* rest of the cells */} | ||
{headCells.map((cell) => ( | ||
<TableCell | ||
key={cell.id} | ||
align={cell.numeric ? "right" : "left"} | ||
padding={cell.disablePadding ? "none" : "normal"} | ||
sortDirection={orderBy === cell.id ? order : false} | ||
> | ||
<TableSortLabel | ||
active={orderBy === cell.id} | ||
direction={orderBy === cell.id ? order : "asc"} | ||
onClick={createSortHandler(cell.id)} | ||
> | ||
{cell.label} | ||
|
||
{/* hidden box */} | ||
{orderBy === cell.id ? ( | ||
<Box component="span" sx={visuallyHidden}> | ||
{order === "desc" ? "sorted descending" : "sorted ascending"} | ||
</Box> | ||
) : null} | ||
</TableSortLabel> | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
); | ||
}; | ||
|
||
export default UserTableHead; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters