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

53 lines
1.7 KiB
JavaScript
Raw Normal View History

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.string.isRequired,
columnName: React.PropTypes.string.isRequired,
canBeOrdered: React.PropTypes.bool.isRequired,
changeOrder: React.PropTypes.func.isRequired,
2015-05-21 14:51:15 +02:00
orderAsc: React.PropTypes.bool.isRequired,
orderBy: React.PropTypes.string.isRequired
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() {
2015-05-21 14:51:15 +02:00
if(this.props.canBeOrdered) {
if(this.props.columnName === this.props.orderBy) {
return (
<div
className={this.props.columnClasses + ' ascribe-table-header-column'}
onClick={this.changeOrder}>
<span>{this.props.displayName} <TableHeaderItemCarret orderAsc={this.props.orderAsc} /></span>
</div>
);
} else {
return (
<div
className={this.props.columnClasses + ' ascribe-table-header-column'}
onClick={this.changeOrder}>
<span>{this.props.displayName}</span>
</div>
);
}
} else {
return (
<div className={this.props.columnClasses + ' ascribe-table-header-column'}>
<span>
{this.props.displayName}
</span>
</div>
);
}
2015-05-21 14:03:56 +02:00
}
});
2015-05-21 14:51:15 +02:00
export default TableHeaderItem;