Sha256: 2d78c2a302ee3d1e3434d62dc1a256c727a8ad04eac8748593135da9362df13d

Contents?: true

Size: 1.08 KB

Versions: 23

Compression:

Stored size: 1.08 KB

Contents

import React from 'react';
import { Icon } from 'patternfly-react';
import classNames from 'classnames';
import PropTypes from 'prop-types';

const SortableHeaderItem = ({ value, title, sort, changeSort }) => {
  const chooseChevron = (active, order) => {
    if (!active) {
      return null;
    }

    const direction = order === 'asc' ? 'angle-up' : 'angle-down';

    return <Icon type="fa" name={direction} />;
  };

  const active = sort.attribute === value;

  const clickHandler = () => {
    let direction = 'asc';

    if (active) {
      direction = sort.order === 'asc' ? 'desc' : 'asc';
    }

    changeSort({
      attribute: value,
      order: direction,
    });
  };

  return (
    <span
      className={`sortable-header ${classNames({ active })}`}
      onClick={clickHandler}
    >
      {chooseChevron(active, sort.order)}
      {title}
    </span>
  );
};

SortableHeaderItem.propTypes = {
  sort: PropTypes.object.isRequired,
  changeSort: PropTypes.func.isRequired,
  value: PropTypes.string.isRequired,
  title: PropTypes.string.isRequired,
};

export default SortableHeaderItem;

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
foreman_leapp-2.0.1 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-2.0.0 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-1.2.1 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-1.2.0 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.15 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-1.1.1 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-1.1.0 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-1.0.0 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.14 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.13 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.12 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.11 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.10 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.9 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.8 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.7 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.6 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.5 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.4 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js
foreman_leapp-0.1.3 webpack/components/PreupgradeReportsList/components/SortableHeaderItem.js