/
table-fixed-cell.jsx
78 lines (72 loc) · 1.78 KB
/
table-fixed-cell.jsx
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
import * as React from 'react';
import * as PropTypes from 'prop-types';
import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles';
const styles = theme => ({
dividerRight: {
borderRight: `1px solid ${theme.palette.divider}`,
},
dividerLeft: {
borderLeft: `1px solid ${theme.palette.divider}`,
},
fixedCell: {
backgroundColor: theme.palette.background.paper,
position: 'sticky',
zIndex: 300,
backgroundClip: 'padding-box',
},
selected: {
backgroundColor: 'inherit',
},
});
class FixedCellBase extends React.PureComponent {
render() {
const {
className,
classes,
component: CellPlaceholder,
position,
selected,
showLeftDivider,
showRightDivider,
side,
style,
...restProps
} = this.props;
return (
<CellPlaceholder
className={classNames({
[classes.dividerLeft]: showLeftDivider,
[classes.dividerRight]: showRightDivider,
[classes.fixedCell]: true,
[classes.selected]: selected,
}, className)}
style={{
...style,
[side]: position,
}}
{...restProps}
/>
);
}
}
FixedCellBase.propTypes = {
component: PropTypes.func.isRequired,
classes: PropTypes.object.isRequired,
className: PropTypes.string,
position: PropTypes.number,
selected: PropTypes.bool,
showLeftDivider: PropTypes.bool,
showRightDivider: PropTypes.bool,
side: PropTypes.string.isRequired,
style: PropTypes.object,
};
FixedCellBase.defaultProps = {
className: undefined,
position: undefined,
selected: false,
showLeftDivider: false,
showRightDivider: false,
style: null,
};
export const FixedCell = withStyles(styles, { name: 'TableFixedCell' })(FixedCellBase);