Duplicate the input text in the underlay div.

This commit is contained in:
Tom Alexander 2024-01-12 23:15:06 -05:00
parent b52ee91745
commit e6f16c854c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 24 additions and 3 deletions

View File

@ -10,6 +10,19 @@
flex-basis: 0;
position: relative;
background: white;
font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
"DejaVu Sans Mono", monospace;
font-weight: normal;
font-size: 3rem;
text-align: initial;
}
.Editor-textarea,
.Editor-underlay {
font-family: inherit;
font-weight: inherit;
font-size: inherit;
padding: 5px;
}
.Editor-textarea {
@ -21,6 +34,7 @@
width: 100%;
height: 100%;
box-sizing: border-box;
border: none;
background-color: transparent;
}
@ -34,4 +48,5 @@
height: 100%;
pointer-events: none;
/* background: orange; */
/* color: purple; */
}

View File

@ -1,15 +1,21 @@
import React, { useState } from 'react';
import './Editor.css';
function Editor() {
function Editor({
defaultValue = "I have a text value."
}) {
function handleChange(event: React.ChangeEvent<HTMLTextAreaElement>) {
console.log(event.target.value);
setValue(event.target.value);
}
const [value, setValue] = useState(defaultValue);
return (
<div className="Editor">
<div className="Editor-textwrapper">
<textarea onChange={handleChange} className="Editor-textarea">I have text</textarea>
<div className="Editor-underlay"></div>
<textarea onChange={handleChange} className="Editor-textarea" value={value} />
<div className="Editor-underlay">{value}</div>
</div>
<div className="Editor-ast"></div>
</div>