Skip to content

Commit bb5178c

Browse files
committed
feat: add demo page config
1 parent d803f0f commit bb5178c

3 files changed

Lines changed: 16 additions & 32 deletions

File tree

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Vite + React + TS</title>
7+
<title>react-basic-contenteditable</title>
88
</head>
99
<body>
1010
<div id="root"></div>

lib/components/contenteditable/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface ContentEditableProps {
77

88
const ContentEditable: React.FC<ContentEditableProps> = ({
99
placeholder,
10-
// emitContent,
10+
onChange,
1111
}) => {
1212
const [content, setContent] = useState("")
1313
const divRef = useRef<HTMLDivElement | null>(null)
@@ -16,8 +16,9 @@ const ContentEditable: React.FC<ContentEditableProps> = ({
1616
if (divRef.current) {
1717
divRef.current.style.height = "auto"
1818
// divRef.current.style.height = divRef.current.scrollHeight + "px"
19+
onChange(content)
1920
}
20-
}, [content])
21+
}, [content, onChange])
2122

2223
/**
2324
* Check if the caret is on the last line of an element

src/App.tsx

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
1-
import { useState } from 'react'
2-
import reactLogo from './assets/react.svg'
3-
import viteLogo from '/vite.svg'
4-
import './App.css'
1+
import "./App.css"
2+
import ContentEditable from "../lib/components/contenteditable"
3+
import { useState } from "react"
54

65
function App() {
7-
const [count, setCount] = useState(0)
8-
6+
const [content, setContent] = useState("")
97
return (
10-
<>
11-
<div>
12-
<a href="https://vitejs.dev" target="_blank">
13-
<img src={viteLogo} className="logo" alt="Vite logo" />
14-
</a>
15-
<a href="https://react.dev" target="_blank">
16-
<img src={reactLogo} className="logo react" alt="React logo" />
17-
</a>
18-
</div>
19-
<h1>Vite + React</h1>
20-
<div className="card">
21-
<button onClick={() => setCount((count) => count + 1)}>
22-
count is {count}
23-
</button>
24-
<p>
25-
Edit <code>src/App.tsx</code> and save to test HMR
26-
</p>
27-
</div>
28-
<p className="read-the-docs">
29-
Click on the Vite and React logos to learn more
30-
</p>
31-
</>
8+
<div>
9+
<div style={{ whiteSpace: "pre-wrap" }}>{content}</div>
10+
<ContentEditable
11+
placeholder="Type here"
12+
onChange={(content) => setContent(content)}
13+
/>
14+
</div>
3215
)
3316
}
3417

0 commit comments

Comments
 (0)