mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 23:15:15 +08:00
Add Subscript demo for React
This commit is contained in:
parent
61603c8323
commit
6b31c9c378
15
demos/src/Marks/Subscript/React/index.html
Normal file
15
demos/src/Marks/Subscript/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("Marks/Subscript", source);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
46
demos/src/Marks/Subscript/React/index.jsx
Normal file
46
demos/src/Marks/Subscript/React/index.jsx
Normal file
@ -0,0 +1,46 @@
|
||||
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 Subscript from '@tiptap/extension-subscript'
|
||||
|
||||
export default () => {
|
||||
const editor = useEditor({
|
||||
extensions: [Document, Paragraph, Text, Subscript],
|
||||
content: `
|
||||
<p>This is regular text.</p>
|
||||
<p><sub>This is subscript.</sub></p>
|
||||
<p><span style="vertical-align: sub">And this.</span></p>
|
||||
`,
|
||||
})
|
||||
|
||||
if (!editor) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().toggleSubscript().run()}
|
||||
className={editor.isActive('subscript') ? 'is-active' : ''}
|
||||
>
|
||||
toggleSubscript
|
||||
</button>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().setSubscript().run()}
|
||||
disabled={editor.isActive('subscript')}
|
||||
>
|
||||
setSubscript
|
||||
</button>
|
||||
<button
|
||||
onClick={() => editor.chain().focus().unsetSubscript().run()}
|
||||
disabled={!editor.isActive('subscript')}
|
||||
>
|
||||
unsetSubscript
|
||||
</button>
|
||||
|
||||
<EditorContent editor={editor} />
|
||||
</>
|
||||
)
|
||||
}
|
39
demos/src/Marks/Subscript/React/index.spec.js
Normal file
39
demos/src/Marks/Subscript/React/index.spec.js
Normal file
@ -0,0 +1,39 @@
|
||||
context('/src/Marks/Subscript/React/', () => {
|
||||
before(() => {
|
||||
cy.visit('/src/Marks/Subscript/React/')
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p>Example Text</p>')
|
||||
cy.get('.ProseMirror').type('{selectall}')
|
||||
})
|
||||
})
|
||||
|
||||
it('should transform inline style to sub tags', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p><span style="vertical-align: sub">Example Text</span></p>')
|
||||
expect(editor.getHTML()).to.eq('<p><sub>Example Text</sub></p>')
|
||||
})
|
||||
})
|
||||
|
||||
it('sould omit inline style with a different vertical align', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p><b style="vertical-align: middle">Example Text</b></p>')
|
||||
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it('the button should make the selected text bold', () => {
|
||||
cy.get('button:first').click()
|
||||
|
||||
cy.get('.ProseMirror').find('sub').should('contain', 'Example Text')
|
||||
})
|
||||
|
||||
it('the button should toggle the selected text bold', () => {
|
||||
cy.get('button:first').click()
|
||||
cy.get('.ProseMirror').type('{selectall}')
|
||||
cy.get('button:first').click()
|
||||
cy.get('.ProseMirror sub').should('not.exist')
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user