import React, { HTMLAttributes, MutableRefObject } from "react";
import classNames from "classnames";
import { UseSelectGetItemPropsOptions } from "downshift";
import { Flex } from "../../Flex";
import { Icon, ICON_TYPE } from "../../Icon";
import { SelectOption } from "./types";
import { List } from "../../List";
interface CreatableOptionProps extends HTMLAttributes {
label: string;
isCreatable: boolean;
optionIndexRef: MutableRefObject;
setOptionIndex: (newIndex: number) => void;
highlightedIndex: number;
getItemProps: (options: UseSelectGetItemPropsOptions) => any;
creatableOption: T;
}
export function CreatableOption({
onClick,
optionIndexRef,
setOptionIndex,
highlightedIndex,
label,
isCreatable,
getItemProps,
creatableOption,
}: CreatableOptionProps) {
if (!isCreatable) return null;
const optionIndex = optionIndexRef.current;
setOptionIndex(optionIndexRef.current + 1);
const isHighlighted = highlightedIndex === optionIndex;
return (
{`Create "${label}"`}
);
}