2022-07-23 00:39:50 +00:00
|
|
|
import { CheckCircleIcon } from "@heroicons/react/outline";
|
|
|
|
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
2022-09-02 11:10:55 +00:00
|
|
|
import Link from "next/link";
|
2022-07-23 00:39:50 +00:00
|
|
|
import { ComponentProps, forwardRef } from "react";
|
2022-09-02 11:10:55 +00:00
|
|
|
import { Icon } from "react-feather";
|
|
|
|
|
|
|
|
import { classNames } from "@calcom/lib";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
export const Dropdown = DropdownMenuPrimitive.Root;
|
|
|
|
|
|
|
|
type DropdownMenuTriggerProps = ComponentProps<typeof DropdownMenuPrimitive["Trigger"]>;
|
|
|
|
export const DropdownMenuTrigger = forwardRef<HTMLButtonElement, DropdownMenuTriggerProps>(
|
|
|
|
({ className = "", ...props }, forwardedRef) => (
|
|
|
|
<DropdownMenuPrimitive.Trigger
|
|
|
|
{...props}
|
|
|
|
className={
|
|
|
|
props.asChild
|
2022-09-13 19:18:29 +00:00
|
|
|
? classNames(
|
|
|
|
className,
|
|
|
|
"radix-state-open:bg-gray-100 radix-state-open:ring-brand-800 radix-state-open:ring-1"
|
|
|
|
)
|
2022-08-03 16:01:29 +00:00
|
|
|
: `inline-flex items-center rounded-md bg-transparent px-3 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-neutral-500 focus:ring-offset-1 group-hover:text-black ${className}`
|
2022-07-23 00:39:50 +00:00
|
|
|
}
|
|
|
|
ref={forwardedRef}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
DropdownMenuTrigger.displayName = "DropdownMenuTrigger";
|
|
|
|
|
|
|
|
export const DropdownMenuTriggerItem = DropdownMenuPrimitive.TriggerItem;
|
|
|
|
|
|
|
|
type DropdownMenuContentProps = ComponentProps<typeof DropdownMenuPrimitive["Content"]>;
|
|
|
|
export const DropdownMenuContent = forwardRef<HTMLDivElement, DropdownMenuContentProps>(
|
2022-09-02 11:10:55 +00:00
|
|
|
({ children, align = "end", ...props }, forwardedRef) => {
|
2022-07-23 00:39:50 +00:00
|
|
|
return (
|
|
|
|
<DropdownMenuPrimitive.Content
|
|
|
|
portalled={props.portalled}
|
2022-09-02 11:10:55 +00:00
|
|
|
align={align}
|
2022-07-23 00:39:50 +00:00
|
|
|
{...props}
|
2022-09-06 17:56:13 +00:00
|
|
|
className="shadow-dropdown w-50 relative z-10 mt-1 -ml-0 origin-top-right rounded-md border border-gray-200 bg-white text-sm"
|
2022-07-23 00:39:50 +00:00
|
|
|
ref={forwardedRef}>
|
|
|
|
{children}
|
|
|
|
</DropdownMenuPrimitive.Content>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
DropdownMenuContent.displayName = "DropdownMenuContent";
|
|
|
|
|
|
|
|
type DropdownMenuLabelProps = ComponentProps<typeof DropdownMenuPrimitive["Label"]>;
|
|
|
|
export const DropdownMenuLabel = (props: DropdownMenuLabelProps) => (
|
|
|
|
<DropdownMenuPrimitive.Label {...props} className="px-3 py-2 text-neutral-500" />
|
|
|
|
);
|
|
|
|
|
|
|
|
type DropdownMenuItemProps = ComponentProps<typeof DropdownMenuPrimitive["CheckboxItem"]>;
|
|
|
|
export const DropdownMenuItem = forwardRef<HTMLDivElement, DropdownMenuItemProps>(
|
|
|
|
({ className = "", ...props }, forwardedRef) => (
|
|
|
|
<DropdownMenuPrimitive.Item
|
|
|
|
className={`text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900 ${className}`}
|
|
|
|
{...props}
|
|
|
|
ref={forwardedRef}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
DropdownMenuItem.displayName = "DropdownMenuItem";
|
|
|
|
|
|
|
|
export const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
|
|
|
|
|
|
|
type DropdownMenuCheckboxItemProps = ComponentProps<typeof DropdownMenuPrimitive["CheckboxItem"]>;
|
|
|
|
export const DropdownMenuCheckboxItem = forwardRef<HTMLDivElement, DropdownMenuCheckboxItemProps>(
|
|
|
|
({ children, ...props }, forwardedRef) => {
|
|
|
|
return (
|
|
|
|
<DropdownMenuPrimitive.CheckboxItem {...props} ref={forwardedRef}>
|
|
|
|
{children}
|
|
|
|
<DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
<CheckCircleIcon />
|
|
|
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
</DropdownMenuPrimitive.CheckboxItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
DropdownMenuCheckboxItem.displayName = "DropdownMenuCheckboxItem";
|
|
|
|
|
|
|
|
export const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
|
|
|
|
|
|
|
type DropdownMenuRadioItemProps = ComponentProps<typeof DropdownMenuPrimitive["RadioItem"]>;
|
|
|
|
export const DropdownMenuRadioItem = forwardRef<HTMLDivElement, DropdownMenuRadioItemProps>(
|
|
|
|
({ children, ...props }, forwardedRef) => {
|
|
|
|
return (
|
|
|
|
<DropdownMenuPrimitive.RadioItem {...props} ref={forwardedRef}>
|
|
|
|
{children}
|
|
|
|
<DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
<CheckCircleIcon />
|
|
|
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
</DropdownMenuPrimitive.RadioItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
DropdownMenuRadioItem.displayName = "DropdownMenuRadioItem";
|
|
|
|
|
2022-09-02 11:10:55 +00:00
|
|
|
type DropdownItemProps = {
|
|
|
|
children: React.ReactNode;
|
|
|
|
color?: "destructive";
|
|
|
|
StartIcon?: Icon;
|
|
|
|
EndIcon?: Icon;
|
|
|
|
href?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
} & 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) {
|
|
|
|
return <Link href={href}>{content}</Link>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const DropdownItem = (props: DropdownItemProps) => {
|
|
|
|
const { StartIcon, EndIcon } = props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ButtonOrLink
|
|
|
|
{...props}
|
|
|
|
className={classNames(
|
2022-09-06 17:56:13 +00:00
|
|
|
"inline-flex items-center px-3 py-2 text-gray-700 hover:text-gray-900",
|
2022-09-02 11:10:55 +00:00
|
|
|
props.color === "destructive" ? "hover:bg-red-100 hover:text-red-700" : " hover:bg-gray-100"
|
|
|
|
)}>
|
|
|
|
<>
|
|
|
|
{StartIcon && <StartIcon />}
|
2022-09-06 17:56:13 +00:00
|
|
|
<div className="mx-2">{props.children}</div>
|
2022-09-02 11:10:55 +00:00
|
|
|
{EndIcon && <EndIcon />}
|
|
|
|
</>
|
|
|
|
</ButtonOrLink>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-07-23 00:39:50 +00:00
|
|
|
export const DropdownMenuSeparator = DropdownMenuPrimitive.Separator;
|
|
|
|
|
|
|
|
export default Dropdown;
|