Sha256: 4af1f03155e64dc76da6301dc0397e354b3a95ada5b13768818679124d0b556a

Contents?: true

Size: 1.4 KB

Versions: 26

Compression:

Stored size: 1.4 KB

Contents

import React from 'react';
import {
  Dropdown,
  DropdownItem,
  DropdownSeparator,
} from '@patternfly/react-core';
import PropTypes from 'prop-types';

import { commonItemPropTypes } from '../helpers/commonPropTypes';

const TypeAheadItems = ({
  isOpen, items, activeItems, getItemProps, highlightedIndex,
}) => {
  const buildDropdownItems = () => items.map(({ text, type, disabled = false }, index) => {
    const key = `${text}${index}`;
    if (type === 'divider') return (<DropdownSeparator key={key} />);
    const isHighlighted = highlightedIndex === index;
    const itemProps = getItemProps({
      index: activeItems.indexOf(text),
      item: text,
      key,
      disabled,
      className: isHighlighted ? 'highlighted' : '',
    });
    const { onClick, ...dropdownProps } = itemProps;
    return (
      <DropdownItem
        {...dropdownProps}
        component={
          <button onClick={onClick}>{text}</button>
        }
      />
    );
  });

  // toggle prop is required but since it is not manually toggled, React.Fragment is used to
  // satisfy the requirement
  return (
    <Dropdown
      toggle={<React.Fragment />}
      isOpen={isOpen}
      dropdownItems={buildDropdownItems()}
      className="typeahead-dropdown"
    />
  );
};

TypeAheadItems.propTypes = {
  ...commonItemPropTypes,
  isOpen: PropTypes.bool,
};

TypeAheadItems.defaultProps = {
  isOpen: false,
};

export default TypeAheadItems;

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
katello-4.6.2.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.6.2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.6.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.4.2.2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.4.2.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.4.2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.5.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.6.0 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.6.0.rc2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.6.0.rc1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.5.0 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.5.0.rc2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.4.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.5.0.rc1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.4.0.2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.4.0.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.3.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.4.0 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.4.0.rc2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.4.0.rc1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js