-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathDataTableHeadCell.js
More file actions
105 lines (92 loc) · 3.01 KB
/
DataTableHeadCell.js
File metadata and controls
105 lines (92 loc) · 3.01 KB
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
/**
=========================================================
* Material Dashboard 2 React - v2.1.0
=========================================================
* Product Page: https://www.creative-tim.com/product/material-dashboard-react
* Copyright 2022 Creative Tim (https://www.creative-tim.com)
Coded by www.creative-tim.com
=========================================================
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
// prop-types is a library for typechecking of props
import PropTypes from "prop-types";
// @mui material components
import Icon from "@mui/material/Icon";
// Material Dashboard 2 React components
import MDBox from "components/MDBox";
// Material Dashboard 2 React contexts
import { useMaterialUIController } from "context";
function DataTableHeadCell({ width, children, sorted, align, ...rest }) {
const [controller] = useMaterialUIController();
const { darkMode } = controller;
return (
<MDBox
component="th"
width={width}
py={1.5}
px={3}
sx={({ palette: { light }, borders: { borderWidth } }) => ({
borderBottom: `${borderWidth[1]} solid ${light.main}`,
})}
>
<MDBox
{...rest}
position="relative"
textAlign={align}
color={darkMode ? "red" : "dark"}
opacity={0.7}
sx={({ typography: { size, fontWeightBold } }) => ({
fontSize: size.xxa,
fontWeight: fontWeightBold,
textTransform: "uppercase",
cursor: sorted && "pointer",
userSelect: sorted && "none",
})}
>
{children}
{sorted && (
<MDBox
position="absolute"
top={0}
right={align !== "right" ? "16px" : 0}
left={align === "right" ? "-5px" : "unset"}
sx={({ typography: { size } }) => ({
fontSize: size.lg,
})}
>
<MDBox
position="absolute"
top={-6}
color={sorted === "asce" ? "text" : "secondary"}
opacity={sorted === "asce" ? 1 : 0.5}
>
<Icon>arrow_drop_up</Icon>
</MDBox>
<MDBox
position="absolute"
top={0}
color={sorted === "desc" ? "text" : "secondary"}
opacity={sorted === "desc" ? 1 : 0.5}
>
<Icon>arrow_drop_down</Icon>
</MDBox>
</MDBox>
)}
</MDBox>
</MDBox>
);
}
// Setting default values for the props of DataTableHeadCell
DataTableHeadCell.defaultProps = {
width: "auto",
sorted: "none",
align: "left",
};
// Typechecking props for the DataTableHeadCell
DataTableHeadCell.propTypes = {
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
children: PropTypes.node.isRequired,
sorted: PropTypes.oneOf([false, "none", "asce", "desc"]),
align: PropTypes.oneOf(["left", "right", "center"]),
};
export default DataTableHeadCell;