2023-02-16 22:39:57 +00:00
|
|
|
import type { GroupBase, Props, SingleValue } from "react-select";
|
|
|
|
import { components } from "react-select";
|
2023-01-21 16:52:21 +00:00
|
|
|
|
|
|
|
import type { EventLocationType } from "@calcom/app-store/locations";
|
|
|
|
import { classNames } from "@calcom/lib";
|
2023-04-19 10:14:59 +00:00
|
|
|
import cx from "@calcom/lib/classNames";
|
2023-03-20 18:46:22 +00:00
|
|
|
import { Select } from "@calcom/ui";
|
2023-01-21 16:52:21 +00:00
|
|
|
|
|
|
|
export type LocationOption = {
|
|
|
|
label: string;
|
|
|
|
value: EventLocationType["type"];
|
|
|
|
icon?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type SingleValueLocationOption = SingleValue<LocationOption>;
|
|
|
|
|
|
|
|
export type GroupOptionType = GroupBase<LocationOption>;
|
|
|
|
|
2023-03-20 18:46:22 +00:00
|
|
|
const OptionWithIcon = ({ icon, label }: { icon?: string; label: string }) => {
|
2023-01-21 16:52:21 +00:00
|
|
|
return (
|
|
|
|
<div className="flex items-center gap-3">
|
2023-04-19 10:14:59 +00:00
|
|
|
{icon && (
|
|
|
|
<img
|
|
|
|
src={icon}
|
|
|
|
alt="cover"
|
|
|
|
// invert all the icons except app icons
|
2023-05-09 15:27:09 +00:00
|
|
|
className={cx("h-3.5 w-3.5", icon && !icon.startsWith("/app-store") && "dark:invert")}
|
2023-04-19 10:14:59 +00:00
|
|
|
/>
|
|
|
|
)}
|
2023-03-20 18:46:22 +00:00
|
|
|
<span className={classNames("text-sm font-medium")}>{label}</span>
|
2023-01-21 16:52:21 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function LocationSelect(props: Props<LocationOption, false, GroupOptionType>) {
|
|
|
|
return (
|
|
|
|
<Select<LocationOption>
|
|
|
|
name="location"
|
2023-02-22 05:22:49 +00:00
|
|
|
id="location-select"
|
2023-01-21 16:52:21 +00:00
|
|
|
components={{
|
|
|
|
Option: (props) => (
|
|
|
|
<components.Option {...props}>
|
2023-03-20 18:46:22 +00:00
|
|
|
<OptionWithIcon icon={props.data.icon} label={props.data.label} />
|
2023-01-21 16:52:21 +00:00
|
|
|
</components.Option>
|
|
|
|
),
|
|
|
|
SingleValue: (props) => (
|
|
|
|
<components.SingleValue {...props}>
|
|
|
|
<OptionWithIcon icon={props.data.icon} label={props.data.label} />
|
|
|
|
</components.SingleValue>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
formatOptionLabel={(e) => (
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
{e.icon && <img src={e.icon} alt="app-icon" className="h-5 w-5" />}
|
|
|
|
<span>{e.label}</span>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-04-05 18:14:46 +00:00
|
|
|
formatGroupLabel={(e) => <p className="text-default text-xs font-medium">{e.label}</p>}
|
2023-01-21 16:52:21 +00:00
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|