2022-07-27 22:12:27 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
2022-09-18 23:14:57 +00:00
|
|
|
import { 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";
|
2022-09-19 11:34:30 +00:00
|
|
|
import { SVGComponent } from "@calcom/types/SVGComponent";
|
2022-07-27 22:12:27 +00:00
|
|
|
|
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;
|
2022-09-18 23:14:57 +00:00
|
|
|
};
|
2022-07-27 22:12:27 +00:00
|
|
|
|
2022-09-18 23:14:57 +00:00
|
|
|
const HorizontalTabItem = function ({ name, href, linkProps, ...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();
|
|
|
|
const isCurrent = asPath.startsWith(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(
|
|
|
|
isCurrent ? "bg-gray-200 text-gray-900" : " text-gray-600 hover:bg-gray-100 hover:text-gray-900 ",
|
|
|
|
"inline-flex items-center justify-center whitespace-nowrap rounded-[4px] py-[10px] px-4 text-sm font-medium leading-4 md:mb-0",
|
|
|
|
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"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{isLocaleReady ? t(name) : <SkeletonText className="h-4 w-24" />}
|
2022-07-27 22:12:27 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default HorizontalTabItem;
|