mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 09:25:29 +08:00
Add HorizontaleRule demo for React
This commit is contained in:
parent
e8c76a75a0
commit
7d6ecf31d8
15
demos/src/Nodes/HorizontalRule/React/index.html
Normal file
15
demos/src/Nodes/HorizontalRule/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("Nodes/HorizontalRule", source);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
34
demos/src/Nodes/HorizontalRule/React/index.jsx
Normal file
34
demos/src/Nodes/HorizontalRule/React/index.jsx
Normal file
@ -0,0 +1,34 @@
|
||||
import React from 'react'
|
||||
import { useEditor, EditorContent } from '@tiptap/react'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import HorizontalRule from '@tiptap/extension-horizontal-rule'
|
||||
import './styles.scss'
|
||||
|
||||
export default () => {
|
||||
const editor = useEditor({
|
||||
extensions: [Document, Paragraph, Text, HorizontalRule],
|
||||
content: `
|
||||
<p>This is a paragraph.</p>
|
||||
<hr>
|
||||
<p>And this is another paragraph.</p>
|
||||
<hr>
|
||||
<p>But between those paragraphs are horizontal rules.</p>
|
||||
`,
|
||||
})
|
||||
|
||||
if (!editor) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<button onClick={() => editor.chain().focus().setHorizontalRule().run()}>
|
||||
setHorizontalRule
|
||||
</button>
|
||||
|
||||
<EditorContent editor={editor} />
|
||||
</>
|
||||
)
|
||||
}
|
57
demos/src/Nodes/HorizontalRule/React/index.spec.js
Normal file
57
demos/src/Nodes/HorizontalRule/React/index.spec.js
Normal file
@ -0,0 +1,57 @@
|
||||
context('/src/Nodes/HorizontalRule/React/', () => {
|
||||
before(() => {
|
||||
cy.visit('/src/Nodes/HorizontalRule/React/')
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p>Example Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it('should parse horizontal rules correctly', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p>Example Text</p><hr>')
|
||||
expect(editor.getHTML()).to.eq('<p>Example Text</p><hr>')
|
||||
})
|
||||
})
|
||||
|
||||
it('should parse horizontal rules with self-closing tag correctly', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p>Example Text</p><hr />')
|
||||
expect(editor.getHTML()).to.eq('<p>Example Text</p><hr>')
|
||||
})
|
||||
})
|
||||
|
||||
it('the button should add a horizontal rule', () => {
|
||||
cy.get('.ProseMirror hr').should('not.exist')
|
||||
|
||||
cy.get('button:first').click()
|
||||
|
||||
cy.get('.ProseMirror hr').should('exist')
|
||||
})
|
||||
|
||||
it('the default markdown shortcut should add a horizontal rule', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.clearContent()
|
||||
|
||||
cy.get('.ProseMirror hr').should('not.exist')
|
||||
|
||||
cy.get('.ProseMirror').type('---')
|
||||
|
||||
cy.get('.ProseMirror hr').should('exist')
|
||||
})
|
||||
})
|
||||
|
||||
it('the alternative markdown shortcut should add a horizontal rule', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.clearContent()
|
||||
|
||||
cy.get('.ProseMirror hr').should('not.exist')
|
||||
|
||||
cy.get('.ProseMirror').type('___ ')
|
||||
|
||||
cy.get('.ProseMirror hr').should('exist')
|
||||
})
|
||||
})
|
||||
})
|
3
demos/src/Nodes/HorizontalRule/React/styles.scss
Normal file
3
demos/src/Nodes/HorizontalRule/React/styles.scss
Normal file
@ -0,0 +1,3 @@
|
||||
hr.ProseMirror-selectednode {
|
||||
border-top: 1px solid #68cef8;
|
||||
}
|
Loading…
Reference in New Issue
Block a user