|
| 1 | +import React from "react"; |
| 2 | +import PropTypes from "prop-types"; |
| 3 | +import { |
| 4 | + Box, |
| 5 | + Checkbox, |
| 6 | + TableRow, |
| 7 | + TableCell, |
| 8 | + TableHead, |
| 9 | + TableSortLabel, |
| 10 | + Toolbar, |
| 11 | + Typography, |
| 12 | + OutlinedInput, |
| 13 | + InputAdornment, |
| 14 | +} from "@mui/material"; |
| 15 | + |
| 16 | +// Label Component |
| 17 | +const Label = ({ color, children }) => { |
| 18 | + const backgroundColors = { |
| 19 | + success: "success.main", |
| 20 | + error: "error.main", |
| 21 | + warning: "warning.main", |
| 22 | + info: "info.main", |
| 23 | + primary: "primary.main", |
| 24 | + secondary: "secondary.main", |
| 25 | + offerSent: "#4CAF50", |
| 26 | + }; |
| 27 | + |
| 28 | + return ( |
| 29 | + <Box |
| 30 | + sx={{ |
| 31 | + display: "inline-flex", |
| 32 | + alignItems: "center", |
| 33 | + justifyContent: "center", |
| 34 | + borderRadius: "8px", |
| 35 | + minWidth: 72, |
| 36 | + minHeight: 32, |
| 37 | + px: 1, |
| 38 | + color: "white", |
| 39 | + fontSize: "0.55rem", |
| 40 | + fontWeight: "bold", |
| 41 | + padding: "4px", |
| 42 | + backgroundColor: backgroundColors[color] || "error.main", |
| 43 | + }} |
| 44 | + > |
| 45 | + {children} |
| 46 | + </Box> |
| 47 | + ); |
| 48 | +}; |
| 49 | + |
| 50 | +Label.propTypes = { |
| 51 | + color: PropTypes.string.isRequired, |
| 52 | + children: PropTypes.node, |
| 53 | +}; |
| 54 | + |
| 55 | +// Iconify Component |
| 56 | +const Iconify = ({ icon, width = 20, sx, ...other }) => ( |
| 57 | + <Box |
| 58 | + component="span" |
| 59 | + sx={{ |
| 60 | + display: "inline-flex", |
| 61 | + alignItems: "center", |
| 62 | + justifyContent: "center", |
| 63 | + width, |
| 64 | + height: width, |
| 65 | + ...sx, |
| 66 | + }} |
| 67 | + {...other} |
| 68 | + > |
| 69 | + <i className={icon} /> |
| 70 | + </Box> |
| 71 | +); |
| 72 | + |
| 73 | +Iconify.propTypes = { |
| 74 | + sx: PropTypes.object, |
| 75 | + width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), |
| 76 | + icon: PropTypes.string.isRequired, |
| 77 | +}; |
| 78 | + |
| 79 | +// Scrollbar Component |
| 80 | +const Scrollbar = ({ children, sx, ...other }) => { |
| 81 | + return ( |
| 82 | + <Box sx={{ overflowX: "auto", ...sx }} {...other}> |
| 83 | + {children} |
| 84 | + </Box> |
| 85 | + ); |
| 86 | +}; |
| 87 | + |
| 88 | +Scrollbar.propTypes = { |
| 89 | + sx: PropTypes.object, |
| 90 | + children: PropTypes.node, |
| 91 | +}; |
| 92 | + |
| 93 | +const UserListHead = ({ |
| 94 | + order, |
| 95 | + orderBy, |
| 96 | + rowCount, |
| 97 | + headLabel, |
| 98 | + numSelected, |
| 99 | + onRequestSort, |
| 100 | + onSelectAllClick, |
| 101 | +}) => { |
| 102 | + const createSortHandler = (property) => (event) => { |
| 103 | + onRequestSort(event, property); |
| 104 | + }; |
| 105 | + |
| 106 | + return ( |
| 107 | + <TableHead |
| 108 | + sx={{ |
| 109 | + bgcolor: "grey.200", |
| 110 | + }} |
| 111 | + > |
| 112 | + <TableRow> |
| 113 | + <TableCell padding="checkbox"> |
| 114 | + <Checkbox |
| 115 | + indeterminate={numSelected > 0 && numSelected < rowCount} |
| 116 | + checked={rowCount > 0 && numSelected === rowCount} |
| 117 | + onChange={onSelectAllClick} |
| 118 | + /> |
| 119 | + </TableCell> |
| 120 | + {headLabel.map((headCell) => ( |
| 121 | + <TableCell |
| 122 | + key={headCell.id} |
| 123 | + align={headCell.alignRight ? "right" : "left"} |
| 124 | + sortDirection={orderBy === headCell.id ? order : false} |
| 125 | + > |
| 126 | + <TableSortLabel |
| 127 | + hideSortIcon |
| 128 | + active={orderBy === headCell.id} |
| 129 | + direction={orderBy === headCell.id ? order : "asc"} |
| 130 | + onClick={createSortHandler(headCell.id)} |
| 131 | + > |
| 132 | + {headCell.label} |
| 133 | + </TableSortLabel> |
| 134 | + </TableCell> |
| 135 | + ))} |
| 136 | + </TableRow> |
| 137 | + </TableHead> |
| 138 | + ); |
| 139 | +}; |
| 140 | + |
| 141 | +UserListHead.propTypes = { |
| 142 | + order: PropTypes.oneOf(["asc", "desc"]), |
| 143 | + orderBy: PropTypes.string, |
| 144 | + rowCount: PropTypes.number, |
| 145 | + headLabel: PropTypes.array, |
| 146 | + numSelected: PropTypes.number, |
| 147 | + onRequestSort: PropTypes.func, |
| 148 | + onSelectAllClick: PropTypes.func, |
| 149 | +}; |
| 150 | +const UserListToolbar = ({ |
| 151 | + numSelected, |
| 152 | + filterName, |
| 153 | + onFilterName, |
| 154 | + backgroundColor, |
| 155 | +}) => { |
| 156 | + return ( |
| 157 | + <Toolbar |
| 158 | + sx={{ |
| 159 | + height: 96, |
| 160 | + display: "flex", |
| 161 | + justifyContent: "space-between", |
| 162 | + padding: 1, |
| 163 | + backgroundColor: "background.paper", |
| 164 | + ...(numSelected > 0 && { |
| 165 | + color: "primary.main", |
| 166 | + bgcolor: "primary.lighter", |
| 167 | + }), |
| 168 | + }} |
| 169 | + > |
| 170 | + {numSelected > 0 ? ( |
| 171 | + <Typography component="div" variant="subtitle1"> |
| 172 | + {numSelected} selected |
| 173 | + </Typography> |
| 174 | + ) : ( |
| 175 | + <OutlinedInput |
| 176 | + value={filterName} |
| 177 | + onChange={onFilterName} |
| 178 | + placeholder="Search applicant..." |
| 179 | + startAdornment={ |
| 180 | + <InputAdornment position="start"> |
| 181 | + <Iconify |
| 182 | + icon="eva:search-fill" |
| 183 | + sx={{ color: "text.disabled", width: 20, height: 20 }} |
| 184 | + /> |
| 185 | + </InputAdornment> |
| 186 | + } |
| 187 | + sx={{ |
| 188 | + width: 240, |
| 189 | + transition: "all 0.3s", |
| 190 | + "&.Mui-focused": { |
| 191 | + width: 320, |
| 192 | + boxShadow: 8, |
| 193 | + }, |
| 194 | + "& fieldset": { |
| 195 | + borderWidth: `1px !important`, |
| 196 | + borderColor: "rgba(0, 0, 0, 0.23) !important", |
| 197 | + }, |
| 198 | + }} |
| 199 | + /> |
| 200 | + )} |
| 201 | + </Toolbar> |
| 202 | + ); |
| 203 | +}; |
| 204 | + |
| 205 | +UserListToolbar.propTypes = { |
| 206 | + numSelected: PropTypes.number, |
| 207 | + filterName: PropTypes.string, |
| 208 | + onFilterName: PropTypes.func, |
| 209 | +}; |
| 210 | + |
| 211 | +export { Label, Iconify, Scrollbar, UserListHead, UserListToolbar }; |
0 commit comments