Advanced /
betaRich Text Editor
WYSIWYG editor berbasis engine headless (TipTap) dengan toolbar & styling custom Naraya. Format teks, heading, list, quote, code, link, gambar (upload/drag/paste), undo/redo.
Overview
Komponen ini di-expose lewat subpath @naraya/ui/rich-text-editor (bukan barrel @naraya/ui) supaya engine TipTap yang berat hanya ter-bundle saat editor benar-benar dipakai. Output berupa HTML string via onChange.
Examples
Editor + HTML output
Lihat HTML
<h2>Selamat datang 👋</h2><p>Ini editor <strong>rich text</strong> Naraya — coba <em>format</em> teks, bikin <u>list</u>, atau tambah <a href="https://naraya.ai">tautan</a>.</p><ul><li>Engine headless (TipTap)</li><li>UI 100% token Naraya</li></ul><pre><code class="language-javascript">const naraya = "design system";
console.log(`Halo ${naraya}`); // syntax highlight</code></pre>Gambar (toolbar / drag / paste)
Klik gambar → kontrol align (kiri/tengah/kanan), toggle inline/wrap (teks ngalir di samping), + handle resize di pojok. Drag gambar buat pindah baris. Demo pakai fallback base64.
Read-only (tanpa toolbar)
Tanpa toolbar (compact)
Props
Roadmap
- ✓ Selesai: format teks (bold/italic/underline/strike/code), H1-H3, list, quote, divider, link, undo/redo.
- ✓ Gambar: upload (onUploadImage) / drag / paste, fallback base64, drag-resize + align kiri/tengah/kanan (float text-wrap).
- ✓ Code block dengan syntax highlight (lowlight, theme-aware).
- Phase 2 sisa: embed video (Youtube — di-skip dulu), tabel.
- Phase 3: math/LaTeX, character count, bubble/slash menu, renderer read-only ringan (RichTextContent).
Tokens Used
--bg-surfaceLatar editor
--border-subtleBorder + pemisah toolbar
--color-primaryTool aktif, link, focus ring
--color-secondaryLatar toolbar & inline code
--text-main / --text-mutedTeks konten vs placeholder/quote
Accessibility
- Toolbar memakai role='toolbar'; tiap tombol punya aria-label, title, dan aria-pressed untuk status aktif.
- Area edit fokusabel dengan focus ring pada container (focus-within).
- onMouseDown preventDefault pada tombol agar seleksi teks tidak hilang saat klik format.