2022-07-23 00:39:50 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { ComponentProps } from "react";
|
|
|
|
import { Fragment } from "react";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { SVGComponent } from "@calcom/types/SVGComponent";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
2023-04-12 15:26:31 +00:00
|
|
|
import { ChevronRight, ExternalLink } from "../../icon";
|
2023-01-10 12:25:39 +00:00
|
|
|
import { Skeleton } from "../../skeleton";
|
2022-09-21 16:01:47 +00:00
|
|
|
|
2022-09-18 23:14:57 +00:00
|
|
|
export type VerticalTabItemProps = {
|
2022-07-23 00:39:50 +00:00
|
|
|
name: string;
|
|
|
|
info?: string;
|
|
|
|
icon?: SVGComponent;
|
|
|
|
disabled?: boolean;
|
2022-09-18 23:14:57 +00:00
|
|
|
children?: VerticalTabItemProps[];
|
2022-08-26 00:11:41 +00:00
|
|
|
textClassNames?: string;
|
|
|
|
className?: string;
|
2022-08-09 09:21:15 +00:00
|
|
|
isChild?: boolean;
|
2022-09-05 21:22:28 +00:00
|
|
|
hidden?: boolean;
|
2022-09-12 20:26:42 +00:00
|
|
|
disableChevron?: boolean;
|
2022-09-18 23:14:57 +00:00
|
|
|
href: string;
|
2022-09-22 15:33:59 +00:00
|
|
|
isExternalLink?: boolean;
|
2022-09-18 23:14:57 +00:00
|
|
|
linkProps?: Omit<ComponentProps<typeof Link>, "href">;
|
2022-12-26 10:23:03 +00:00
|
|
|
avatar?: string;
|
2022-09-18 23:14:57 +00:00
|
|
|
};
|
2022-07-23 00:39:50 +00:00
|
|
|
|
2022-09-18 23:14:57 +00:00
|
|
|
const VerticalTabItem = function ({
|
2022-09-12 20:26:42 +00:00
|
|
|
name,
|
|
|
|
href,
|
|
|
|
info,
|
|
|
|
isChild,
|
|
|
|
disableChevron,
|
2022-09-18 23:14:57 +00:00
|
|
|
linkProps,
|
2022-09-12 20:26:42 +00:00
|
|
|
...props
|
2022-09-18 23:14:57 +00:00
|
|
|
}: VerticalTabItemProps) {
|
2022-07-23 00:39:50 +00:00
|
|
|
const { t } = useLocale();
|
2022-09-18 23:14:57 +00:00
|
|
|
const { asPath } = useRouter();
|
|
|
|
const isCurrent = asPath.startsWith(href);
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment key={name}>
|
2022-09-05 21:22:28 +00:00
|
|
|
{!props.hidden && (
|
|
|
|
<>
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link
|
|
|
|
key={name}
|
|
|
|
href={href}
|
|
|
|
{...linkProps}
|
|
|
|
target={props.isExternalLink ? "_blank" : "_self"}
|
|
|
|
className={classNames(
|
2023-04-05 18:14:46 +00:00
|
|
|
props.textClassNames || "text-default text-sm font-medium leading-none",
|
|
|
|
"min-h-8 hover:bg-subtle [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis group-hover:text-default group flex w-64 flex-row items-center rounded-md px-3 py-[10px]",
|
2023-01-06 12:13:56 +00:00
|
|
|
props.disabled && "pointer-events-none !opacity-30",
|
|
|
|
(isChild || !props.icon) && "ml-7 w-auto ltr:mr-5 rtl:ml-5",
|
|
|
|
!info ? "h-6" : "h-14",
|
|
|
|
props.className
|
|
|
|
)}
|
|
|
|
data-testid={`vertical-tab-${name}`}
|
|
|
|
aria-current={isCurrent ? "page" : undefined}>
|
|
|
|
{props.icon && (
|
2023-03-08 23:16:26 +00:00
|
|
|
<props.icon className="h-[16px] w-[16px] stroke-[2px] ltr:mr-2 rtl:ml-2 md:mt-0" />
|
2023-01-06 12:13:56 +00:00
|
|
|
)}
|
|
|
|
<div className="h-fit">
|
|
|
|
<span className="flex items-center space-x-2 rtl:space-x-reverse">
|
2023-02-03 16:49:33 +00:00
|
|
|
<Skeleton title={t(name)} as="p" className="max-w-36 min-h-4 mt-px truncate">
|
2023-01-06 12:13:56 +00:00
|
|
|
{t(name)}
|
|
|
|
</Skeleton>
|
2023-04-12 15:26:31 +00:00
|
|
|
{props.isExternalLink ? <ExternalLink /> : null}
|
2023-01-06 12:13:56 +00:00
|
|
|
</span>
|
|
|
|
{info && (
|
|
|
|
<Skeleton as="p" title={t(info)} className="max-w-44 mt-1 truncate text-xs font-normal">
|
|
|
|
{t(info)}
|
|
|
|
</Skeleton>
|
2022-09-05 21:22:28 +00:00
|
|
|
)}
|
2023-01-06 12:13:56 +00:00
|
|
|
</div>
|
|
|
|
{!disableChevron && isCurrent && (
|
|
|
|
<div className="ml-auto self-center">
|
2023-04-12 15:26:31 +00:00
|
|
|
<ChevronRight
|
2023-01-06 12:13:56 +00:00
|
|
|
width={20}
|
|
|
|
height={20}
|
2023-04-05 18:14:46 +00:00
|
|
|
className="text-default h-auto w-[20px] stroke-[1.5px]"
|
2023-01-06 12:13:56 +00:00
|
|
|
/>
|
2022-09-05 21:22:28 +00:00
|
|
|
</div>
|
2023-01-06 12:13:56 +00:00
|
|
|
)}
|
2022-09-05 21:22:28 +00:00
|
|
|
</Link>
|
|
|
|
{props.children?.map((child) => (
|
2022-09-18 23:14:57 +00:00
|
|
|
<VerticalTabItem key={child.name} {...child} isChild />
|
2022-09-05 21:22:28 +00:00
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
2022-07-23 00:39:50 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default VerticalTabItem;
|