mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-19 14:53:00 +08:00
Add Focus demo for React
This commit is contained in:
parent
1cf0309f90
commit
e26fdb4d90
15
demos/src/Extensions/Focus/React/index.html
Normal file
15
demos/src/Extensions/Focus/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("Extensions/Focus", source);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
39
demos/src/Extensions/Focus/React/index.jsx
Normal file
39
demos/src/Extensions/Focus/React/index.jsx
Normal 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, it’ll 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} />
|
||||
}
|
9
demos/src/Extensions/Focus/React/index.spec.js
Normal file
9
demos/src/Extensions/Focus/React/index.spec.js
Normal 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')
|
||||
})
|
||||
})
|
30
demos/src/Extensions/Focus/React/styles.scss
Normal file
30
demos/src/Extensions/Focus/React/styles.scss
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user