2022-07-23 00:39:50 +00:00
|
|
|
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
2022-09-02 11:10:55 +00:00
|
|
|
import Link from "next/link";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { ComponentProps } from "react";
|
|
|
|
import { forwardRef } from "react";
|
2022-09-02 11:10:55 +00:00
|
|
|
|
|
|
|
import { classNames } from "@calcom/lib";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { SVGComponent } from "@calcom/types/SVGComponent";
|
2023-05-17 12:47:44 +00:00
|
|
|
import { CheckCircle } from "@calcom/ui/components/icon";
|
2023-01-26 22:51:03 +00:00
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { ButtonColor } from "../../button/Button";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
export const Dropdown = DropdownMenuPrimitive.Root;
|
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
type DropdownMenuTriggerProps = ComponentProps<(typeof DropdownMenuPrimitive)["Trigger"]>;
|
2022-07-23 00:39:50 +00:00
|
|
|
export const DropdownMenuTrigger = forwardRef<HTMLButtonElement, DropdownMenuTriggerProps>(
|
|
|
|
({ className = "", ...props }, forwardedRef) => (
|
|
|
|
<DropdownMenuPrimitive.Trigger
|
|
|
|
{...props}
|
2023-01-22 00:03:59 +00:00
|
|
|
className={classNames(
|
|
|
|
!props.asChild &&
|
2023-04-05 18:14:46 +00:00
|
|
|
`focus:bg-subtle hover:bg-muted text-default group-hover:text-emphasis inline-flex items-center rounded-md bg-transparent px-3 py-2 text-sm font-medium ring-0 ${className}`
|
2023-01-22 00:03:59 +00:00
|
|
|
)}
|
2022-07-23 00:39:50 +00:00
|
|
|
ref={forwardedRef}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
DropdownMenuTrigger.displayName = "DropdownMenuTrigger";
|
|
|
|
|
2022-09-30 10:29:22 +00:00
|
|
|
export const DropdownMenuTriggerItem = DropdownMenuPrimitive.Trigger;
|
|
|
|
|
|
|
|
export const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
|
2022-07-23 00:39:50 +00:00
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
type DropdownMenuContentProps = ComponentProps<(typeof DropdownMenuPrimitive)["Content"]>;
|
2022-07-23 00:39:50 +00:00
|
|
|
export const DropdownMenuContent = forwardRef<HTMLDivElement, DropdownMenuContentProps>(
|
2023-01-02 08:28:12 +00:00
|
|
|
({ children, sideOffset = 2, align = "end", ...props }, forwardedRef) => {
|
2022-07-23 00:39:50 +00:00
|
|
|
return (
|
|
|
|
<DropdownMenuPrimitive.Content
|
2022-09-02 11:10:55 +00:00
|
|
|
align={align}
|
2022-07-23 00:39:50 +00:00
|
|
|
{...props}
|
2023-01-02 08:28:12 +00:00
|
|
|
sideOffset={sideOffset}
|
2023-01-15 11:40:40 +00:00
|
|
|
className={classNames(
|
2023-04-05 18:14:46 +00:00
|
|
|
"shadow-dropdown w-50 bg-default border-subtle relative z-10 ml-1.5 origin-top-right rounded-md border text-sm",
|
2023-07-05 03:24:42 +00:00
|
|
|
"[&>*:first-child]:mt-1 [&>*:last-child]:mb-1",
|
|
|
|
props.className
|
2023-01-15 11:40:40 +00:00
|
|
|
)}
|
2022-07-23 00:39:50 +00:00
|
|
|
ref={forwardedRef}>
|
|
|
|
{children}
|
|
|
|
</DropdownMenuPrimitive.Content>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
DropdownMenuContent.displayName = "DropdownMenuContent";
|
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
type DropdownMenuLabelProps = ComponentProps<(typeof DropdownMenuPrimitive)["Label"]>;
|
2022-07-23 00:39:50 +00:00
|
|
|
export const DropdownMenuLabel = (props: DropdownMenuLabelProps) => (
|
2023-04-05 18:14:46 +00:00
|
|
|
<DropdownMenuPrimitive.Label {...props} className="text-subtle px-3 py-2" />
|
2022-07-23 00:39:50 +00:00
|
|
|
);
|
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
type DropdownMenuItemProps = ComponentProps<(typeof DropdownMenuPrimitive)["CheckboxItem"]>;
|
2022-07-23 00:39:50 +00:00
|
|
|
export const DropdownMenuItem = forwardRef<HTMLDivElement, DropdownMenuItemProps>(
|
|
|
|
({ className = "", ...props }, forwardedRef) => (
|
|
|
|
<DropdownMenuPrimitive.Item
|
2023-04-05 18:14:46 +00:00
|
|
|
className={`focus:ring-brand-800 hover:bg-subtle hover:text-emphasis text-default text-sm ring-inset first-of-type:rounded-t-[inherit] last-of-type:rounded-b-[inherit] focus:outline-none focus:ring-1 ${className}`}
|
2022-07-23 00:39:50 +00:00
|
|
|
{...props}
|
|
|
|
ref={forwardedRef}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
DropdownMenuItem.displayName = "DropdownMenuItem";
|
|
|
|
|
|
|
|
export const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
type DropdownMenuCheckboxItemProps = ComponentProps<(typeof DropdownMenuPrimitive)["CheckboxItem"]>;
|
2022-07-23 00:39:50 +00:00
|
|
|
export const DropdownMenuCheckboxItem = forwardRef<HTMLDivElement, DropdownMenuCheckboxItemProps>(
|
|
|
|
({ children, ...props }, forwardedRef) => {
|
|
|
|
return (
|
|
|
|
<DropdownMenuPrimitive.CheckboxItem {...props} ref={forwardedRef}>
|
|
|
|
{children}
|
|
|
|
<DropdownMenuPrimitive.ItemIndicator>
|
2023-05-17 12:47:44 +00:00
|
|
|
<CheckCircle />
|
2022-07-23 00:39:50 +00:00
|
|
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
</DropdownMenuPrimitive.CheckboxItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
DropdownMenuCheckboxItem.displayName = "DropdownMenuCheckboxItem";
|
|
|
|
|
|
|
|
export const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
type DropdownMenuRadioItemProps = ComponentProps<(typeof DropdownMenuPrimitive)["RadioItem"]>;
|
2022-07-23 00:39:50 +00:00
|
|
|
export const DropdownMenuRadioItem = forwardRef<HTMLDivElement, DropdownMenuRadioItemProps>(
|
|
|
|
({ children, ...props }, forwardedRef) => {
|
|
|
|
return (
|
|
|
|
<DropdownMenuPrimitive.RadioItem {...props} ref={forwardedRef}>
|
|
|
|
{children}
|
|
|
|
<DropdownMenuPrimitive.ItemIndicator>
|
2023-05-17 12:47:44 +00:00
|
|
|
<CheckCircle />
|
2022-07-23 00:39:50 +00:00
|
|
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
</DropdownMenuPrimitive.RadioItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
DropdownMenuRadioItem.displayName = "DropdownMenuRadioItem";
|
|
|
|
|
2022-09-02 11:10:55 +00:00
|
|
|
type DropdownItemProps = {
|
|
|
|
children: React.ReactNode;
|
2023-01-17 17:12:22 +00:00
|
|
|
color?: ButtonColor;
|
2022-12-18 10:44:44 +00:00
|
|
|
StartIcon?: SVGComponent;
|
|
|
|
EndIcon?: SVGComponent;
|
2022-09-02 11:10:55 +00:00
|
|
|
href?: string;
|
|
|
|
disabled?: boolean;
|
2023-06-29 17:03:44 +00:00
|
|
|
childrenClassName?: string;
|
2022-09-02 11:10:55 +00:00
|
|
|
} & ButtonOrLinkProps;
|
|
|
|
|
|
|
|
type ButtonOrLinkProps = ComponentProps<"button"> & ComponentProps<"a">;
|
|
|
|
export function ButtonOrLink({ href, ...props }: ButtonOrLinkProps) {
|
|
|
|
const isLink = typeof href !== "undefined";
|
|
|
|
const ButtonOrLink = isLink ? "a" : "button";
|
|
|
|
|
|
|
|
const content = <ButtonOrLink {...props} />;
|
|
|
|
|
|
|
|
if (isLink) {
|
2022-10-04 15:50:15 +00:00
|
|
|
return (
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link href={href} legacyBehavior>
|
|
|
|
{content}
|
2022-10-04 15:50:15 +00:00
|
|
|
</Link>
|
|
|
|
);
|
2022-09-02 11:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const DropdownItem = (props: DropdownItemProps) => {
|
2023-06-29 17:03:44 +00:00
|
|
|
const { StartIcon, EndIcon, children, color, childrenClassName, ...rest } = props;
|
2022-09-02 11:10:55 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ButtonOrLink
|
2023-01-31 21:45:38 +00:00
|
|
|
{...rest}
|
2022-09-02 11:10:55 +00:00
|
|
|
className={classNames(
|
2023-04-05 18:14:46 +00:00
|
|
|
"hover:text-emphasis text-default inline-flex w-full items-center space-x-2 px-3 py-2 disabled:cursor-not-allowed",
|
|
|
|
color === "destructive" ? "hover:bg-error hover:text-red-700" : "hover:bg-subtle"
|
2022-09-02 11:10:55 +00:00
|
|
|
)}>
|
|
|
|
<>
|
2023-01-15 11:40:40 +00:00
|
|
|
{StartIcon && <StartIcon className="h-4 w-4" />}
|
2023-06-29 17:03:44 +00:00
|
|
|
<div className={classNames("text-sm font-medium leading-5", childrenClassName)}>{children}</div>
|
2023-01-15 11:40:40 +00:00
|
|
|
{EndIcon && <EndIcon className="h-4 w-4" />}
|
2022-09-02 11:10:55 +00:00
|
|
|
</>
|
|
|
|
</ButtonOrLink>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
type DropdownMenuSeparatorProps = ComponentProps<(typeof DropdownMenuPrimitive)["Separator"]>;
|
2023-01-15 11:40:40 +00:00
|
|
|
export const DropdownMenuSeparator = forwardRef<HTMLDivElement, DropdownMenuSeparatorProps>(
|
|
|
|
({ className = "", ...props }, forwardedRef) => {
|
|
|
|
return (
|
|
|
|
<DropdownMenuPrimitive.Separator
|
2023-04-05 18:14:46 +00:00
|
|
|
className={classNames("bg-emphasis my-1 h-px", className)}
|
2023-01-15 11:40:40 +00:00
|
|
|
{...props}
|
|
|
|
ref={forwardedRef}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
DropdownMenuSeparator.displayName = "DropdownMenuSeparator";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
export default Dropdown;
|