Add Strike demo for React
This commit is contained in:
15
demos/src/Marks/Strike/React/index.html
Normal file
15
demos/src/Marks/Strike/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/Strike", source);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
48
demos/src/Marks/Strike/React/index.jsx
Normal file
48
demos/src/Marks/Strike/React/index.jsx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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 Strike from '@tiptap/extension-strike'
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const editor = useEditor({
|
||||||
|
extensions: [Document, Paragraph, Text, Strike],
|
||||||
|
content: `
|
||||||
|
<p>This isn’t striked through.</s></p>
|
||||||
|
<p><s>But that’s striked through.</s></p>
|
||||||
|
<p><del>And this.</del></p>
|
||||||
|
<p><strike>This too.</strike></p>
|
||||||
|
<p style="text-decoration: line-through">This as well.</p>
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!editor) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
onClick={() => editor.chain().focus().toggleStrike().run()}
|
||||||
|
className={editor.isActive('strike') ? 'is-active' : ''}
|
||||||
|
>
|
||||||
|
toggleStrike
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => editor.chain().focus().setStrike().run()}
|
||||||
|
disabled={editor.isActive('strike')}
|
||||||
|
>
|
||||||
|
setStrike
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => editor.chain().focus().unsetStrike().run()}
|
||||||
|
disabled={!editor.isActive('strike')}
|
||||||
|
>
|
||||||
|
unsetStrike
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<EditorContent editor={editor} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
77
demos/src/Marks/Strike/React/index.spec.js
Normal file
77
demos/src/Marks/Strike/React/index.spec.js
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
context('/src/Marks/Strike/React/', () => {
|
||||||
|
before(() => {
|
||||||
|
cy.visit('/src/Marks/Strike/React/')
|
||||||
|
})
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.setContent('<p>Example Text</p>')
|
||||||
|
cy.get('.ProseMirror').type('{selectall}')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should parse s tags correctly', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.setContent('<p><s>Example Text</s></p>')
|
||||||
|
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should transform del tags to s tags', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.setContent('<p><del>Example Text</del></p>')
|
||||||
|
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should transform strike tags to s tags', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.setContent('<p><strike>Example Text</strike></p>')
|
||||||
|
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should transform any tag with text decoration line through to s tags', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.setContent(
|
||||||
|
'<p><span style="text-decoration: line-through">Example Text</span></p>',
|
||||||
|
)
|
||||||
|
expect(editor.getHTML()).to.eq('<p><s>Example Text</s></p>')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('the button should strike the selected text', () => {
|
||||||
|
cy.get('button:first').click()
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('s').should('contain', 'Example Text')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('the button should toggle the selected text striked', () => {
|
||||||
|
cy.get('button:first').click()
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').type('{selectall}')
|
||||||
|
|
||||||
|
cy.get('button:first').click()
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('s').should('not.exist')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should strike the selected text when the keyboard shortcut is pressed', () => {
|
||||||
|
cy.get('.ProseMirror')
|
||||||
|
.trigger('keydown', { modKey: true, shiftKey: true, key: 'x' })
|
||||||
|
.find('s')
|
||||||
|
.should('contain', 'Example Text')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should toggle the selected text striked when the keyboard shortcut is pressed', () => {
|
||||||
|
cy.get('.ProseMirror')
|
||||||
|
.trigger('keydown', { modKey: true, shiftKey: true, key: 'x' })
|
||||||
|
.trigger('keydown', { modKey: true, shiftKey: true, key: 'x' })
|
||||||
|
.find('s')
|
||||||
|
.should('not.exist')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should make a striked text from the markdown shortcut', () => {
|
||||||
|
cy.get('.ProseMirror').type('~~Strike~~').find('s').should('contain', 'Strike')
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user