@@ -3,8 +3,6 @@ import type { Editor } from '@tiptap/core';
3
3
import './RichTextEditorMenuBar.scss' ;
4
4
5
5
import React from 'react' ;
6
- import * as propTypes from 'prop-types' ;
7
-
8
6
import classNames from 'classnames' ;
9
7
10
8
import {
@@ -17,68 +15,74 @@ import {
17
15
} from '@fortawesome/pro-regular-svg-icons' ;
18
16
import IconButton from '../IconButton' ;
19
17
20
- import { RichTextEditorActions , RichTextEditorAllActionsArray } from './richTextEditorActions' ;
18
+ import { RichTextEditorActions } from './richTextEditorActions' ;
21
19
import { createActionHandlers } from './actionHandlers' ;
22
20
23
21
type RichTextEditorMenuBarProps = {
24
22
availableActions : typeof RichTextEditorActions [ keyof typeof RichTextEditorActions ] [ ] ;
25
23
editor : Editor ;
24
+ editable ?: boolean
26
25
}
27
26
28
27
function RichTextEditorMenuBar ( {
29
28
availableActions,
30
29
editor,
30
+ editable = true ,
31
31
} : RichTextEditorMenuBarProps ) {
32
32
const actionHandlers = createActionHandlers ( editor ) ;
33
33
34
34
const actions = [
35
35
{
36
36
label : 'Bold' ,
37
37
name : RichTextEditorActions . BOLD ,
38
- disabled : availableActions . includes ( RichTextEditorActions . BOLD ) && ! editor . can ( )
39
- . chain ( )
40
- . focus ( )
41
- . toggleBold ( )
42
- . run ( ) ,
38
+ disabled : ! editable || (
39
+ availableActions . includes ( RichTextEditorActions . BOLD ) && ! editor . can ( )
40
+ . chain ( )
41
+ . focus ( )
42
+ . toggleBold ( )
43
+ . run ( )
44
+ ) ,
43
45
onClick : actionHandlers . bold ,
44
46
icon : faBold ,
45
47
} ,
46
48
{
47
49
label : 'Italic' ,
48
50
name : RichTextEditorActions . ITALIC ,
49
- disabled : availableActions . includes ( RichTextEditorActions . ITALIC ) && ! editor . can ( )
50
- . chain ( )
51
- . focus ( )
52
- . toggleItalic ( )
53
- . run ( ) ,
51
+ disabled : ! editable || (
52
+ availableActions . includes ( RichTextEditorActions . ITALIC ) && ! editor . can ( )
53
+ . chain ( )
54
+ . focus ( )
55
+ . toggleItalic ( )
56
+ . run ( )
57
+ ) ,
54
58
onClick : actionHandlers . italic ,
55
59
icon : faItalic ,
56
60
} ,
57
61
{
58
62
label : 'Link' ,
59
63
name : RichTextEditorActions . LINK ,
60
- disabled : false ,
64
+ disabled : ! editable ,
61
65
onClick : actionHandlers . link ,
62
66
icon : faLink ,
63
67
} ,
64
68
{
65
69
label : 'Unlink' ,
66
70
name : RichTextEditorActions . UNLINK ,
67
- disabled : availableActions . includes ( RichTextEditorActions . LINK ) && ! editor . isActive ( 'link' ) ,
71
+ disabled : ! editable || ( availableActions . includes ( RichTextEditorActions . LINK ) && ! editor . isActive ( 'link' ) ) ,
68
72
onClick : actionHandlers . unlink ,
69
73
icon : faUnlink ,
70
74
} ,
71
75
{
72
76
label : 'Unordered List' ,
73
77
name : RichTextEditorActions . UNORDERED_LIST ,
74
- disabled : false ,
78
+ disabled : ! editable ,
75
79
onClick : actionHandlers . unorderedList ,
76
80
icon : faListUl ,
77
81
} ,
78
82
{
79
83
label : 'Ordered List' ,
80
84
name : RichTextEditorActions . ORDERED_LIST ,
81
- disabled : false ,
85
+ disabled : ! editable ,
82
86
onClick : actionHandlers . orderedList ,
83
87
icon : faListOl ,
84
88
} ,
@@ -104,10 +108,5 @@ function RichTextEditorMenuBar({
104
108
) ;
105
109
}
106
110
107
- RichTextEditorMenuBar . propTypes = {
108
- availableActions : propTypes . arrayOf ( propTypes . oneOf ( RichTextEditorAllActionsArray ) ) . isRequired ,
109
- editor : propTypes . object . isRequired ,
110
- } ;
111
-
112
111
// eslint-disable-next-line import/no-default-export
113
112
export default RichTextEditorMenuBar ;
0 commit comments