1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 17:45:10 +01:00
onion/js/components/ascribe_table/table_header_item.js

59 lines
1.9 KiB
JavaScript
Raw Normal View History

'use strict';
2015-05-21 14:03:56 +02:00
import React from 'react';
2015-05-21 14:51:15 +02:00
import TableHeaderItemCarret from './table_header_item_carret';
2015-05-21 14:03:56 +02:00
let TableHeaderItem = React.createClass({
2015-05-21 14:51:15 +02:00
propTypes: {
columnClasses: React.PropTypes.string.isRequired,
displayName: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.element
]).isRequired,
2015-05-21 14:51:15 +02:00
columnName: React.PropTypes.string.isRequired,
canBeOrdered: React.PropTypes.bool,
changeOrder: React.PropTypes.func,
orderAsc: React.PropTypes.bool,
2015-07-01 10:53:40 +02:00
orderBy: React.PropTypes.string,
className: React.PropTypes.string
2015-05-21 14:51:15 +02:00
},
changeOrder() {
this.props.changeOrder(this.props.columnName, !this.props.orderAsc);
2015-05-21 14:51:15 +02:00
},
2015-05-21 14:03:56 +02:00
render() {
if(this.props.canBeOrdered && this.props.changeOrder && this.props.orderAsc != null && this.props.orderBy) {
2015-05-21 14:51:15 +02:00
if(this.props.columnName === this.props.orderBy) {
return (
<th
2015-07-01 10:53:40 +02:00
className={'ascribe-table-header-column ' + this.props.className}
2015-05-21 14:51:15 +02:00
onClick={this.changeOrder}>
<span>{this.props.displayName} <TableHeaderItemCarret orderAsc={this.props.orderAsc} /></span>
2015-06-04 17:21:38 +02:00
</th>
2015-05-21 14:51:15 +02:00
);
} else {
return (
<th
2015-07-01 10:53:40 +02:00
className={'ascribe-table-header-column ' + this.props.className}
2015-05-21 14:51:15 +02:00
onClick={this.changeOrder}>
<span>{this.props.displayName}</span>
2015-06-04 17:21:38 +02:00
</th>
2015-05-21 14:51:15 +02:00
);
}
} else {
return (
2015-07-01 10:53:40 +02:00
<th className={'ascribe-table-header-column ' + this.props.className}>
2015-05-21 14:51:15 +02:00
<span>
{this.props.displayName}
</span>
2015-06-04 17:21:38 +02:00
</th>
2015-05-21 14:51:15 +02:00
);
}
2015-05-21 14:03:56 +02:00
}
});
2015-05-21 14:51:15 +02:00
export default TableHeaderItem;