-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtable-heading-cell.js
More file actions
64 lines (53 loc) · 1.67 KB
/
table-heading-cell.js
File metadata and controls
64 lines (53 loc) · 1.67 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
import React from 'react';
import { getStyleProperties } from './utils/styleHelper';
class TableHeadingCell extends React.Component {
constructor(props, context) {
super(props, context);
this._handleClick = this._handleClick.bind(this);
this._handleHover = this._handleHover.bind(this);
}
getSortIcon() {
const { sorted, sortAscending, icons } = this.props;
if (sorted) {
return sortAscending ? icons.sortAscending : icons.sortDescending;
}
}
render() {
const { styles, settings, alignment, headerAlignment } = this.props;
const style = styles.getStyle({
useStyles: settings.useGriddleStyles,
styles: styles.inlineStyles,
styleName: 'columnTitle',
mergeStyles: alignment || headerAlignment ?
{textAlign: headerAlignment || alignment} :
null
});
const { className } = getStyleProperties(this.props, 'tableHeadingCell');
return (
<th
key={this.props.column}
style={style}
onMouseOver={this._handleHover}
onClick={this._handleClick}
className={className}
>
{this.props.title} { this.getSortIcon() }
</th>);
}
_handleHover() {
this.props.headingHover(this.props.column);
}
_handleClick() {
this.props.headingClick(this.props.column);
}
}
TableHeadingCell.propTypes = {
headingHover: React.PropTypes.func,
headingClick: React.PropTypes.func,
column: React.PropTypes.string,
headerAlignment: React.PropTypes.oneOf(['left', 'right', 'center']),
alignment: React.PropTypes.oneOf(['left', 'right', 'center']),
sortAscending: React.PropTypes.bool,
sorted: React.PropTypes.bool
};
export default TableHeadingCell;