Initial attendee management
This commit is contained in:
@@ -3,3 +3,6 @@ export { Button, type ButtonProps, type ButtonVariant, type ButtonSize } from '.
|
||||
export { Badge, type BadgeProps, type BadgeVariant } from './badge'
|
||||
export { Input, type InputProps } from './input'
|
||||
export { Label, type LabelProps } from './label'
|
||||
export { Modal, type ModalProps } from './modal'
|
||||
export { ToastProvider, useToast, type ToastType, type Toast } from './toast'
|
||||
|
||||
|
||||
91
apps/web/src/components/ui/modal.tsx
Normal file
91
apps/web/src/components/ui/modal.tsx
Normal file
@@ -0,0 +1,91 @@
|
||||
import { useEffect, type ReactNode } from 'react';
|
||||
import { X } from 'lucide-react';
|
||||
import { cn } from '../../lib/utils';
|
||||
|
||||
export type ModalProps = {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
title: string;
|
||||
description?: string;
|
||||
children: ReactNode;
|
||||
maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
||||
};
|
||||
|
||||
const maxWidthClasses = {
|
||||
sm: 'max-w-sm',
|
||||
md: 'max-w-md',
|
||||
lg: 'max-w-lg',
|
||||
xl: 'max-w-xl',
|
||||
'2xl': 'max-w-2xl',
|
||||
};
|
||||
|
||||
export function Modal({
|
||||
isOpen,
|
||||
onClose,
|
||||
title,
|
||||
description,
|
||||
children,
|
||||
maxWidth = 'lg',
|
||||
}: ModalProps) {
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('keydown', handleKeyDown);
|
||||
document.body.style.overflow = 'hidden';
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('keydown', handleKeyDown);
|
||||
document.body.style.overflow = 'unset';
|
||||
};
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-4 overflow-y-auto"
|
||||
>
|
||||
{/* Backdrop */}
|
||||
<div
|
||||
className="fixed inset-0 bg-black/60 backdrop-blur-xs transition-opacity animate-fade-in"
|
||||
onClick={onClose}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
{/* Modal Dialog */}
|
||||
<div
|
||||
className={cn(
|
||||
'relative w-full rounded-2xl border border-border bg-surface p-6 shadow-2xl transition-all animate-step-enter my-8',
|
||||
maxWidthClasses[maxWidth],
|
||||
)}
|
||||
>
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="min-w-0 flex-1">
|
||||
<h2 className="text-lg font-bold text-primary">{title}</h2>
|
||||
{description ? (
|
||||
<p className="mt-1 text-sm text-foreground/70">{description}</p>
|
||||
) : null}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="shrink-0 -mr-2 -mt-2 p-2 rounded-xl text-foreground/40 hover:text-foreground hover:bg-primary-soft transition-colors"
|
||||
aria-label="Cerrar modal"
|
||||
>
|
||||
<X className="size-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-5">{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
146
apps/web/src/components/ui/toast.tsx
Normal file
146
apps/web/src/components/ui/toast.tsx
Normal file
@@ -0,0 +1,146 @@
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from 'react';
|
||||
import { AlertCircle, CheckCircle2, Info, X } from 'lucide-react';
|
||||
import { cn } from '../../lib/utils';
|
||||
|
||||
export type ToastType = 'success' | 'error' | 'info';
|
||||
|
||||
export type Toast = {
|
||||
id: string;
|
||||
type: ToastType;
|
||||
title?: string;
|
||||
message: string;
|
||||
duration?: number;
|
||||
};
|
||||
|
||||
type ToastContextValue = {
|
||||
toasts: Toast[];
|
||||
showToast: (toast: Omit<Toast, 'id'>) => string;
|
||||
removeToast: (id: string) => void;
|
||||
success: (message: string, title?: string) => string;
|
||||
error: (message: string, title?: string) => string;
|
||||
info: (message: string, title?: string) => string;
|
||||
};
|
||||
|
||||
const ToastContext = createContext<ToastContextValue | null>(null);
|
||||
|
||||
export function ToastProvider({ children }: { children: ReactNode }) {
|
||||
const [toasts, setToasts] = useState<Toast[]>([]);
|
||||
|
||||
const removeToast = useCallback((id: string) => {
|
||||
setToasts((prev) => prev.filter((t) => t.id !== id));
|
||||
}, []);
|
||||
|
||||
const showToast = useCallback(
|
||||
({ type, title, message, duration = 4000 }: Omit<Toast, 'id'>) => {
|
||||
const id = `${Date.now()}-${Math.random().toString(36).slice(2, 7)}`;
|
||||
const newToast: Toast = { id, type, title, message, duration };
|
||||
|
||||
setToasts((prev) => [...prev, newToast]);
|
||||
|
||||
if (duration > 0) {
|
||||
setTimeout(() => {
|
||||
removeToast(id);
|
||||
}, duration);
|
||||
}
|
||||
|
||||
return id;
|
||||
},
|
||||
[removeToast],
|
||||
);
|
||||
|
||||
const success = useCallback(
|
||||
(message: string, title?: string) => showToast({ type: 'success', title, message }),
|
||||
[showToast],
|
||||
);
|
||||
|
||||
const error = useCallback(
|
||||
(message: string, title?: string) => showToast({ type: 'error', title, message }),
|
||||
[showToast],
|
||||
);
|
||||
|
||||
const info = useCallback(
|
||||
(message: string, title?: string) => showToast({ type: 'info', title, message }),
|
||||
[showToast],
|
||||
);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
toasts,
|
||||
showToast,
|
||||
removeToast,
|
||||
success,
|
||||
error,
|
||||
info,
|
||||
}),
|
||||
[toasts, showToast, removeToast, success, error, info],
|
||||
);
|
||||
|
||||
return (
|
||||
<ToastContext.Provider value={value}>
|
||||
{children}
|
||||
{/* Toast Container */}
|
||||
<div
|
||||
aria-live="polite"
|
||||
className="fixed bottom-4 right-4 z-50 flex max-w-sm w-full flex-col gap-2 pointer-events-none px-4 sm:px-0"
|
||||
>
|
||||
{toasts.map((toast) => (
|
||||
<div
|
||||
key={toast.id}
|
||||
role="alert"
|
||||
className={cn(
|
||||
'pointer-events-auto flex items-start gap-3 rounded-xl border p-4 shadow-lg backdrop-blur-sm transition-all animate-fade-in bg-surface',
|
||||
toast.type === 'success' && 'border-success/30 text-primary',
|
||||
toast.type === 'error' && 'border-danger/30 text-primary',
|
||||
toast.type === 'info' && 'border-border text-primary',
|
||||
)}
|
||||
>
|
||||
<div className="shrink-0 mt-0.5">
|
||||
{toast.type === 'success' && (
|
||||
<CheckCircle2 className="size-5 text-success" />
|
||||
)}
|
||||
{toast.type === 'error' && (
|
||||
<AlertCircle className="size-5 text-danger" />
|
||||
)}
|
||||
{toast.type === 'info' && (
|
||||
<Info className="size-5 text-accent" />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
{toast.title ? (
|
||||
<p className="font-semibold text-sm text-primary">{toast.title}</p>
|
||||
) : null}
|
||||
<p className="text-sm text-foreground/80 leading-relaxed break-words">
|
||||
{toast.message}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeToast(toast.id)}
|
||||
className="shrink-0 -mr-1 -mt-1 p-1 rounded-lg text-foreground/40 hover:text-foreground hover:bg-primary-soft transition-colors"
|
||||
aria-label="Cerrar notificación"
|
||||
>
|
||||
<X className="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ToastContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useToast() {
|
||||
const ctx = useContext(ToastContext);
|
||||
if (!ctx) {
|
||||
throw new Error('useToast debe utilizarse dentro de un <ToastProvider>');
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
Reference in New Issue
Block a user