|
| 1 | +import FontSize from '@tiptap/extension-font-size' |
| 2 | +import TextStyle from '@tiptap/extension-text-style' |
| 3 | +import { EditorContent, useEditor } from '@tiptap/react' |
| 4 | +import StarterKit from '@tiptap/starter-kit' |
| 5 | + |
| 6 | +export default () => { |
| 7 | + const editor = useEditor({ |
| 8 | + shouldRerenderOnTransaction: true, |
| 9 | + extensions: [StarterKit, TextStyle, FontSize], |
| 10 | + content: ` |
| 11 | + <p>Adjusting font sizes can greatly affect the readability of your text, making it easier for users to engage with your content.</p> |
| 12 | + <p>When designing a website, it's crucial to balance large headings and smaller body text for a clean, organized layout.</p> |
| 13 | + <p>When setting font sizes, it's important to consider accessibility, ensuring that text is readable for users with different visual impairments.</p> |
| 14 | + <p><span style="font-size: 10px">Too small</span> a font size can strain the eyes, while <span style="font-size: 40px">too large</span> can disrupt the flow of the design.</p> |
| 15 | + <p>When designing for mobile, font sizes should be adjusted to maintain readability on smaller screens.</p> |
| 16 | + `, |
| 17 | + }) |
| 18 | + |
| 19 | + if (!editor) { |
| 20 | + return null |
| 21 | + } |
| 22 | + |
| 23 | + return <> |
| 24 | + <div className="control-group"> |
| 25 | + <div className="button-group"> |
| 26 | + <button |
| 27 | + onClick={() => editor.chain().focus().setFontSize('28px').run()} |
| 28 | + className={editor.isActive('textStyle', { fontSize: '28px' }) ? 'is-active' : ''} |
| 29 | + data-test-id="28px" |
| 30 | + > |
| 31 | + Font size 28px |
| 32 | + </button> |
| 33 | + <button |
| 34 | + onClick={() => editor.chain().focus().setFontSize('32px').run()} |
| 35 | + className={editor.isActive('textStyle', { fontSize: '32px' }) ? 'is-active' : ''} |
| 36 | + data-test-id="32px" |
| 37 | + > |
| 38 | + Font size 32px |
| 39 | + </button> |
| 40 | + <button |
| 41 | + onClick={() => editor.chain().focus().unsetFontSize().run()} |
| 42 | + data-test-id="unsetFontSize" |
| 43 | + > |
| 44 | + Unset font size |
| 45 | + </button> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + |
| 49 | + <EditorContent editor={editor} /> |
| 50 | + </> |
| 51 | +} |
0 commit comments