Skip to content

Commit 090fb11

Browse files
committed
Support all headings in tiptap
Signed-off-by: Émile Ré <emile@getprobo.com>
1 parent 33b054a commit 090fb11

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

packages/ui/src/RichEditor/BlockMenu/BlockMenuContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
useFloating,
1111
} from "@floating-ui/react";
1212
import type { Icon } from "@phosphor-icons/react";
13-
import { CodeBlockIcon, GridFourIcon, ListBulletsIcon, ListNumbersIcon, MinusIcon, QuotesIcon, TextHOneIcon, TextHThreeIcon, TextHTwoIcon, TextTIcon } from "@phosphor-icons/react";
13+
import { CodeBlockIcon, GridFourIcon, ListBulletsIcon, ListNumbersIcon, MinusIcon, QuotesIcon, TextHFourIcon, TextHOneIcon, TextHThreeIcon, TextHTwoIcon, TextTIcon } from "@phosphor-icons/react";
1414
import { type Editor } from "@tiptap/react";
1515
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
1616

@@ -35,6 +35,7 @@ const BLOCK_ITEMS: BlockItem[] = [
3535
{ label: "Heading 1", icon: TextHOneIcon, action: chain => chain.toggleHeading({ level: 1 }) },
3636
{ label: "Heading 2", icon: TextHTwoIcon, action: chain => chain.toggleHeading({ level: 2 }) },
3737
{ label: "Heading 3", icon: TextHThreeIcon, action: chain => chain.toggleHeading({ level: 3 }) },
38+
{ label: "Heading 4", icon: TextHFourIcon, action: chain => chain.toggleHeading({ level: 4 }) },
3839
{ label: "Bullet List", icon: ListBulletsIcon, action: chain => chain.toggleBulletList() },
3940
{ label: "Ordered List", icon: ListNumbersIcon, action: chain => chain.toggleOrderedList() },
4041
{ label: "Code Block", icon: CodeBlockIcon, action: chain => chain.toggleCodeBlock() },

packages/ui/src/RichEditor/OptionsMenu/OptionsMenuContent.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by the ISC license
33
// that can be found in the LICENSE file.
44

5-
import { CodeBlockIcon, ListBulletsIcon, ListNumbersIcon, QuotesIcon, TextHOneIcon, TextHThreeIcon, TextHTwoIcon, TextTIcon } from "@phosphor-icons/react";
5+
import { CodeBlockIcon, ListBulletsIcon, ListNumbersIcon, QuotesIcon, TextHFourIcon, TextHOneIcon, TextHThreeIcon, TextHTwoIcon, TextTIcon } from "@phosphor-icons/react";
66
import { TextSelection } from "@tiptap/pm/state";
77
import { type Editor } from "@tiptap/react";
88

@@ -158,6 +158,13 @@ export function OptionsMenuContent({
158158
<TextHThreeIcon size={16} weight="bold" />
159159
Heading 3
160160
</MenuButton>
161+
<MenuButton
162+
active={hoveredBlock != null && isBlockNodeType(editor, hoveredBlock, "heading", { level: 4 })}
163+
onClick={() => handleAction(chain => chain.toggleHeading({ level: 4 }))}
164+
>
165+
<TextHFourIcon size={16} weight="bold" />
166+
Heading 4
167+
</MenuButton>
161168
<MenuButton
162169
active={hoveredBlock != null && isBlockNodeType(editor, hoveredBlock, "bulletList")}
163170
onClick={() => handleAction(chain => chain.toggleBulletList())}

packages/ui/src/RichEditor/RichEditor.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ const extensions = [
3737
Document,
3838
Paragraph,
3939
Text,
40-
Heading.configure({
41-
levels: [1, 2, 3],
42-
}),
40+
Heading,
4341
Bold,
4442
Italic,
4543
Strike,

packages/ui/src/rich-editor.css

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212

1313
strong { @apply font-semibold; }
1414

15-
h1 { @apply text-2xl font-semibold mt-4; }
16-
17-
h2 { @apply text-xl font-semibold mt-3; }
18-
19-
h3 { @apply text-lg font-semibold mt-2; }
15+
h1 { @apply text-4xl font-semibold mt-4; }
16+
h2 { @apply text-3xl font-semibold mt-3; }
17+
h3 { @apply text-2xl font-semibold mt-2; }
18+
h4 { @apply text-xl font-semibold mt-2; }
19+
h5 { @apply text-lg font-semibold mt-2; }
20+
h6 { @apply text-base font-semibold mt-2; }
2021

2122
ul {
2223
@apply list-disc list-outside my-2 pl-4;

0 commit comments

Comments
 (0)