import { Popover, Transition } from '@headlessui/react' import classNames from 'classnames' import React, { ReactNode, useRef } from 'react' import { ChevronDownIcon } from '@heroicons/react/20/solid' import { popover, BlurMenuButtonOnEscape } from './popover' import { useSearchableItems } from '../hooks/use-searchable-items' import { SearchInput } from './search-input' import { EllipsisHorizontalIcon } from '@heroicons/react/24/solid' export const TabWrapper = ({ className, children }: { className?: string children: ReactNode }) => (
{children}
) const TabButtonText = ({ children, active }: { children: ReactNode active: boolean }) => ( {children} ) export const TabButton = ({ className, children, onClick, active }: { className?: string children: ReactNode onClick: () => void active: boolean }) => ( ) export const DropdownTabButton = ({ className, transitionClassName, active, children, ...optionsProps }: { className?: string transitionClassName?: string active: boolean children: ReactNode } & Omit) => { const dropdownButtonRef = useRef(null) return ( {({ close: closeDropdown }) => ( <> {children} )} ) } type ItemsProps = { closeDropdown: () => void options: Array<{ selected: boolean; onClick: () => void; label: string }> searchable?: boolean collectionTitle?: string } const Items = ({ options, searchable, collectionTitle, closeDropdown }: ItemsProps) => { const { filteredData, showableData, showSearch, searching, searchRef, handleSearchInput, handleClearSearch, handleShowAll, countOfMoreToShow } = useSearchableItems({ data: options, maxItemsInitially: searchable ? 5 : options.length, itemMatchesSearchValue: (option, trimmedSearchString) => option.label.toLowerCase().includes(trimmedSearchString.toLowerCase()) }) const itemClassName = classNames( 'w-full text-left', popover.items.classNames.navigationLink, popover.items.classNames.selectedOption, popover.items.classNames.hoverLink, { [popover.items.classNames.roundedStart]: !searchable || !showSearch // when the menu is not searchable, the first item needs rounded top }, popover.items.classNames.roundedEnd ) return ( <> {searchable && showSearch && (
{collectionTitle && (
{collectionTitle}
)}
)}
{showableData.map(({ selected, label, onClick }, index) => { return ( ) })} {countOfMoreToShow > 0 && ( )} {searching && !filteredData.length && ( )}
) }