1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 09:50:31 +01:00
onion/js/components/ascribe_table/table_header_item.js

58 lines
1.8 KiB
JavaScript
Raw Permalink 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: {
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;