1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00
onion/js/components/ascribe_table/table_header_item.js

60 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: {
displayElement: 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() {
const { canBeOrdered, changeOrder, className, columnName, displayElement, orderAsc, orderBy } = this.props;
if (canBeOrdered && changeOrder && orderAsc != null && orderBy) {
if (columnName === orderBy) {
2015-05-21 14:51:15 +02:00
return (
<th
className={'ascribe-table-header-column ' + className}
2015-05-21 14:51:15 +02:00
onClick={this.changeOrder}>
<span>{displayElement} <TableHeaderItemCarret orderAsc={orderAsc} /></span>
2015-06-04 17:21:38 +02:00
</th>
2015-05-21 14:51:15 +02:00
);
} else {
return (
<th
className={'ascribe-table-header-column ' + className}
2015-05-21 14:51:15 +02:00
onClick={this.changeOrder}>
<span>{displayElement}</span>
2015-06-04 17:21:38 +02:00
</th>
2015-05-21 14:51:15 +02:00
);
}
} else {
return (
<th className={'ascribe-table-header-column ' + className}>
2015-05-21 14:51:15 +02:00
<span>
{displayElement}
2015-05-21 14:51:15 +02:00
</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;