Add Placeholder demo for React
This commit is contained in:
15
demos/src/Extensions/Placeholder/React/index.html
Normal file
15
demos/src/Extensions/Placeholder/React/index.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module">
|
||||||
|
import setup from "../../../../setup/react.ts";
|
||||||
|
import source from "@source";
|
||||||
|
setup("Extensions/Placeholder", source);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
27
demos/src/Extensions/Placeholder/React/index.jsx
Normal file
27
demos/src/Extensions/Placeholder/React/index.jsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { useEditor, EditorContent } from '@tiptap/react'
|
||||||
|
import StarterKit from '@tiptap/starter-kit'
|
||||||
|
import Placeholder from '@tiptap/extension-placeholder'
|
||||||
|
import './styles.scss'
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const editor = useEditor({
|
||||||
|
extensions: [
|
||||||
|
StarterKit,
|
||||||
|
Placeholder.configure({
|
||||||
|
// Use a placeholder:
|
||||||
|
placeholder: 'Write something …',
|
||||||
|
// Use different placeholders depending on the node type:
|
||||||
|
// placeholder: ({ node }) => {
|
||||||
|
// if (node.type.name === 'heading') {
|
||||||
|
// return 'What’s the title?'
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return 'Can you add some further context?'
|
||||||
|
// },
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
return <EditorContent editor={editor} />
|
||||||
|
}
|
||||||
24
demos/src/Extensions/Placeholder/React/styles.scss
Normal file
24
demos/src/Extensions/Placeholder/React/styles.scss
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* Basic editor styles */
|
||||||
|
.ProseMirror {
|
||||||
|
> * + * {
|
||||||
|
margin-top: 0.75em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Placeholder (at the top) */
|
||||||
|
.ProseMirror p.is-editor-empty:first-child::before {
|
||||||
|
color: #adb5bd;
|
||||||
|
content: attr(data-placeholder);
|
||||||
|
float: left;
|
||||||
|
height: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Placeholder (on every new line) */
|
||||||
|
/*.ProseMirror p.is-empty::before {
|
||||||
|
color: #adb5bd;
|
||||||
|
content: attr(data-placeholder);
|
||||||
|
float: left;
|
||||||
|
height: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}*/
|
||||||
Reference in New Issue
Block a user