import { FC, useState } from 'react'; import { Box, CircularProgress, TextField } from '@mui/material'; import { hash } from '../../core/security/hash'; type EditorProps = { value: string; label?: string; rows?: number; }; export const Editor: FC = ({ value, label, rows }) => { const [content, setContent] = useState(''); const [preview, setPreview] = useState(); const [loading, setLoading] = useState(false); const labelId = `cms-editor--${hash(label ?? '')}`; const renderPreview = () => { if (!content) { return; } setLoading(true); fetch('/cms/render-editor-preview', { method: 'POST', body: JSON.stringify({ haystack: content }), }) .then((data) => data.json()) .then((data) => { setLoading(false); setPreview(data.html); }); }; return ( {label && } renderPreview()}> {!content ? ( Empty preview. ) : ( {loading ? : {preview}} )} Styling with Markdown is supported ); };