2022-12-19 13:34:40 +00:00
|
|
|
import { TFunction } from "next-i18next";
|
2022-07-27 23:28:21 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
|
2022-12-15 15:03:57 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
|
2022-07-27 23:28:21 +00:00
|
|
|
type DefaultStep = {
|
|
|
|
title: string;
|
|
|
|
};
|
|
|
|
|
2022-12-07 21:47:02 +00:00
|
|
|
function Stepper<T extends DefaultStep>(props: {
|
|
|
|
href: string;
|
|
|
|
step: number;
|
|
|
|
steps: T[];
|
|
|
|
disableSteps?: boolean;
|
2022-12-19 13:34:40 +00:00
|
|
|
t?: TFunction;
|
2022-12-07 21:47:02 +00:00
|
|
|
}) {
|
2022-12-19 13:34:40 +00:00
|
|
|
let { t } = useLocale();
|
|
|
|
if (props.t) {
|
|
|
|
t = props.t;
|
|
|
|
}
|
2022-07-27 23:28:21 +00:00
|
|
|
const { href, steps } = props;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{steps.length > 1 && (
|
|
|
|
<nav className="flex items-center justify-center" aria-label="Progress">
|
|
|
|
<p className="text-sm font-medium">
|
2022-12-15 15:03:57 +00:00
|
|
|
{t("current_step_of_total", { currentStep: props.step, maxSteps: steps.length })}
|
2022-07-27 23:28:21 +00:00
|
|
|
</p>
|
|
|
|
<ol role="list" className="ml-8 flex items-center space-x-5">
|
|
|
|
{steps.map((mapStep, index) => (
|
|
|
|
<li key={mapStep.title}>
|
2022-12-07 21:47:02 +00:00
|
|
|
<Link href={props.disableSteps ? "#" : `${href}?step=${index + 1}`} shallow replace>
|
2022-07-27 23:28:21 +00:00
|
|
|
{index + 1 < props.step ? (
|
|
|
|
<a className="block h-2.5 w-2.5 rounded-full bg-gray-600 hover:bg-gray-900">
|
|
|
|
<span className="sr-only">{mapStep.title}</span>
|
|
|
|
</a>
|
|
|
|
) : index + 1 === props.step ? (
|
|
|
|
<a className="relative flex items-center justify-center" aria-current="step">
|
|
|
|
<span className="absolute flex h-5 w-5 p-px" aria-hidden="true">
|
|
|
|
<span className="h-full w-full rounded-full bg-gray-200" />
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
className="relative block h-2.5 w-2.5 rounded-full bg-gray-600"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
<span className="sr-only">{mapStep.title}</span>
|
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<a className="block h-2.5 w-2.5 rounded-full bg-gray-200 hover:bg-gray-400">
|
|
|
|
<span className="sr-only">{mapStep.title}</span>
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ol>
|
|
|
|
</nav>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Stepper;
|