import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import classnames from 'classnames'; import PlainButton from '../plain-button/PlainButton'; // @ts-ignore flow import import DropdownMenu, { MenuToggle } from '../dropdown-menu'; import { Menu, SelectMenuItem } from '../menu'; import messages from './messages'; import './CategorySelector.scss'; import { Category } from './CategorySelector'; interface CategorySelectorComponentProps { categories: Category[]; categoryProps: Record; className: string; currentCategory: string; maxLinks: number; measureRef: (ref: Element | null) => void; moreRef: React.RefObject; onSelect: (value: string) => void; } const CategorySelectorComponent = ({ measureRef, moreRef, className, categories, maxLinks, currentCategory, categoryProps, onSelect, }: CategorySelectorComponentProps) => { const linkCategories = categories.slice(0, maxLinks); const overflowCategories = categories.slice(maxLinks); const selectedOverflow = overflowCategories.find(({ value }) => currentCategory === value); const renderCategory = ({ value, displayText }: Category) => ( onSelect(value)} onKeyPress={(event: React.KeyboardEvent) => { if (event.key === 'Enter' || event.key === ' ') onSelect(value); }} role="button" tabIndex={0} {...categoryProps} > {displayText} ); return (
{linkCategories.map(renderCategory)}
= categories.length, })} > {selectedOverflow ? selectedOverflow.displayText : } {overflowCategories.map(({ value, displayText }: Category) => ( onSelect(value)} > {displayText} ))}
); }; export default CategorySelectorComponent;