import SelectIcon from "@/app/icons/downArrowIcon.svg"; import Popover from "@/app/components/Popover"; import React, { useContext, useMemo, useRef } from "react"; import useRelativePosition, { Orientation, } from "@/app/hooks/useRelativePosition"; import List from "@/app/components/List"; import Selected from "@/app/icons/selectedIcon.svg"; export type Option = { value: Value; label: string; icon?: React.ReactNode; }; export interface SearchProps { value?: string; onSelect?: (v: Value) => void; options?: Option[]; inMobile?: boolean; } const Select = (props: SearchProps) => { const { value, onSelect, options = [], inMobile } = props; const { isMobileScreen, selectClassName } = useContext(List.ListContext); const optionsRef = useRef[]>([]); optionsRef.current = options; const selectedOption = useMemo( () => optionsRef.current.find((o) => o.value === value), [value], ); const contentRef = useRef(null); const { position, getRelativePosition } = useRelativePosition({ delay: 0, }); let headerH = 100; let baseH = position?.poi.distanceToBottomBoundary || 0; if (isMobileScreen) { headerH = 60; } if (position?.poi.relativePosition[1] === Orientation.bottom) { baseH = position?.poi.distanceToTopBoundary; } const maxHeight = `${baseH - headerH}px`; const content = (
{options?.map((o) => (
{ onSelect?.(o.value); }} >
{!!o.icon &&
{o.icon}
}
{o.label}
))}
); return ( { getRelativePosition(contentRef.current!, ""); }} className={selectClassName} >
{!!selectedOption?.icon && (
{selectedOption?.icon}
)}
{selectedOption?.label}
); }; export default Select;