All files / posts-table/components/PostsTable/components/PostsHeader/components/PostOrderSwitch index.jsx

7.69% Statements 1/13
0% Branches 0/12
0% Functions 0/8
7.69% Lines 1/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81                                                                                                                                                    1x            
import React from 'react';
import PropTypes from 'prop-types';
 
import {
  Text,
  ArrowLongDownIcon,
  ArrowLongUpIcon,
} from '@bufferapp/components';
 
import classNames from 'classnames';
 
import {
  container,
  buttonItem,
  buttonActive,
} from './style.less';
 
class PostOrderSwitch extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isDescendHovered: false,
      isAscendHovered: false,
    };
  }
 
  render() {
    const { isDescendingSelected, handleClick } = this.props;
    const descendingClass = classNames(buttonItem, {
      [buttonActive]: isDescendingSelected,
    });
    const ascendingClass = classNames(buttonItem, {
      [buttonActive]: !isDescendingSelected,
    });
    return (
      <div>
        <span style={{ top: '-4px', position: 'relative' }}>
          <Text size="small">Order</Text>
        </span>
        <ul className={container}>
          <li  // eslint-disable-line
            key="descending"
            className={descendingClass}
            onMouseEnter={() => { this.setState({ isDescendHovered: true }); }}
            onMouseLeave={() => { this.setState({ isDescendHovered: false }); }}
            onClick={() => handleClick({ isDescendingSelected: true })}
          >
            {(isDescendingSelected || this.state.isDescendHovered) &&
              <ArrowLongDownIcon color={'shuttleGray'} />
            }
            {(!isDescendingSelected && !this.state.isDescendHovered) &&
              <ArrowLongDownIcon color={'geyser'} />
            }
          </li>
          <li  // eslint-disable-line
            key="ascending"
            className={ascendingClass}
            onMouseEnter={() => { this.setState({ isAscendHovered: true }); }}
            onMouseLeave={() => { this.setState({ isAscendHovered: false }); }}
            onClick={() => handleClick({ isDescendingSelected: false })}
          >
            {(!isDescendingSelected || this.state.isAscendHovered) &&
              <ArrowLongUpIcon color={'shuttleGray'} />
            }
            {(isDescendingSelected && !this.state.isAscendHovered) &&
              <ArrowLongUpIcon color={'geyser'} />
            }
          </li>
        </ul>
      </div>
    );
  }
}
 
PostOrderSwitch.propTypes = {
  isDescendingSelected: PropTypes.bool.isRequired,
  handleClick: PropTypes.func.isRequired,
};
 
export default PostOrderSwitch;