all: Aggiunte varie feature e riscritte svariate cose
This commit is contained in:
@@ -3,11 +3,14 @@ import { StateUpdater, useEffect, useRef } from 'preact/hooks'
|
||||
import { Markdown } from './Markdown'
|
||||
|
||||
type Props = {
|
||||
placeholder?: string
|
||||
source: string
|
||||
setSource: StateUpdater<string>
|
||||
}
|
||||
|
||||
export const MarkdownEditor = ({ source, setSource }: Props) => {
|
||||
export const MarkdownEditor = ({ placeholder, source, setSource }: Props) => {
|
||||
placeholder ??= 'Scrivi qualcosa...'
|
||||
|
||||
const editorRef = useRef<HTMLTextAreaElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -28,23 +31,17 @@ export const MarkdownEditor = ({ source, setSource }: Props) => {
|
||||
<div class="editor">
|
||||
<h1>Editor</h1>
|
||||
<textarea
|
||||
onInput={e =>
|
||||
setSource(e.target instanceof HTMLTextAreaElement ? e.target.value : '')
|
||||
}
|
||||
onInput={e => setSource(e.target instanceof HTMLTextAreaElement ? e.target.value : '')}
|
||||
value={source}
|
||||
cols={60}
|
||||
ref={editorRef}
|
||||
placeholder="Scrivi una nuova soluzione..."
|
||||
placeholder={placeholder}
|
||||
></textarea>
|
||||
</div>
|
||||
<div class="preview">
|
||||
<h1>Preview</h1>
|
||||
<div class="preview-content">
|
||||
{source.trim().length ? (
|
||||
<Markdown source={source} />
|
||||
) : (
|
||||
<div class="placeholder">Scrivi una nuova soluzione...</div>
|
||||
)}
|
||||
{source.trim().length ? <Markdown source={source} /> : <div class="placeholder">{placeholder}</div>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user