@@ -102,8 +102,6 @@ export function RichTextEditorToolbar({
102102 ) ;
103103
104104 const noEditor = ! editor ;
105- const isActive = ( name : string , attrs ?: Record < string , unknown > ) =>
106- editor ?. isActive ( name , attrs ) ?? false ;
107105
108106 const btnClass = ( active : boolean ) =>
109107 `shrink-0 rounded p-2 hover:bg-gray-100 ${ active ? 'bg-gray-200' : '' } ` ;
@@ -137,7 +135,9 @@ export function RichTextEditorToolbar({
137135 editor ?. chain ( ) . focus ( ) . toggleHeading ( { level : 1 } ) . run ( )
138136 }
139137 disabled = { noEditor }
140- className = { btnClass ( isActive ( 'heading' , { level : 1 } ) ) }
138+ className = { btnClass (
139+ editor ?. isActive ( 'heading' , { level : 1 } ) ?? false ,
140+ ) }
141141 title = "Heading 1"
142142 >
143143 < Heading1 className = "h-4 w-4" />
@@ -147,7 +147,9 @@ export function RichTextEditorToolbar({
147147 editor ?. chain ( ) . focus ( ) . toggleHeading ( { level : 2 } ) . run ( )
148148 }
149149 disabled = { noEditor }
150- className = { btnClass ( isActive ( 'heading' , { level : 2 } ) ) }
150+ className = { btnClass (
151+ editor ?. isActive ( 'heading' , { level : 2 } ) ?? false ,
152+ ) }
151153 title = "Heading 2"
152154 >
153155 < Heading2 className = "h-4 w-4" />
@@ -157,7 +159,9 @@ export function RichTextEditorToolbar({
157159 editor ?. chain ( ) . focus ( ) . toggleHeading ( { level : 3 } ) . run ( )
158160 }
159161 disabled = { noEditor }
160- className = { btnClass ( isActive ( 'heading' , { level : 3 } ) ) }
162+ className = { btnClass (
163+ editor ?. isActive ( 'heading' , { level : 3 } ) ?? false ,
164+ ) }
161165 title = "Heading 3"
162166 >
163167 < Heading3 className = "h-4 w-4" />
@@ -169,39 +173,39 @@ export function RichTextEditorToolbar({
169173 < button
170174 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . toggleBold ( ) . run ( ) }
171175 disabled = { noEditor }
172- className = { btnClass ( isActive ( 'bold' ) ) }
176+ className = { btnClass ( editor ?. isActive ( 'bold' ) ?? false ) }
173177 title = "Bold"
174178 >
175179 < Bold className = "h-4 w-4" />
176180 </ button >
177181 < button
178182 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . toggleItalic ( ) . run ( ) }
179183 disabled = { noEditor }
180- className = { btnClass ( isActive ( 'italic' ) ) }
184+ className = { btnClass ( editor ?. isActive ( 'italic' ) ?? false ) }
181185 title = "Italic"
182186 >
183187 < Italic className = "h-4 w-4" />
184188 </ button >
185189 < button
186190 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . toggleUnderline ( ) . run ( ) }
187191 disabled = { noEditor }
188- className = { btnClass ( isActive ( 'underline' ) ) }
192+ className = { btnClass ( editor ?. isActive ( 'underline' ) ?? false ) }
189193 title = "Underline"
190194 >
191195 < UnderlineIcon className = "h-4 w-4" />
192196 </ button >
193197 < button
194198 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . toggleStrike ( ) . run ( ) }
195199 disabled = { noEditor }
196- className = { btnClass ( isActive ( 'strike' ) ) }
200+ className = { btnClass ( editor ?. isActive ( 'strike' ) ?? false ) }
197201 title = "Strikethrough"
198202 >
199203 < Strikethrough className = "h-4 w-4" />
200204 </ button >
201205 < button
202206 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . toggleCode ( ) . run ( ) }
203207 disabled = { noEditor }
204- className = { btnClass ( isActive ( 'code' ) ) }
208+ className = { btnClass ( editor ?. isActive ( 'code' ) ?? false ) }
205209 title = "Code"
206210 >
207211 < Code className = "h-4 w-4" />
@@ -213,23 +217,23 @@ export function RichTextEditorToolbar({
213217 < button
214218 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . toggleBulletList ( ) . run ( ) }
215219 disabled = { noEditor }
216- className = { btnClass ( isActive ( 'bulletList' ) ) }
220+ className = { btnClass ( editor ?. isActive ( 'bulletList' ) ?? false ) }
217221 title = "Bullet List"
218222 >
219223 < List className = "h-4 w-4" />
220224 </ button >
221225 < button
222226 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . toggleOrderedList ( ) . run ( ) }
223227 disabled = { noEditor }
224- className = { btnClass ( isActive ( 'orderedList' ) ) }
228+ className = { btnClass ( editor ?. isActive ( 'orderedList' ) ?? false ) }
225229 title = "Numbered List"
226230 >
227231 < ListOrdered className = "h-4 w-4" />
228232 </ button >
229233 < button
230234 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . toggleBlockquote ( ) . run ( ) }
231235 disabled = { noEditor }
232- className = { btnClass ( isActive ( 'blockquote' ) ) }
236+ className = { btnClass ( editor ?. isActive ( 'blockquote' ) ?? false ) }
233237 title = "Blockquote"
234238 >
235239 < Quote className = "h-4 w-4" />
@@ -241,23 +245,27 @@ export function RichTextEditorToolbar({
241245 < button
242246 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . setTextAlign ( 'left' ) . run ( ) }
243247 disabled = { noEditor }
244- className = { btnClass ( isActive ( 'textAlign' , { textAlign : 'left' } ) ) }
248+ className = { btnClass ( editor ?. isActive ( { textAlign : 'left' } ) ?? false ) }
245249 title = "Align Left"
246250 >
247251 < AlignLeft className = "h-4 w-4" />
248252 </ button >
249253 < button
250254 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . setTextAlign ( 'center' ) . run ( ) }
251255 disabled = { noEditor }
252- className = { btnClass ( isActive ( 'textAlign' , { textAlign : 'center' } ) ) }
256+ className = { btnClass (
257+ editor ?. isActive ( { textAlign : 'center' } ) ?? false ,
258+ ) }
253259 title = "Align Center"
254260 >
255261 < AlignCenter className = "h-4 w-4" />
256262 </ button >
257263 < button
258264 onClick = { ( ) => editor ?. chain ( ) . focus ( ) . setTextAlign ( 'right' ) . run ( ) }
259265 disabled = { noEditor }
260- className = { btnClass ( isActive ( 'textAlign' , { textAlign : 'right' } ) ) }
266+ className = { btnClass (
267+ editor ?. isActive ( { textAlign : 'right' } ) ?? false ,
268+ ) }
261269 title = "Align Right"
262270 >
263271 < AlignRight className = "h-4 w-4" />
@@ -269,7 +277,7 @@ export function RichTextEditorToolbar({
269277 < button
270278 onClick = { addLink }
271279 disabled = { noEditor }
272- className = { btnClass ( isActive ( 'link' ) ) }
280+ className = { btnClass ( editor ?. isActive ( 'link' ) ?? false ) }
273281 title = "Add Link"
274282 >
275283 < LinkIcon className = "h-4 w-4" />
0 commit comments