import { useState } from 'react'; import { Prose } from '#/components/molecules/prose.jsx'; import { cn } from '#/lib/utils.js'; /** * A field for words that will be read as markdown, with the reading beside * the writing. * * What is typed here is rendered wherever it is read, so a writer who cannot * see that finds out after publishing. The preview is the same renderer the * page uses, so a fenced block that reads wrong here reads wrong there. * * Preview is a tab rather than a second pane, because at this width two * columns would give each of them half a line of code. */ export function MarkdownField({ value, onChange, placeholder, rows = 8, disabled, label, autoFocus, className, }) { const [preview, setPreview] = useState(false); return (
{[ { key: 'write', label: 'Write' }, { key: 'preview', label: 'Preview' }, ].map((tab) => { const current = (tab.key === 'preview') === preview; return ( ); })}
{preview ? ( // The written height, so the field does not jump as a reader looks.
{value.trim() ? ( ) : (

Nothing to preview yet.

)}
) : (