mirror of https://github.com/lidarr/Lidarr
95 lines
2.0 KiB
JavaScript
95 lines
2.0 KiB
JavaScript
|
import PropTypes from 'prop-types';
|
||
|
import React, { Component } from 'react';
|
||
|
import { icons, sortDirections } from 'Helpers/Props';
|
||
|
import Link from 'Components/Link/Link';
|
||
|
import Icon from 'Components/Icon';
|
||
|
import styles from './TableHeaderCell.css';
|
||
|
|
||
|
class VirtualTableHeaderCell extends Component {
|
||
|
|
||
|
//
|
||
|
// Listeners
|
||
|
|
||
|
onPress = () => {
|
||
|
const {
|
||
|
name,
|
||
|
fixedSortDirection
|
||
|
} = this.props;
|
||
|
|
||
|
if (fixedSortDirection) {
|
||
|
this.props.onSortPress(name, fixedSortDirection);
|
||
|
} else {
|
||
|
this.props.onSortPress(name);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Render
|
||
|
|
||
|
render() {
|
||
|
const {
|
||
|
className,
|
||
|
name,
|
||
|
isSortable,
|
||
|
isVisible,
|
||
|
isModifiable,
|
||
|
sortKey,
|
||
|
sortDirection,
|
||
|
fixedSortDirection,
|
||
|
children,
|
||
|
onSortPress,
|
||
|
...otherProps
|
||
|
} = this.props;
|
||
|
|
||
|
const isSorting = isSortable && sortKey === name;
|
||
|
const sortIcon = sortDirection === sortDirections.ASCENDING ?
|
||
|
icons.SORT_ASCENDING :
|
||
|
icons.SORT_DESCENDING;
|
||
|
|
||
|
return (
|
||
|
isSortable ?
|
||
|
<Link
|
||
|
component="th"
|
||
|
className={className}
|
||
|
onPress={this.onPress}
|
||
|
{...otherProps}
|
||
|
>
|
||
|
{children}
|
||
|
|
||
|
{
|
||
|
isSorting &&
|
||
|
<Icon
|
||
|
name={sortIcon}
|
||
|
className={styles.sortIcon}
|
||
|
/>
|
||
|
}
|
||
|
</Link> :
|
||
|
|
||
|
<th className={className}>
|
||
|
{children}
|
||
|
</th>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
VirtualTableHeaderCell.propTypes = {
|
||
|
className: PropTypes.string,
|
||
|
name: PropTypes.string.isRequired,
|
||
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
||
|
isSortable: PropTypes.bool,
|
||
|
isVisible: PropTypes.bool,
|
||
|
isModifiable: PropTypes.bool,
|
||
|
sortKey: PropTypes.string,
|
||
|
fixedSortDirection: PropTypes.string,
|
||
|
sortDirection: PropTypes.string,
|
||
|
children: PropTypes.node,
|
||
|
onSortPress: PropTypes.func
|
||
|
};
|
||
|
|
||
|
VirtualTableHeaderCell.defaultProps = {
|
||
|
className: styles.headerCell,
|
||
|
isSortable: false
|
||
|
};
|
||
|
|
||
|
export default VirtualTableHeaderCell;
|