-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
/
TableRow.js
107 lines (99 loc) · 2.75 KB
/
TableRow.js
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
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import makeStyles from '../styles/makeStyles';
import Tablelvl2Context from '../Table/Tablelvl2Context';
export const styles = theme => ({
/* Styles applied to the root element. */
root: {
color: 'inherit',
display: 'table-row',
verticalAlign: 'middle',
// We disable the focus ring for mouse, touch and keyboard users.
outline: 'none',
'&$selected': {
backgroundColor:
theme.palette.type === 'light'
? 'rgba(0, 0, 0, 0.04)' // grey[100]
: 'rgba(255, 255, 255, 0.08)',
},
'&$hover:hover': {
backgroundColor:
theme.palette.type === 'light'
? 'rgba(0, 0, 0, 0.07)' // grey[200]
: 'rgba(255, 255, 255, 0.14)',
},
},
/* Styles applied to the root element if `selected={true}`. */
selected: {},
/* Styles applied to the root element if `hover={true}`. */
hover: {},
/* Styles applied to the root element if table variant="head". */
head: {},
/* Styles applied to the root element if table variant="footer". */
footer: {},
});
const useStyles = makeStyles(styles, { name: 'MuiTableRow' });
/**
* Will automatically set dynamic row height
* based on the material table element parent (head, body, etc).
*/
const TableRow = React.forwardRef(function TableRow(props, ref) {
const { classes: _, className, component: Component, hover, selected, ...other } = props;
const tablelvl2 = React.useContext(Tablelvl2Context);
const classes = useStyles(props);
return (
<Component
ref={ref}
className={clsx(
classes.root,
{
[classes.head]: tablelvl2 && tablelvl2.variant === 'head',
[classes.footer]: tablelvl2 && tablelvl2.variant === 'footer',
[classes.hover]: hover,
[classes.selected]: selected,
},
className,
)}
{...other}
/>
);
});
TableRow.propTypes = {
/**
* Should be valid <tr> children such as `TableCell`.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the table row will shade on hover.
*/
hover: PropTypes.bool,
/**
* If `true`, the table row will have the selected shading.
*/
selected: PropTypes.bool,
};
TableRow.defaultProps = {
component: 'tr',
hover: false,
selected: false,
};
TableRow.useStyles = useStyles;
TableRow.options = {
name: 'MuiTableRow',
};
export default TableRow;