2024-06-11 16:48:09 +00:00
|
|
|
import { Button, ButtonProps } from "@/ui";
|
|
|
|
|
import { ChevronLeft } from "lucide-react";
|
|
|
|
|
import { To, useNavigate } from "react-router-dom";
|
2024-07-03 15:15:52 +00:00
|
|
|
import { CustomButton } from "../Buttons/CustomButton";
|
2024-06-11 16:48:09 +00:00
|
|
|
|
|
|
|
|
export interface BackHistoryButtonProps extends ButtonProps {
|
|
|
|
|
label?: string;
|
|
|
|
|
url?: To;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const BackHistoryButton = ({
|
|
|
|
|
label = "Volver atrás",
|
|
|
|
|
size,
|
|
|
|
|
url = undefined,
|
|
|
|
|
...props
|
|
|
|
|
}: BackHistoryButtonProps): JSX.Element => {
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
2024-07-03 15:15:52 +00:00
|
|
|
return (
|
|
|
|
|
<CustomButton
|
|
|
|
|
type='button'
|
|
|
|
|
label={label}
|
|
|
|
|
icon={ChevronLeft}
|
|
|
|
|
variant='ghost'
|
|
|
|
|
onClick={() => {
|
|
|
|
|
url ? navigate(url) : navigate(-1);
|
|
|
|
|
}}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2024-06-11 16:48:09 +00:00
|
|
|
return (
|
|
|
|
|
<Button
|
2024-07-03 15:15:52 +00:00
|
|
|
variant='ghost'
|
2024-06-11 16:48:09 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
url ? navigate(url) : navigate(-1);
|
|
|
|
|
}}
|
|
|
|
|
size={size}
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
2024-07-03 15:15:52 +00:00
|
|
|
<ChevronLeft className='w-4 h-4' />
|
2024-06-11 16:48:09 +00:00
|
|
|
<span className={size === "icon" ? "sr-only" : "ml-2"}>{label}</span>
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
};
|