feat(ui): enhance UI with animations, dark mode support and and improved components

- Add framer-motion page transitions and AnimatePresence support
- Add dark mode support across all components
- Create reusable UI components (Button, Badge, Card, EmptyState, Input, Toast, Skeleton)
- Add CSS custom properties for consistent theming
- Add animation variants and utility functions
- Improve ChatArea, Sidebar, TriggersPanel with animations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-03-15 17:24:40 +08:00
parent 308994121c
commit e3d164e9d2
18 changed files with 772 additions and 108 deletions

View File

@@ -0,0 +1,32 @@
import { cn } from '../../lib/utils';
type BadgeVariant = 'default' | 'primary' | 'success' | 'warning' | 'error' | 'info';
interface BadgeProps {
children: React.ReactNode;
variant?: BadgeVariant;
className?: string;
}
const variantStyles: Record<BadgeVariant, string> = {
default: 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300',
primary: 'bg-primary-light text-primary',
success: 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400',
warning: 'bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400',
error: 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400',
info: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400',
};
export function Badge({ children, variant = 'default', className }: BadgeProps) {
return (
<span
className={cn(
'inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium',
variantStyles[variant],
className
)}
>
{children}
</span>
);
}

View File

@@ -0,0 +1,54 @@
import { forwardRef } from 'react';
import { motion, HTMLMotionProps } from 'framer-motion';
import { cn } from '../../lib/utils';
import { Loader2 } from 'lucide-react';
export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger' | 'outline';
export type ButtonSize = 'sm' | 'md' | 'lg';
export interface ButtonProps extends Omit<HTMLMotionProps<'button'>, 'children'> {
variant?: ButtonVariant;
size?: ButtonSize;
loading?: boolean;
children?: React.ReactNode;
}
const variantStyles: Record<ButtonVariant, string> = {
primary: 'bg-primary text-white hover:bg-primary-hover',
secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-100 dark:hover:bg-gray-600',
ghost: 'text-gray-600 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700',
danger: 'bg-red-500 text-white hover:bg-red-600',
outline: 'border border-gray-300 text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-800',
};
const sizeStyles: Record<ButtonSize, string> = {
sm: 'px-3 py-1.5 text-xs rounded-md',
md: 'px-4 py-2 text-sm rounded-lg',
lg: 'px-6 py-3 text-base rounded-lg',
};
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant = 'primary', size = 'md', loading, disabled, children, ...props }, ref) => {
return (
<motion.button
ref={ref}
whileTap={{ scale: 0.98 }}
className={cn(
'inline-flex items-center justify-center font-medium transition-colors duration-fast',
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2',
'disabled:opacity-50 disabled:cursor-not-allowed',
variantStyles[variant],
sizeStyles[size],
className
)}
disabled={disabled || loading}
{...props}
>
{loading && <Loader2 className="w-4 h-4 mr-2 animate-spin" />}
{children}
</motion.button>
);
}
);
Button.displayName = 'Button';

View File

@@ -0,0 +1,64 @@
import { motion, HTMLMotionProps } from 'framer-motion';
import { cn } from '../../lib/utils';
import { cardHover } from '../../lib/animations';
interface CardProps extends Omit<HTMLMotionProps<'div'>, 'children'> {
children: React.ReactNode;
hoverable?: boolean;
}
export function Card({ children, className, hoverable = false, ...props }: CardProps) {
return (
<motion.div
className={cn(
'rounded-xl border border-gray-200 bg-white p-4 shadow-sm',
'dark:border-gray-700 dark:bg-gray-800',
hoverable && 'cursor-pointer transition-shadow duration-200',
className
)}
{...(hoverable && { whileHover: cardHover })}
{...props}
>
{children}
</motion.div>
);
}
interface CardHeaderProps {
children: React.ReactNode;
className?: string;
}
export function CardHeader({ children, className }: CardHeaderProps) {
return (
<div className={cn('mb-3', className)}>
{children}
</div>
);
}
interface CardTitleProps {
children: React.ReactNode;
className?: string;
}
export function CardTitle({ children, className }: CardTitleProps) {
return (
<h3 className={cn('text-sm font-semibold text-gray-900 dark:text-gray-100', className)}>
{children}
</h3>
);
}
interface CardContentProps {
children: React.ReactNode;
className?: string;
}
export function CardContent({ children, className }: CardContentProps) {
return (
<div className={cn('text-sm text-gray-600 dark:text-gray-300', className)}>
{children}
</div>
);
}

View File

@@ -0,0 +1,28 @@
import { cn } from '../../lib/utils';
interface EmptyStateProps {
icon: React.ReactNode;
title: string;
description: string;
action?: React.ReactNode;
className?: string;
}
export function EmptyState({ icon, title, description, action, className }: EmptyStateProps) {
return (
<div className={cn('flex-1 flex items-center justify-center p-6', className)}>
<div className="text-center max-w-sm">
<div className="w-16 h-16 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center mx-auto mb-4 text-gray-400">
{icon}
</div>
<h3 className="text-base font-semibold text-gray-700 dark:text-gray-300 mb-2">
{title}
</h3>
<p className="text-sm text-gray-500 dark:text-gray-400 mb-4">
{description}
</p>
{action}
</div>
</div>
);
}

View File

@@ -0,0 +1,45 @@
import { forwardRef, InputHTMLAttributes } from 'react';
import { cn } from '../../lib/utils';
export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
label?: string;
error?: string;
}
export const Input = forwardRef<HTMLInputElement, InputProps>(
({ className, label, error, id, ...props }, ref) => {
const inputId = id || label?.toLowerCase().replace(/\s+/g, '-');
return (
<div className="w-full">
{label && (
<label
htmlFor={inputId}
className="block text-xs text-gray-500 dark:text-gray-400 mb-1"
>
{label}
</label>
)}
<input
ref={ref}
id={inputId}
className={cn(
'w-full text-sm border border-gray-200 rounded-lg px-3 py-2',
'bg-white dark:bg-gray-800 dark:border-gray-700 dark:text-gray-100',
'placeholder:text-gray-400 dark:placeholder:text-gray-500',
'focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent',
'transition-colors duration-fast',
error && 'border-red-500 focus:ring-red-500',
className
)}
{...props}
/>
{error && (
<p className="mt-1 text-xs text-red-500">{error}</p>
)}
</div>
);
}
);
Input.displayName = 'Input';

View File

@@ -0,0 +1,42 @@
import { cn } from '../../lib/utils';
interface SkeletonProps {
className?: string;
}
export function Skeleton({ className }: SkeletonProps) {
return (
<div
className={cn(
'animate-pulse bg-gray-200 dark:bg-gray-700 rounded',
className
)}
/>
);
}
export function CardSkeleton() {
return (
<div className="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-4">
<Skeleton className="h-4 w-24 mb-3" />
<Skeleton className="h-3 w-full mb-2" />
<Skeleton className="h-3 w-3/4" />
</div>
);
}
export function ListSkeleton({ count = 3 }: { count?: number }) {
return (
<div className="space-y-2">
{Array.from({ length: count }).map((_, i) => (
<div key={i} className="flex items-center gap-3 p-2">
<Skeleton className="w-8 h-8 rounded-full" />
<div className="flex-1">
<Skeleton className="h-3 w-24 mb-1" />
<Skeleton className="h-2 w-32" />
</div>
</div>
))}
</div>
);
}

View File

@@ -0,0 +1,89 @@
import { useState, useCallback, createContext, useContext } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { X, CheckCircle, AlertCircle, Info, AlertTriangle } from 'lucide-react';
import { cn } from '../../lib/utils';
type ToastType = 'success' | 'error' | 'info' | 'warning';
interface Toast {
id: string;
message: string;
type: ToastType;
}
interface ToastContextType {
toast: (message: string, type?: ToastType) => void;
}
const ToastContext = createContext<ToastContextType | null>(null);
export function useToast() {
const context = useContext(ToastContext);
if (!context) {
throw new Error('useToast must be used within a ToastProvider');
}
return context;
}
const iconMap: Record<ToastType, React.ReactNode> = {
success: <CheckCircle className="w-5 h-5 text-green-500" />,
error: <AlertCircle className="w-5 h-5 text-red-500" />,
info: <Info className="w-5 h-5 text-blue-500" />,
warning: <AlertTriangle className="w-5 h-5 text-yellow-500" />,
};
const styleMap: Record<ToastType, string> = {
success: 'bg-green-50 border-green-200 dark:bg-green-900/20 dark:border-green-800',
error: 'bg-red-50 border-red-200 dark:bg-red-900/20 dark:border-red-800',
info: 'bg-blue-50 border-blue-200 dark:bg-blue-900/20 dark:border-blue-800',
warning: 'bg-yellow-50 border-yellow-200 dark:bg-yellow-900/20 dark:border-yellow-800',
};
export function ToastProvider({ children }: { children: React.ReactNode }) {
const [toasts, setToasts] = useState<Toast[]>([]);
const toast = useCallback((message: string, type: ToastType = 'info') => {
const id = Date.now().toString();
setToasts((prev) => [...prev, { id, message, type }]);
setTimeout(() => {
setToasts((prev) => prev.filter((t) => t.id !== id));
}, 3000);
}, []);
const removeToast = useCallback((id: string) => {
setToasts((prev) => prev.filter((t) => t.id !== id));
}, []);
return (
<ToastContext.Provider value={{ toast }}>
{children}
<div className="fixed bottom-4 right-4 z-50 space-y-2">
<AnimatePresence>
{toasts.map((t) => (
<motion.div
key={t.id}
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
className={cn(
'flex items-center gap-3 px-4 py-3 rounded-lg border shadow-lg',
'bg-white dark:bg-gray-800',
styleMap[t.type]
)}
>
{iconMap[t.type]}
<span className="text-sm text-gray-700 dark:text-gray-200">{t.message}</span>
<button
onClick={() => removeToast(t.id)}
className="ml-2 text-gray-400 hover:text-gray-600"
aria-label="Close"
>
<X className="w-4 h-4" />
</button>
</motion.div>
))}
</AnimatePresence>
</div>
</ToastContext.Provider>
);
}

View File

@@ -0,0 +1,15 @@
export { Button } from './Button';
export type { ButtonProps } from './Button';
export { Card, CardHeader, CardTitle, CardContent } from './Card';
export { Input } from './Input';
export type { InputProps } from './Input';
export { Badge } from './Badge';
export { Skeleton, CardSkeleton, ListSkeleton } from './Skeleton';
export { EmptyState } from './EmptyState';
export { ToastProvider, useToast } from './Toast';