2022-07-27 22:12:27 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
2022-08-03 16:01:29 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-08-02 09:35:48 +00:00
|
|
|
import { useUrlMatchesCurrentUrl } from "@calcom/lib/hooks/useUrlMatchesCurrentUrl";
|
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;
|
2023-07-18 21:18:08 +00:00
|
|
|
linkShallow?: boolean;
|
|
|
|
linkScroll?: boolean;
|
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-07-18 21:18:08 +00:00
|
|
|
const HorizontalTabItem = function ({
|
|
|
|
name,
|
|
|
|
href,
|
|
|
|
linkShallow,
|
|
|
|
linkScroll,
|
|
|
|
avatar,
|
|
|
|
...props
|
|
|
|
}: HorizontalTabItemProps) {
|
2022-09-15 19:53:09 +00:00
|
|
|
const { t, isLocaleReady } = useLocale();
|
2023-01-31 19:54:40 +00:00
|
|
|
|
2023-08-02 09:35:48 +00:00
|
|
|
const isCurrent = useUrlMatchesCurrentUrl(href);
|
2022-07-27 22:12:27 +00:00
|
|
|
|
|
|
|
return (
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link
|
|
|
|
key={name}
|
|
|
|
href={href}
|
2023-07-18 21:18:08 +00:00
|
|
|
shallow={linkShallow}
|
|
|
|
scroll={linkScroll}
|
2023-01-06 12:13:56 +00:00
|
|
|
className={classNames(
|
2023-06-05 05:51:19 +00:00
|
|
|
isCurrent ? "bg-emphasis 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;
|