change and add into components, widgets and pages
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import React from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Button, type ButtonProps } from '@/components/ui/Button';
|
||||
|
||||
export interface BackButtonProps extends Omit<ButtonProps, 'onClick'> {
|
||||
/** Route explicite vers laquelle naviguer (ex: "/support"). Si non spécifié, fait un retour arrière navigateur (-1) */
|
||||
to?: string;
|
||||
/** Texte à afficher à côté de la flèche */
|
||||
label?: string;
|
||||
/** Callback optionnel si vous souhaitez intercepter le clic */
|
||||
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
||||
}
|
||||
|
||||
export const BackButton: React.FC<BackButtonProps> = ({
|
||||
to,
|
||||
label = "Retour",
|
||||
onClick,
|
||||
variant = "ghost",
|
||||
size = "sm",
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}) => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
if (onClick) {
|
||||
onClick(e);
|
||||
} else if (to) {
|
||||
navigate(to);
|
||||
} else {
|
||||
navigate(-1); // Comportement natif "Précédent" dans l'historique
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant={variant}
|
||||
size={size}
|
||||
onClick={handleClick}
|
||||
leftIcon={
|
||||
<svg
|
||||
className="w-4 h-4 transition-transform group-hover:-translate-x-0.5"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 19l-7-7 7-7" />
|
||||
</svg>
|
||||
}
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
{children || label}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
export default BackButton;
|
||||
Reference in New Issue
Block a user