-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtable-heading-cell.js
More file actions
88 lines (73 loc) · 2.58 KB
/
table-heading-cell.js
File metadata and controls
88 lines (73 loc) · 2.58 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
import React from 'react';
import classnames from 'classnames';
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;
}
}
isSortable() {
const { column, renderProperties } = this.props;
const columnProperties = renderProperties.columnProperties[column];
if(columnProperties && columnProperties.hasOwnProperty('sortable') && columnProperties.sortable === false) {
return false;
}
return true;
}
render() {
const style = this.props.styles.getStyle({
styles: this.props.styles.inlineStyles,
styleName: 'columnTitle',
mergeStyles: {
width: this.props.columnProperty.width,
...(this.props.alignment || this.props.headerAlignment ? {textAlign: this.props.headerAlignment || this.props.alignment} : {}),
...this.props.style
}
});
const { className } = getStyleProperties(this.props, 'tableHeadingCell');
const classNames = classnames(className, this.props.columnProperty ? this.props.columnProperty.headerCssClassName : null)
const { sorted, state, title, sortAscending } = this.props;
const clickEvent = this.isSortable() ? this._handleClick : null;
return (
<th
key={this.props.column}
style={style}
onMouseOver={this._handleHover}
onClick={clickEvent}
className={classNames}
>
{this.props.hasOwnProperty('customHeadingComponent') ?
<this.props.customHeadingComponent
state={state}
title={title}
sorted={sorted}
sortAscending={sortAscending}
sortIcon={this.getSortIcon()} /> :
[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;