add react demo for formatting
This commit is contained in:
98
docs/src/demos/Examples/Formatting/React/index.jsx
Normal file
98
docs/src/demos/Examples/Formatting/React/index.jsx
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { useEditor, EditorContent } from '@tiptap/react'
|
||||||
|
import StarterKit from '@tiptap/starter-kit'
|
||||||
|
import TextAlign from '@tiptap/extension-text-align'
|
||||||
|
import Highlight from '@tiptap/extension-highlight'
|
||||||
|
import './styles.scss'
|
||||||
|
|
||||||
|
const MenuBar = ({ editor }) => {
|
||||||
|
if (!editor) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()} className={editor.isActive('heading', { level: 1 }) ? 'is-active' : ''}>
|
||||||
|
h1
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()} className={editor.isActive('heading', { level: 2 }) ? 'is-active' : ''}>
|
||||||
|
h2
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().toggleHeading({ level: 3 }).run()} className={editor.isActive('heading', { level: 3 }) ? 'is-active' : ''}>
|
||||||
|
h3
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().setParagraph().run()} className={editor.isActive('paragraph') ? 'is-active' : ''}>
|
||||||
|
paragraph
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().toggleBold().run()} className={editor.isActive('bold') ? 'is-active' : ''}>
|
||||||
|
bold
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().toggleItalic().run()} className={editor.isActive('italic') ? 'is-active' : ''}>
|
||||||
|
italic
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().toggleStrike().run()} className={editor.isActive('strike') ? 'is-active' : ''}>
|
||||||
|
strike
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().toggleHighlight().run()} className={editor.isActive('highlight') ? 'is-active' : ''}>
|
||||||
|
highlight
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().setTextAlign('left').run()} className={editor.isActive({ textAlign: 'left' }) ? 'is-active' : ''}>
|
||||||
|
left
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().setTextAlign('center').run()} className={editor.isActive({ textAlign: 'center' }) ? 'is-active' : ''}>
|
||||||
|
center
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().setTextAlign('right').run()} className={editor.isActive({ textAlign: 'right' }) ? 'is-active' : ''}>
|
||||||
|
right
|
||||||
|
</button>
|
||||||
|
<button onClick={() => editor.chain().focus().setTextAlign('justify').run()} className={editor.isActive({ textAlign: 'justify' }) ? 'is-active' : ''}>
|
||||||
|
justify
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const editor = useEditor({
|
||||||
|
extensions: [
|
||||||
|
StarterKit,
|
||||||
|
TextAlign.configure({
|
||||||
|
types: ['heading', 'paragraph'],
|
||||||
|
}),
|
||||||
|
Highlight,
|
||||||
|
],
|
||||||
|
content: `
|
||||||
|
<h3 style="text-align:center">
|
||||||
|
Devs Just Want to Have Fun by Cyndi Lauper
|
||||||
|
</h3>
|
||||||
|
<p style="text-align:center">
|
||||||
|
I come home in the morning light<br>
|
||||||
|
My mother says, <mark>“When you gonna live your life right?”</mark><br>
|
||||||
|
Oh mother dear we’re not the fortunate ones<br>
|
||||||
|
And devs, they wanna have fun<br>
|
||||||
|
Oh devs just want to have fun</p>
|
||||||
|
<p style="text-align:center">
|
||||||
|
The phone rings in the middle of the night<br>
|
||||||
|
My father yells, "What you gonna do with your life?"<br>
|
||||||
|
Oh daddy dear, you know you’re still number one<br>
|
||||||
|
But <s>girls</s>devs, they wanna have fun<br>
|
||||||
|
Oh devs just want to have
|
||||||
|
</p>
|
||||||
|
<p style="text-align:center">
|
||||||
|
That’s all they really want<br>
|
||||||
|
Some fun<br>
|
||||||
|
When the working day is done<br>
|
||||||
|
Oh devs, they wanna have fun<br>
|
||||||
|
Oh devs just wanna have fun<br>
|
||||||
|
(devs, they wanna, wanna have fun, devs wanna have)
|
||||||
|
</p>
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<MenuBar editor={editor} />
|
||||||
|
<EditorContent editor={editor} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
62
docs/src/demos/Examples/Formatting/React/styles.scss
Normal file
62
docs/src/demos/Examples/Formatting/React/styles.scss
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/* Basic editor styles */
|
||||||
|
.ProseMirror {
|
||||||
|
margin-top: 1rem;
|
||||||
|
|
||||||
|
> * + * {
|
||||||
|
margin-top: 0.75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul,
|
||||||
|
ol {
|
||||||
|
padding: 0 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6 {
|
||||||
|
line-height: 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background-color: rgba(#616161, 0.1);
|
||||||
|
color: #616161;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background: #0D0D0D;
|
||||||
|
color: #FFF;
|
||||||
|
font-family: 'JetBrainsMono', monospace;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
|
||||||
|
code {
|
||||||
|
color: inherit;
|
||||||
|
padding: 0;
|
||||||
|
background: none;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mark {
|
||||||
|
background-color: #FAF594;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
padding-left: 1rem;
|
||||||
|
border-left: 2px solid rgba(#0D0D0D, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
border: none;
|
||||||
|
border-top: 2px solid rgba(#0D0D0D, 0.1);
|
||||||
|
margin: 2rem 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
7
docs/src/demos/Examples/Formatting/Vue/index.spec.js
Normal file
7
docs/src/demos/Examples/Formatting/Vue/index.spec.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
context('/demos/Examples/Vue', () => {
|
||||||
|
before(() => {
|
||||||
|
cy.visit('/demos/Examples/Vue')
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO: Write tests
|
||||||
|
})
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
context('/demos/Examples/Formatting', () => {
|
|
||||||
before(() => {
|
|
||||||
cy.visit('/demos/Examples/Formatting')
|
|
||||||
})
|
|
||||||
|
|
||||||
// TODO: Write tests
|
|
||||||
})
|
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
# Formatting
|
# Formatting
|
||||||
|
|
||||||
<demo name="Examples/Formatting" />
|
<demos :items="{
|
||||||
|
Vue: 'Examples/Formatting/Vue',
|
||||||
|
React: 'Examples/Formatting/React',
|
||||||
|
}" />
|
||||||
|
|||||||
Reference in New Issue
Block a user