import type { Dispatch, SetStateAction } from "react"; import React from "react"; import type { GroupBase, OptionProps, MultiValueProps, MultiValue as MultiValueType, SingleValue, } from "react-select"; import { components } from "react-select"; import type { Props } from "react-select"; import { classNames } from "@calcom/lib"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Select } from "../select"; export type Option = { value: string; label: string; }; const InputOption: React.FC>> = ({ isDisabled, isFocused, isSelected, children, innerProps, ...rest }) => { const props = { ...innerProps, }; return ( {children} ); }; type MultiSelectionCheckboxesProps = { options: { label: string; value: string }[]; setSelected: Dispatch>; selected: Option[]; setValue: (s: Option[]) => unknown; countText?: string; }; const MultiValue = ({ index, getValue, countText, }: { index: number; getValue: () => readonly Option[]; countText: string; }) => { const { t } = useLocale(); const count = getValue().filter((option) => option.value !== "all").length; return <>{!index && count !== 0 &&
{t(countText, { count })}
}; }; export default function MultiSelectCheckboxes({ options, isLoading, selected, setSelected, setValue, className, isDisabled, countText, }: Omit & MultiSelectionCheckboxesProps) { const additonalComponents = { MultiValue: (props: MultiValueProps>) => ( ), }; const allOptions = [{ label: "Select all", value: "all" }, ...options]; const allSelected = selected.length === options.length ? allOptions : selected; return (