Sha256: 21a4863d3ee1d86cf4c8109ff73a94d2c39810f017d276038eff17b967f58d51

Contents?: true

Size: 1.38 KB

Versions: 49

Compression:

Stored size: 1.38 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 isHovered = activeItems[highlightedIndex] === text;
    const itemProps = getItemProps({
      index: activeItems.indexOf(text),
      item: text,
      key,
      isHovered,
      disabled,
    });
    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

49 entries across 49 versions & 1 rubygems

Version Path
katello-4.2.2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.2.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.2.0.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.1.4 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.0.3 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.2.0.1.rc3 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-3.18.5 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.2.0.1.rc2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.2.0.rc2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.1.3 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.2.0.rc1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.0.2.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.1.2.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.0.2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.1.2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-3.18.4 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.1.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.1.0 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-4.0.1.2 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js
katello-3.18.3.1 webpack/components/TypeAhead/pf4Search/TypeAheadItems.js