Add Read "raw_content" contentEditable Element & Edit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
.article {
|
||||
overflow-x: auto;
|
||||
|
||||
a {
|
||||
color: #28b9be;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-weight: bold;
|
||||
margin-top: 1.5em;
|
||||
|
||||
&:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6, p {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
p {
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
img {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
pre {
|
||||
color: #fff;
|
||||
padding: .5em;
|
||||
overflow: auto;
|
||||
border-radius: .5em;
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
:not(pre) > code {
|
||||
color: brown;
|
||||
padding: 0 .5em;
|
||||
border-radius: .5em;
|
||||
display: inline-block;
|
||||
background-color: antiquewhite;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { clsn } from "~utils";
|
||||
|
||||
import styles from "./article.module.less";
|
||||
|
||||
interface ArticleProps {
|
||||
className?: string;
|
||||
value: string | number;
|
||||
onChange: (value: string) => void;
|
||||
}
|
||||
|
||||
function Article({ className, value, onChange }: ArticleProps) {
|
||||
const articleRef = useRef<HTMLElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!articleRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (articleRef.current.innerHTML !== String(value)) {
|
||||
articleRef.current.innerHTML = String(value);
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
return (
|
||||
<article
|
||||
ref={articleRef}
|
||||
className={clsn(styles.article, className)}
|
||||
contentEditable
|
||||
onInput={(ev) => onChange(articleRef.current.innerHTML)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default Article;
|
||||
Reference in New Issue
Block a user