2025-11-06 11:53:46 +08:00
|
|
|
import { cn } from '@/lib/utils';
|
2025-11-12 09:36:48 +08:00
|
|
|
import { t } from 'i18next';
|
2025-11-06 11:53:46 +08:00
|
|
|
import { ArrowBigLeft } from 'lucide-react';
|
|
|
|
|
import React from 'react';
|
2026-01-04 19:14:20 +08:00
|
|
|
import { useNavigate } from 'react-router';
|
2025-11-06 11:53:46 +08:00
|
|
|
import { Button } from '../ui/button';
|
|
|
|
|
|
2026-01-04 19:14:20 +08:00
|
|
|
interface BackButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
2025-11-06 11:53:46 +08:00
|
|
|
to?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BackButton: React.FC<BackButtonProps> = ({
|
|
|
|
|
to,
|
|
|
|
|
className,
|
|
|
|
|
children,
|
|
|
|
|
...props
|
|
|
|
|
}) => {
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
|
if (to) {
|
|
|
|
|
navigate(to);
|
|
|
|
|
} else {
|
|
|
|
|
navigate(-1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
2025-11-21 09:33:50 +08:00
|
|
|
className={cn(
|
|
|
|
|
'gap-2 bg-bg-card border border-border-default hover:bg-border-button hover:text-text-primary',
|
|
|
|
|
className,
|
|
|
|
|
)}
|
2025-11-06 11:53:46 +08:00
|
|
|
onClick={handleClick}
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
<ArrowBigLeft className="h-4 w-4" />
|
2025-11-12 09:36:48 +08:00
|
|
|
{children || t('common.back')}
|
2025-11-06 11:53:46 +08:00
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default BackButton;
|