2022-07-27 22:12:27 +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";
|
2022-07-27 22:12:27 +00:00
|
|
|
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
2022-08-03 16:01:29 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { SVGComponent } from "@calcom/types/SVGComponent";
|
2022-07-27 22:12:27 +00:00
|
|
|
|
2023-01-31 19:54:40 +00:00
|
|
|
import { Avatar } from "../../avatar";
|
2023-01-10 12:25:39 +00:00
|
|
|
import { SkeletonText } from "../../skeleton";
|
2022-09-15 19:53:09 +00:00
|
|
|
|
2022-09-18 23:14:57 +00:00
|
|
|
export type HorizontalTabItemProps = {
|
2022-07-27 22:12:27 +00:00
|
|
|
name: string;
|
|
|
|
disabled?: boolean;
|
2022-09-02 19:00:41 +00:00
|
|
|
className?: string;
|
2022-09-18 23:14:57 +00:00
|
|
|
href: string;
|
|
|
|
linkProps?: Omit<ComponentProps<typeof Link>, "href">;
|
2022-09-19 11:34:30 +00:00
|
|
|
icon?: SVGComponent;
|
2023-01-31 19:54:40 +00:00
|
|
|
avatar?: string;
|
2022-09-18 23:14:57 +00:00
|
|
|
};
|
2022-07-27 22:12:27 +00:00
|
|
|
|
2023-01-31 19:54:40 +00:00
|
|
|
const HorizontalTabItem = function ({ name, href, linkProps, avatar, ...props }: HorizontalTabItemProps) {
|
2022-09-15 19:53:09 +00:00
|
|
|
const { t, isLocaleReady } = useLocale();
|
2022-09-18 23:14:57 +00:00
|
|
|
const { asPath } = useRouter();
|
2023-01-31 19:54:40 +00:00
|
|
|
|
|
|
|
const isCurrent = asPath === href;
|
2022-07-27 22:12:27 +00:00
|
|
|
|
|
|
|
return (
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link
|
|
|
|
key={name}
|
|
|
|
href={href}
|
|
|
|
{...linkProps}
|
|
|
|
className={classNames(
|
2023-01-31 19:54:40 +00:00
|
|
|
isCurrent ? "bg-gray-100 text-gray-900" : " text-gray-600 hover:bg-gray-100 hover:text-gray-900 ",
|
|
|
|
"inline-flex items-center justify-center whitespace-nowrap rounded-[6px] py-[10px] px-2 text-sm font-medium leading-4 md:mb-0",
|
2023-01-06 12:13:56 +00:00
|
|
|
props.disabled && "pointer-events-none !opacity-30",
|
|
|
|
props.className
|
|
|
|
)}
|
|
|
|
aria-current={isCurrent ? "page" : undefined}>
|
|
|
|
{props.icon && (
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
//@ts-ignore
|
|
|
|
<props.icon
|
|
|
|
className={classNames(
|
2023-01-12 16:57:43 +00:00
|
|
|
isCurrent ? "text-gray-900" : "text-gray-400 group-hover:text-gray-500",
|
2023-01-06 12:13:56 +00:00
|
|
|
"-ml-0.5 hidden h-4 w-4 ltr:mr-2 rtl:ml-2 sm:inline-block"
|
|
|
|
)}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
)}
|
2023-01-31 19:54:40 +00:00
|
|
|
{isLocaleReady ? (
|
|
|
|
<div className="flex items-center gap-x-2">
|
|
|
|
{avatar && <Avatar size="sm" imageSrc={avatar} alt="avatar" />} {t(name)}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<SkeletonText className="h-4 w-24" />
|
|
|
|
)}
|
2022-07-27 22:12:27 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default HorizontalTabItem;
|