import React from 'react'; import { SelectOptionType } from './interfaces'; import { ChipWrapper, IconWrapper, LabelWrapper, SelectMenuWrapper, SelectOption, } from './styles'; type SelectMenuProps = { menuPosition?: 'absolute' | 'fixed'; menuZIndex?: number; onOptionClick: (opt: SelectOptionType) => void; options: SelectOptionType[]; wrapperElementRef: React.RefObject; selectedOptionLabel?: string; selectMenuWidth?: string; }; const SelectMenu: React.FC = ({ menuPosition, menuZIndex, onOptionClick, options, wrapperElementRef, selectedOptionLabel, selectMenuWidth, }) => { const getSelectMenuOptions = () => { const wrapperElement = wrapperElementRef.current; if (menuPosition == 'absolute' || !wrapperElement) return {}; const boundingRect = wrapperElement.getBoundingClientRect(); return { fixedPosition: { top: boundingRect.top + 48, right: window.innerWidth - boundingRect.right, }, selectMenuWidth, }; }; return ( {options.map((opt) => { return ( onOptionClick(opt)} > {opt.icon && {opt.icon}} {opt.label} {opt.chip && {opt.chip}} ); })} ); }; export default SelectMenu;