Add Focus demo for React

This commit is contained in:
Sven Adlung 2021-11-16 13:57:39 +01:00
parent 1cf0309f90
commit e26fdb4d90
4 changed files with 93 additions and 0 deletions

View 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/Focus", source);
</script>
</body>
</html>

View File

@ -0,0 +1,39 @@
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 Focus from '@tiptap/extension-focus'
import Code from '@tiptap/extension-code'
import BulletList from '@tiptap/extension-bullet-list'
import ListItem from '@tiptap/extension-list-item'
import './styles.scss'
export default () => {
const editor = useEditor({
extensions: [
Document,
Paragraph,
Text,
Focus.configure({
className: 'has-focus',
mode: 'all',
}),
Code,
BulletList,
ListItem,
],
autofocus: true,
content: `
<p>
The focus extension adds a class to the focused node only. That enables you to add a custom styling to just that node. By default, itll add <code>.has-focus</code>, even to nested nodes.
</p>
<ul>
<li>Nested elements (like this list item) will be focused with the default setting of <code>mode: all</code>.</li>
<li>Otherwise the whole list will get the focus class, even when just a single list item is selected.</li>
</ul>
`,
})
return <EditorContent editor={editor} />
}

View File

@ -0,0 +1,9 @@
context('/src/Extensions/Focus/React/', () => {
before(() => {
cy.visit('/src/Extensions/Focus/React/')
})
it('should have class', () => {
cy.get('.ProseMirror p:first').should('have.class', 'has-focus')
})
})

View File

@ -0,0 +1,30 @@
.has-focus {
border-radius: 3px;
box-shadow: 0 0 0 3px #68cef8;
}
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
ul,
ol {
padding: 0 1rem;
}
blockquote {
border-left: 2px solid rgba(#0d0d0d, 0.1);
padding-left: 1rem;
}
code {
background-color: rgba(#616161, 0.1);
border-radius: 0.25em;
box-decoration-break: clone;
color: #616161;
font-size: 0.9rem;
padding: 0.25em;
}
}