1- import { IconButton , Flex , Separator , Select } from "@radix-ui/themes" ;
21import {
2+ CodeIcon ,
33 FontBoldIcon ,
44 FontItalicIcon ,
5- UnderlineIcon ,
6- StrikethroughIcon ,
7- CodeIcon ,
8- QuoteIcon ,
95 Link1Icon ,
106 ListBulletIcon ,
7+ QuoteIcon ,
8+ StrikethroughIcon ,
9+ UnderlineIcon ,
1110} from "@radix-ui/react-icons" ;
11+ import { Flex , IconButton , Select , Separator } from "@radix-ui/themes" ;
1212import type { Editor } from "@tiptap/react" ;
1313
1414interface FormattingToolbarProps {
@@ -22,12 +22,15 @@ export function FormattingToolbar({ editor }: FormattingToolbarProps) {
2222 const toggleStrike = ( ) => editor . chain ( ) . focus ( ) . toggleStrike ( ) . run ( ) ;
2323 const toggleCode = ( ) => editor . chain ( ) . focus ( ) . toggleCode ( ) . run ( ) ;
2424 const toggleCodeBlock = ( ) => editor . chain ( ) . focus ( ) . toggleCodeBlock ( ) . run ( ) ;
25- const toggleBlockquote = ( ) => editor . chain ( ) . focus ( ) . toggleBlockquote ( ) . run ( ) ;
26- const toggleBulletList = ( ) => editor . chain ( ) . focus ( ) . toggleBulletList ( ) . run ( ) ;
27- const toggleOrderedList = ( ) => editor . chain ( ) . focus ( ) . toggleOrderedList ( ) . run ( ) ;
28-
25+ const toggleBlockquote = ( ) =>
26+ editor . chain ( ) . focus ( ) . toggleBlockquote ( ) . run ( ) ;
27+ const toggleBulletList = ( ) =>
28+ editor . chain ( ) . focus ( ) . toggleBulletList ( ) . run ( ) ;
29+ const toggleOrderedList = ( ) =>
30+ editor . chain ( ) . focus ( ) . toggleOrderedList ( ) . run ( ) ;
31+
2932 const setLink = ( ) => {
30- const url = window . prompt ( ' Enter URL:' ) ;
33+ const url = window . prompt ( " Enter URL:" ) ;
3134 if ( url ) {
3235 editor . chain ( ) . focus ( ) . setLink ( { href : url } ) . run ( ) ;
3336 }
@@ -39,14 +42,14 @@ export function FormattingToolbar({ editor }: FormattingToolbarProps) {
3942
4043 const getCurrentHeading = ( ) => {
4144 for ( let i = 1 ; i <= 6 ; i ++ ) {
42- if ( editor . isActive ( ' heading' , { level : i } ) ) {
45+ if ( editor . isActive ( " heading" , { level : i } ) ) {
4346 return i . toString ( ) ;
4447 }
4548 }
46- if ( editor . isActive ( ' paragraph' ) ) {
47- return ' paragraph' ;
49+ if ( editor . isActive ( " paragraph" ) ) {
50+ return " paragraph" ;
4851 }
49- return ' paragraph' ;
52+ return " paragraph" ;
5053 } ;
5154
5255 return (
@@ -66,15 +69,15 @@ export function FormattingToolbar({ editor }: FormattingToolbarProps) {
6669 < Select . Root
6770 value = { getCurrentHeading ( ) }
6871 onValueChange = { ( value ) => {
69- if ( value === ' paragraph' ) {
72+ if ( value === " paragraph" ) {
7073 editor . chain ( ) . focus ( ) . setParagraph ( ) . run ( ) ;
7174 } else {
72- setHeading ( parseInt ( value ) as 1 | 2 | 3 | 4 | 5 | 6 ) ;
75+ setHeading ( parseInt ( value , 10 ) as 1 | 2 | 3 | 4 | 5 | 6 ) ;
7376 }
7477 } }
7578 size = "1"
7679 >
77- < Select . Trigger style = { { minWidth : ' 80px' } } />
80+ < Select . Trigger style = { { minWidth : " 80px" } } />
7881 < Select . Content >
7982 < Select . Item value = "paragraph" > Paragraph</ Select . Item >
8083 < Select . Item value = "1" > Heading 1</ Select . Item >
@@ -91,34 +94,34 @@ export function FormattingToolbar({ editor }: FormattingToolbarProps) {
9194 { /* Text Formatting */ }
9295 < IconButton
9396 size = "1"
94- variant = { editor . isActive ( ' bold' ) ? ' solid' : ' ghost' }
97+ variant = { editor . isActive ( " bold" ) ? " solid" : " ghost" }
9598 onClick = { toggleBold }
9699 title = "Bold (Ctrl+B)"
97100 >
98101 < FontBoldIcon />
99102 </ IconButton >
100-
103+
101104 < IconButton
102105 size = "1"
103- variant = { editor . isActive ( ' italic' ) ? ' solid' : ' ghost' }
106+ variant = { editor . isActive ( " italic" ) ? " solid" : " ghost" }
104107 onClick = { toggleItalic }
105108 title = "Italic (Ctrl+I)"
106109 >
107110 < FontItalicIcon />
108111 </ IconButton >
109-
112+
110113 < IconButton
111114 size = "1"
112- variant = { editor . isActive ( ' underline' ) ? ' solid' : ' ghost' }
115+ variant = { editor . isActive ( " underline" ) ? " solid" : " ghost" }
113116 onClick = { toggleUnderline }
114117 title = "Underline (Ctrl+U)"
115118 >
116119 < UnderlineIcon />
117120 </ IconButton >
118-
121+
119122 < IconButton
120123 size = "1"
121- variant = { editor . isActive ( ' strike' ) ? ' solid' : ' ghost' }
124+ variant = { editor . isActive ( " strike" ) ? " solid" : " ghost" }
122125 onClick = { toggleStrike }
123126 title = "Strikethrough (Ctrl+Shift+X)"
124127 >
@@ -130,16 +133,16 @@ export function FormattingToolbar({ editor }: FormattingToolbarProps) {
130133 { /* Code */ }
131134 < IconButton
132135 size = "1"
133- variant = { editor . isActive ( ' code' ) ? ' solid' : ' ghost' }
136+ variant = { editor . isActive ( " code" ) ? " solid" : " ghost" }
134137 onClick = { toggleCode }
135138 title = "Inline Code (Ctrl+E)"
136139 >
137140 < CodeIcon />
138141 </ IconButton >
139-
142+
140143 < IconButton
141144 size = "1"
142- variant = { editor . isActive ( ' codeBlock' ) ? ' solid' : ' ghost' }
145+ variant = { editor . isActive ( " codeBlock" ) ? " solid" : " ghost" }
143146 onClick = { toggleCodeBlock }
144147 title = "Code Block (Ctrl+Shift+C)"
145148 >
@@ -151,25 +154,25 @@ export function FormattingToolbar({ editor }: FormattingToolbarProps) {
151154 { /* Lists and Blocks */ }
152155 < IconButton
153156 size = "1"
154- variant = { editor . isActive ( ' bulletList' ) ? ' solid' : ' ghost' }
157+ variant = { editor . isActive ( " bulletList" ) ? " solid" : " ghost" }
155158 onClick = { toggleBulletList }
156159 title = "Bullet List (Ctrl+Shift+8)"
157160 >
158161 < ListBulletIcon />
159162 </ IconButton >
160-
163+
161164 < IconButton
162165 size = "1"
163- variant = { editor . isActive ( ' orderedList' ) ? ' solid' : ' ghost' }
166+ variant = { editor . isActive ( " orderedList" ) ? " solid" : " ghost" }
164167 onClick = { toggleOrderedList }
165168 title = "Numbered List (Ctrl+Shift+7)"
166169 >
167- < span style = { { fontSize : ' 11px' , fontWeight : ' bold' } } > 1.</ span >
170+ < span style = { { fontSize : " 11px" , fontWeight : " bold" } } > 1.</ span >
168171 </ IconButton >
169-
172+
170173 < IconButton
171174 size = "1"
172- variant = { editor . isActive ( ' blockquote' ) ? ' solid' : ' ghost' }
175+ variant = { editor . isActive ( " blockquote" ) ? " solid" : " ghost" }
173176 onClick = { toggleBlockquote }
174177 title = "Blockquote (Ctrl+Shift+B)"
175178 >
@@ -181,13 +184,12 @@ export function FormattingToolbar({ editor }: FormattingToolbarProps) {
181184 { /* Links */ }
182185 < IconButton
183186 size = "1"
184- variant = { editor . isActive ( ' link' ) ? ' solid' : ' ghost' }
187+ variant = { editor . isActive ( " link" ) ? " solid" : " ghost" }
185188 onClick = { setLink }
186189 title = "Link (Ctrl+K)"
187190 >
188191 < Link1Icon />
189192 </ IconButton >
190-
191193 </ Flex >
192194 ) ;
193195}
0 commit comments