import React from "react"; import { Chips } from "../../../chips"; import { useInputContext } from "../Input/Input.context"; import { ComboboxOption } from "../types"; import { useSelectedOptionsContext } from "./selectedOptionsContext"; interface SelectedOptionsProps { selectedOptions?: ComboboxOption[]; size?: "medium" | "small"; children: React.ReactNode; } const Option = ({ option }: { option: ComboboxOption }) => { const { isMultiSelect, removeSelectedOption } = useSelectedOptionsContext(); const { focusInput, readOnly, inputProps } = useInputContext(); if (!isMultiSelect) { return (
{option.label}
); } if (readOnly || inputProps.disabled) { return ( {option.label} ); } return ( { event.stopPropagation(); removeSelectedOption(option); focusInput(); }} > {option.label} ); }; const SelectedOptions: React.FC = ({ selectedOptions = [], size, children, }) => { const { value } = useInputContext(); const { isMultiSelect } = useSelectedOptionsContext(); return ( {value.length === 0 || (isMultiSelect && selectedOptions.length) ? selectedOptions.map((option, i) => ( ); }; export default SelectedOptions;