canina/frontend/application/components/BackButton.tsx
parsa aghaei 2d83a00169
All checks were successful
Deploy Canina / deploy (push) Successful in 1m54s
feat(ui): optimize wiki ingredient links, product images, back buttons, and checkout settings
2026-08-17 14:43:36 +03:30

39 lines
1.1 KiB
TypeScript

"use client";
import React from "react";
import { useRouter } from "next/navigation";
import { ChevronLeft } from "lucide-react";
import { cn } from "../lib/utils";
interface BackButtonProps {
className?: string;
label?: string;
}
export default function BackButton({ className, label = "بازگشت" }: BackButtonProps) {
const router = useRouter();
const handleBack = () => {
// router.back() preserves browser history and scroll position natively
if (typeof window !== "undefined" && window.history.length > 1) {
router.back();
} else {
router.push("/");
}
};
return (
<button
type="button"
onClick={handleBack}
className={cn(
"inline-flex items-center gap-1.5 px-4 py-2 bg-white/80 backdrop-blur-sm border border-medical-gray-200 hover:border-canina-blue hover:text-canina-blue text-medical-gray-700 text-xs font-black rounded-xl transition-all shadow-xs active:scale-95 whitespace-nowrap cursor-pointer font-vazir",
className
)}
>
<span>{label}</span>
<ChevronLeft className="w-4 h-4" />
</button>
);
}