'use client'; import { useState, useRef, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Bold, Italic, Underline, List, ListOrdered, Quote, Link, Undo, Redo, Type, AlignLeft, AlignCenter, AlignRight } from 'lucide-react'; interface SimpleEditorProps { data?: string; onChange?: (data: string) => void; placeholder?: string; className?: string; disabled?: boolean; } export default function SimpleEditor({ data = '', onChange, placeholder = 'Start typing...', className = '', disabled = false }: SimpleEditorProps) { const [content, setContent] = useState(data); const editorRef = useRef(null); const [isMounted, setIsMounted] = useState(false); useEffect(() => { setIsMounted(true); }, []); useEffect(() => { setContent(data); }, [data]); const handleInput = () => { if (editorRef.current) { const html = editorRef.current.innerHTML; setContent(html); onChange?.(html); } }; const execCommand = (command: string, value?: string) => { document.execCommand(command, false, value); editorRef.current?.focus(); handleInput(); }; const insertLink = () => { const url = prompt('Enter URL:'); if (url) { execCommand('createLink', url); } }; const toolbarButtons = [ { command: 'bold', icon: Bold, label: 'Bold' }, { command: 'italic', icon: Italic, label: 'Italic' }, { command: 'underline', icon: Underline, label: 'Underline' }, { command: 'insertUnorderedList', icon: List, label: 'Bullet List' }, { command: 'insertOrderedList', icon: ListOrdered, label: 'Numbered List' }, { command: 'formatBlock', icon: Quote, label: 'Quote', value: 'blockquote' }, { command: 'justifyLeft', icon: AlignLeft, label: 'Align Left' }, { command: 'justifyCenter', icon: AlignCenter, label: 'Align Center' }, { command: 'justifyRight', icon: AlignRight, label: 'Align Right' }, { command: 'undo', icon: Undo, label: 'Undo' }, { command: 'redo', icon: Redo, label: 'Redo' }, ]; if (!isMounted) { return (
Loading editor...
); } return (
{/* Toolbar */}
{toolbarButtons.map((button) => { const IconComponent = button.icon; return ( ); })}
{/* Editor Content */}
); }