import React, { HTMLAttributes, ReactNode, useContext } from "react"; import classNames from "classnames"; import { Box } from "../../Box"; import { SelectOption } from "../shared/types"; import { Flex } from "../../Flex"; import { Icon, ICON_TYPE } from "../../Icon"; import { SingleSelectContext } from "./SingleSelectContext"; interface SingleSelectOptionProps extends HTMLAttributes { option: T; children?: ReactNode; isDisabled?: boolean; } export function SingleSelectOption({ option, children, isDisabled = false, ...rest }: SingleSelectOptionProps) { const { getItemProps, selectedItem, highlightedIndex, optionIndexRef, setOptionIndex, } = useContext(SingleSelectContext); const optionIndex = optionIndexRef.current; setOptionIndex(optionIndexRef.current + 1); const isSelected = !!selectedItem && selectedItem.value === option.value; const isHighlighted = highlightedIndex === optionIndex; const itemProps = getItemProps({ item: option, index: optionIndex, disabled: isDisabled, }); return ( {children || option.label} {isSelected && ( )} ); }