2023-03-20 11:18:23 +00:00
|
|
|
import type { GroupBase, InputProps, OptionProps } from "react-select";
|
2023-02-16 22:39:57 +00:00
|
|
|
import { components as reactSelectComponents } from "react-select";
|
2022-10-10 18:50:43 +00:00
|
|
|
|
|
|
|
import { classNames } from "@calcom/lib";
|
2022-11-23 02:55:25 +00:00
|
|
|
|
2023-01-14 00:48:19 +00:00
|
|
|
import { UpgradeTeamsBadge } from "../../badge";
|
2023-01-26 22:51:03 +00:00
|
|
|
import { FiCheck } from "../../icon";
|
2022-10-10 18:50:43 +00:00
|
|
|
|
|
|
|
export const InputComponent = <
|
|
|
|
Option,
|
|
|
|
IsMulti extends boolean = false,
|
|
|
|
Group extends GroupBase<Option> = GroupBase<Option>
|
|
|
|
>({
|
|
|
|
inputClassName,
|
|
|
|
...props
|
|
|
|
}: InputProps<Option, IsMulti, Group>) => {
|
|
|
|
return (
|
|
|
|
<reactSelectComponents.Input
|
|
|
|
// disables our default form focus hightlight on the react-select input element
|
|
|
|
inputClassName={classNames(
|
|
|
|
"focus:ring-0 focus:ring-offset-0 dark:!text-darkgray-900 !text-black",
|
|
|
|
inputClassName
|
|
|
|
)}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-01-11 18:41:45 +00:00
|
|
|
type ExtendedOption = {
|
|
|
|
value: string | number;
|
|
|
|
label: string;
|
|
|
|
needsUpgrade?: boolean;
|
|
|
|
};
|
|
|
|
|
2022-10-10 18:50:43 +00:00
|
|
|
export const OptionComponent = <
|
|
|
|
Option,
|
|
|
|
IsMulti extends boolean = false,
|
|
|
|
Group extends GroupBase<Option> = GroupBase<Option>
|
|
|
|
>({
|
|
|
|
...props
|
|
|
|
}: OptionProps<Option, IsMulti, Group>) => {
|
|
|
|
return (
|
2023-03-20 11:18:23 +00:00
|
|
|
// This gets styled in the select classNames prop now - handles overrides with styles vs className here doesnt
|
|
|
|
<reactSelectComponents.Option {...props}>
|
|
|
|
<div className="flex">
|
2023-01-11 18:41:45 +00:00
|
|
|
<span className="mr-auto">{props.label}</span>
|
2023-01-14 00:48:19 +00:00
|
|
|
{(props.data as unknown as ExtendedOption).needsUpgrade && <UpgradeTeamsBadge />}
|
2023-01-23 23:08:01 +00:00
|
|
|
{props.isSelected && <FiCheck className="ml-2 h-4 w-4" />}
|
2023-03-20 11:18:23 +00:00
|
|
|
</div>
|
2022-10-10 18:50:43 +00:00
|
|
|
</reactSelectComponents.Option>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-03-20 11:18:23 +00:00
|
|
|
// We need to override this component if we need a icon - we can't simpily override styles
|
|
|
|
type IconLeadingProps = {
|
|
|
|
icon: React.ReactNode;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
} & React.ComponentProps<typeof reactSelectComponents.Control>;
|
2022-10-10 18:50:43 +00:00
|
|
|
|
2023-03-20 11:18:23 +00:00
|
|
|
export const IconLeading = ({ icon, children, ...props }: IconLeadingProps) => {
|
|
|
|
return (
|
|
|
|
<reactSelectComponents.Control {...props}>
|
|
|
|
{icon}
|
|
|
|
{children}
|
|
|
|
</reactSelectComponents.Control>
|
|
|
|
);
|
|
|
|
};
|