2022-05-23 17:59:09 +00:00
|
|
|
import React from "react";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { Props } from "react-select";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-05-23 17:59:09 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { Avatar } from "@calcom/ui";
|
|
|
|
import { FiX } from "@calcom/ui/components/icon";
|
2022-02-11 22:20:10 +00:00
|
|
|
|
|
|
|
import Select from "@components/ui/form/Select";
|
|
|
|
|
2022-05-23 17:59:09 +00:00
|
|
|
type CheckedSelectOption = {
|
2021-09-29 21:33:18 +00:00
|
|
|
avatar: string;
|
|
|
|
label: string;
|
|
|
|
value: string;
|
2022-02-09 00:05:13 +00:00
|
|
|
disabled?: boolean;
|
2021-09-14 08:45:28 +00:00
|
|
|
};
|
|
|
|
|
2022-05-23 17:59:09 +00:00
|
|
|
export const CheckedSelect = ({
|
|
|
|
options = [],
|
|
|
|
value = [],
|
|
|
|
...props
|
|
|
|
}: Omit<Props<CheckedSelectOption, true>, "value" | "onChange"> & {
|
|
|
|
value?: readonly CheckedSelectOption[];
|
|
|
|
onChange: (value: readonly CheckedSelectOption[]) => void;
|
|
|
|
}) => {
|
2021-10-15 10:53:42 +00:00
|
|
|
const { t } = useLocale();
|
2021-09-14 08:45:28 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-05-23 17:59:09 +00:00
|
|
|
<Select
|
2021-09-14 08:45:28 +00:00
|
|
|
styles={{
|
|
|
|
option: (styles, { isDisabled }) => ({
|
|
|
|
...styles,
|
|
|
|
backgroundColor: isDisabled ? "#F5F5F5" : "inherit",
|
|
|
|
}),
|
|
|
|
}}
|
|
|
|
name={props.name}
|
2021-10-15 10:53:42 +00:00
|
|
|
placeholder={props.placeholder || t("select")}
|
2021-09-14 08:45:28 +00:00
|
|
|
isSearchable={false}
|
|
|
|
options={options}
|
2022-05-23 17:59:09 +00:00
|
|
|
value={value}
|
2021-09-14 08:45:28 +00:00
|
|
|
isMulti
|
2022-05-23 17:59:09 +00:00
|
|
|
{...props}
|
2021-09-14 08:45:28 +00:00
|
|
|
/>
|
2022-05-23 17:59:09 +00:00
|
|
|
{value.map((option) => (
|
2023-01-20 22:04:58 +00:00
|
|
|
<div key={option.value} className="border p-2 font-medium">
|
2021-09-14 08:45:28 +00:00
|
|
|
<Avatar
|
2023-01-21 11:41:49 +00:00
|
|
|
className="inline ltr:mr-2 rtl:ml-2"
|
|
|
|
size="sm"
|
2021-09-14 08:45:28 +00:00
|
|
|
imageSrc={option.avatar}
|
2022-02-09 00:05:13 +00:00
|
|
|
alt={option.label}
|
2021-09-14 08:45:28 +00:00
|
|
|
/>
|
|
|
|
{option.label}
|
2023-01-23 23:08:01 +00:00
|
|
|
<FiX
|
2022-05-23 17:59:09 +00:00
|
|
|
onClick={() => props.onChange(value.filter((item) => item.value !== option.value))}
|
2023-01-12 16:57:43 +00:00
|
|
|
className="float-right mt-0.5 h-5 w-5 cursor-pointer text-gray-500"
|
2021-09-14 08:45:28 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
2022-02-09 00:05:13 +00:00
|
|
|
};
|
2021-09-14 08:45:28 +00:00
|
|
|
|
|
|
|
export default CheckedSelect;
|