mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-16 21:37:51 +00:00
- Substitui Dialog básico pelo AlertDialog especializado - Melhora feedback visual na confirmação de deleção - Mantém consistência com o design system - Implementa padrões de acessibilidade do Radix UI
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
import React from 'react';
|
|
import { useButtonTracking } from '../../hooks/useButtonTracking';
|
|
import { ButtonTrackingOptions } from '../../types/analytics';
|
|
import { cn } from '../../lib/utils';
|
|
import { EVENT_CATEGORIES } from '../../constants/analytics';
|
|
|
|
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
as?: 'button' | 'span';
|
|
trackingId: string;
|
|
variant?: 'default' | 'primary' | 'secondary' | 'outline' | 'ghost' | 'link' | 'destructive';
|
|
size?: 'sm' | 'md' | 'lg';
|
|
trackingProperties?: ButtonTrackingOptions;
|
|
}
|
|
|
|
export function buttonVariants({
|
|
variant = 'default',
|
|
size = 'md',
|
|
className = '',
|
|
}: {
|
|
variant?: ButtonProps['variant'];
|
|
size?: ButtonProps['size'];
|
|
className?: string;
|
|
} = {}) {
|
|
return cn(
|
|
'inline-flex items-center justify-center px-4 py-2',
|
|
'text-sm font-medium',
|
|
'rounded-md shadow-sm',
|
|
'transition-colors duration-200',
|
|
'disabled:opacity-50 disabled:cursor-not-allowed',
|
|
{
|
|
'text-white bg-purple-600 hover:bg-purple-700': variant === 'primary' || variant === 'default',
|
|
'text-gray-700 bg-white border border-gray-300 hover:bg-gray-50': variant === 'secondary',
|
|
'text-purple-600 bg-transparent hover:bg-purple-50': variant === 'ghost',
|
|
'text-purple-600 bg-transparent hover:underline': variant === 'link',
|
|
'text-purple-600 border border-purple-600 hover:bg-purple-50': variant === 'outline',
|
|
'text-white bg-red-600 hover:bg-red-700': variant === 'destructive',
|
|
'px-3 py-1.5 text-sm': size === 'sm',
|
|
'px-4 py-2 text-base': size === 'md',
|
|
'px-6 py-3 text-lg': size === 'lg',
|
|
},
|
|
className
|
|
);
|
|
}
|
|
|
|
export function Button({
|
|
as: Component = 'button',
|
|
children,
|
|
className = '',
|
|
trackingId,
|
|
variant = 'default',
|
|
size = 'md',
|
|
trackingProperties,
|
|
onClick,
|
|
disabled,
|
|
type = 'button',
|
|
...props
|
|
}: ButtonProps) {
|
|
const { trackButtonClick } = useButtonTracking({
|
|
category: EVENT_CATEGORIES.INTERACTION,
|
|
element_type: 'button',
|
|
...trackingProperties
|
|
});
|
|
|
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
trackButtonClick(trackingId, {
|
|
variant,
|
|
size,
|
|
...trackingProperties,
|
|
});
|
|
|
|
onClick?.(event);
|
|
};
|
|
|
|
return (
|
|
<Component
|
|
type={Component === 'button' ? type : undefined}
|
|
className={buttonVariants({ variant, size, className })}
|
|
onClick={handleClick}
|
|
disabled={disabled}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</Component>
|
|
);
|
|
}
|