myagent10101's picture
feat: Complete CodeSync collaborative coding platform
8f9c4ef verified
Raw History Blame Contribute Delete
5.08 kB
// ─────────────────────────────────────────────────────────────
// UI Components β€” Reusable UI primitives
// ─────────────────────────────────────────────────────────────
'use client';
import { forwardRef, type ButtonHTMLAttributes, type InputHTMLAttributes } from 'react';
import { cn } from '../../lib/utils';
// ─── Button ──────────────────────────────────────────────────
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
size?: 'sm' | 'md' | 'lg';
}
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant = 'primary', size = 'md', ...props }, ref) => {
const variants = {
primary: 'bg-editor-accent hover:bg-editor-accent-hover text-white',
secondary: 'bg-editor-surface hover:bg-editor-hover text-editor-text border border-editor-border',
ghost: 'hover:bg-editor-hover text-editor-text-muted hover:text-editor-text',
danger: 'bg-editor-error hover:bg-red-600 text-white',
};
const sizes = {
sm: 'px-2.5 py-1 text-xs',
md: 'px-4 py-2 text-sm',
lg: 'px-6 py-2.5 text-base',
};
return (
<button
ref={ref}
className={cn(
'inline-flex items-center justify-center rounded-md font-medium transition-colors focus-ring disabled:opacity-50 disabled:pointer-events-none',
variants[variant],
sizes[size],
className
)}
{...props}
/>
);
}
);
Button.displayName = 'Button';
// ─── Input ───────────────────────────────────────────────────
export const Input = forwardRef<HTMLInputElement, InputHTMLAttributes<HTMLInputElement>>(
({ className, ...props }, ref) => (
<input
ref={ref}
className={cn('input-field w-full', className)}
{...props}
/>
)
);
Input.displayName = 'Input';
// ─── Skeleton ────────────────────────────────────────────────
export function Skeleton({ className }: { className?: string }) {
return (
<div className={cn('animate-pulse rounded bg-editor-hover', className)} />
);
}
// ─── Badge ───────────────────────────────────────────────────
interface BadgeProps {
children: React.ReactNode;
variant?: 'default' | 'success' | 'warning' | 'error';
className?: string;
}
export function Badge({ children, variant = 'default', className }: BadgeProps) {
const variants = {
default: 'bg-editor-hover text-editor-text-muted',
success: 'bg-editor-success/10 text-editor-success',
warning: 'bg-editor-warning/10 text-editor-warning',
error: 'bg-editor-error/10 text-editor-error',
};
return (
<span
className={cn(
'inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium',
variants[variant],
className
)}
>
{children}
</span>
);
}
// ─── Modal ───────────────────────────────────────────────────
interface ModalProps {
isOpen: boolean;
onClose: () => void;
title: string;
children: React.ReactNode;
}
export function Modal({ isOpen, onClose, title, children }: ModalProps) {
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center">
<div className="absolute inset-0 bg-black/60 backdrop-blur-sm" onClick={onClose} />
<div className="relative w-full max-w-md rounded-lg border border-editor-border bg-editor-surface p-6 shadow-xl animate-fade-in">
<h2 className="text-lg font-bold mb-4">{title}</h2>
{children}
</div>
</div>
);
}
// ─── Tooltip ─────────────────────────────────────────────────
interface TooltipProps {
children: React.ReactNode;
content: string;
}
export function Tooltip({ children, content }: TooltipProps) {
return (
<div className="group relative inline-flex">
{children}
<div className="pointer-events-none absolute -top-8 left-1/2 -translate-x-1/2 opacity-0 transition-opacity group-hover:opacity-100">
<div className="rounded bg-editor-bg border border-editor-border px-2 py-1 text-[10px] text-editor-text whitespace-nowrap shadow-lg">
{content}
</div>
</div>
</div>
);
}