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-04-05 18:14:46 +00:00
|
|
|
isCurrent ? "bg-subtle text-emphasis" : " hover:bg-subtle hover:text-emphasis text-default ",
|
2023-02-20 14:11:51 +00:00
|
|
|
"inline-flex items-center justify-center whitespace-nowrap rounded-[6px] p-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-04-05 18:14:46 +00:00
|
|
|
isCurrent ? "text-emphasis" : "group-hover:text-subtle text-muted",
|
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;
|