@madie/madie-design-system 1.2.77 → 1.2.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/RichTextEditor/index.jsx +88 -65
- package/dist/browser.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
- package/test/components/MadieDeleteDialog.test.js +1 -1
- package/test/components/RichTextEditor.test.js +257 -37
|
@@ -40,7 +40,7 @@ const iconStyle = {
|
|
|
40
40
|
display: "block",
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
const MenuBar = ({editor, disabled}) => {
|
|
43
|
+
export const MenuBar = ({editor, disabled, id}) => {
|
|
44
44
|
if (!editor) {
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
@@ -49,11 +49,12 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
49
49
|
className="control-group"
|
|
50
50
|
role="toolbar"
|
|
51
51
|
aria-label="Text formatting toolbar"
|
|
52
|
-
data-testid=
|
|
52
|
+
data-testid={`${id}-rich-text-editor-toolbar`}
|
|
53
|
+
id={`${id}-rich-text-editor-toolbar`}
|
|
53
54
|
>
|
|
54
55
|
<div className="button-group">
|
|
55
56
|
<Tooltip
|
|
56
|
-
data-testid=
|
|
57
|
+
data-testid={`${id}-undo-tooltip`}
|
|
57
58
|
title="Undo"
|
|
58
59
|
placement="top"
|
|
59
60
|
enterDelay={1000}
|
|
@@ -64,12 +65,13 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
64
65
|
onClick={() =>
|
|
65
66
|
editor.chain().focus().undo().run()
|
|
66
67
|
}
|
|
68
|
+
data-testId={`${id}-undo-button`}
|
|
67
69
|
>
|
|
68
70
|
<UndoIcon/>
|
|
69
71
|
</IconButton>
|
|
70
72
|
</Tooltip>
|
|
71
73
|
<Tooltip
|
|
72
|
-
data-testid=
|
|
74
|
+
data-testid={`${id}-redo-tooltip`}
|
|
73
75
|
title="Redo"
|
|
74
76
|
placement="top"
|
|
75
77
|
enterDelay={1000}
|
|
@@ -81,12 +83,13 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
81
83
|
editor.chain().focus().redo().run()
|
|
82
84
|
}
|
|
83
85
|
style={{borderRight: "solid 1px #9c9c9c"}}
|
|
86
|
+
data-testId={`${id}-redo-button`}
|
|
84
87
|
>
|
|
85
88
|
<RedoIcon/>
|
|
86
89
|
</IconButton>
|
|
87
90
|
</Tooltip>
|
|
88
91
|
<Tooltip
|
|
89
|
-
data-testid=
|
|
92
|
+
data-testid={`${id}-bold-tooltip`}
|
|
90
93
|
title="Bold"
|
|
91
94
|
placement="top"
|
|
92
95
|
enterDelay={1000}
|
|
@@ -102,12 +105,13 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
102
105
|
className={editor.isActive("bold") ? "is-active" : ""}
|
|
103
106
|
disabled={disabled}
|
|
104
107
|
type="button"
|
|
108
|
+
data-testId={`${id}-add-bold-button`}
|
|
105
109
|
>
|
|
106
110
|
<FormatBoldIcon/>
|
|
107
111
|
</IconButton>
|
|
108
112
|
</Tooltip>
|
|
109
113
|
<Tooltip
|
|
110
|
-
data-testid=
|
|
114
|
+
data-testid={`${id}-italic-tooltip`}
|
|
111
115
|
title="Italic"
|
|
112
116
|
placement="top"
|
|
113
117
|
enterDelay={1000}
|
|
@@ -123,12 +127,13 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
123
127
|
className={editor.isActive("italic") ? "is-active" : ""}
|
|
124
128
|
disabled={disabled}
|
|
125
129
|
type="button"
|
|
130
|
+
data-testId={`${id}-add-italic-button`}
|
|
126
131
|
>
|
|
127
132
|
<FormatItalicIcon/>
|
|
128
133
|
</IconButton>
|
|
129
134
|
</Tooltip>
|
|
130
135
|
<Tooltip
|
|
131
|
-
data-testid=
|
|
136
|
+
data-testid={`${id}-underline-tooltip`}
|
|
132
137
|
title="Underline"
|
|
133
138
|
placement="top"
|
|
134
139
|
enterDelay={1000}
|
|
@@ -146,12 +151,13 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
146
151
|
}
|
|
147
152
|
disabled={disabled}
|
|
148
153
|
type="button"
|
|
154
|
+
data-testId={`${id}-add-underline-button`}
|
|
149
155
|
>
|
|
150
156
|
<FormatUnderlinedIcon/>
|
|
151
157
|
</IconButton>
|
|
152
158
|
</Tooltip>
|
|
153
159
|
<Tooltip
|
|
154
|
-
data-testid=
|
|
160
|
+
data-testid={`${id}-strikethrough-tooltip`}
|
|
155
161
|
title="Strikethrough"
|
|
156
162
|
placement="top"
|
|
157
163
|
enterDelay={1000}
|
|
@@ -168,12 +174,13 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
168
174
|
style={{borderRight: "solid 1px #9c9c9c"}}
|
|
169
175
|
disabled={disabled}
|
|
170
176
|
type="button"
|
|
177
|
+
data-testId={`${id}-add-strikethrough-button`}
|
|
171
178
|
>
|
|
172
179
|
<StrikethroughSIcon/>
|
|
173
180
|
</IconButton>
|
|
174
181
|
</Tooltip>
|
|
175
182
|
<Tooltip
|
|
176
|
-
data-testid=
|
|
183
|
+
data-testid={`${id}-orderedlist-tooltip`}
|
|
177
184
|
title="Ordered List"
|
|
178
185
|
placement="top"
|
|
179
186
|
enterDelay={1000}
|
|
@@ -191,12 +198,13 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
191
198
|
}
|
|
192
199
|
disabled={disabled}
|
|
193
200
|
type="button"
|
|
201
|
+
data-testId={`${id}-add-ordered-list-button`}
|
|
194
202
|
>
|
|
195
203
|
<FormatListNumberedIcon/>
|
|
196
204
|
</IconButton>
|
|
197
205
|
</Tooltip>
|
|
198
206
|
<Tooltip
|
|
199
|
-
data-testid=
|
|
207
|
+
data-testid={`${id}-bulletedlist-tooltip`}
|
|
200
208
|
title="Bulleted List"
|
|
201
209
|
placement="top"
|
|
202
210
|
enterDelay={1000}
|
|
@@ -215,12 +223,13 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
215
223
|
style={{borderRight: "solid 1px #9c9c9c"}}
|
|
216
224
|
disabled={disabled}
|
|
217
225
|
type="button"
|
|
226
|
+
data-testId={`${id}-add-bulleted-list-button`}
|
|
218
227
|
>
|
|
219
228
|
<FormatListBulletedIcon/>
|
|
220
229
|
</IconButton>
|
|
221
230
|
</Tooltip>
|
|
222
231
|
<Tooltip
|
|
223
|
-
data-testid=
|
|
232
|
+
data-testid={`${id}-table-tooltip`}
|
|
224
233
|
title="Table"
|
|
225
234
|
placement="top"
|
|
226
235
|
enterDelay={1000}
|
|
@@ -241,6 +250,7 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
241
250
|
}
|
|
242
251
|
disabled={disabled}
|
|
243
252
|
type="button"
|
|
253
|
+
data-testId={`${id}-insert-table-button`}
|
|
244
254
|
>
|
|
245
255
|
|
|
246
256
|
<TableChartIcon/>
|
|
@@ -249,21 +259,22 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
249
259
|
{editor.isActive("table") && (
|
|
250
260
|
<>
|
|
251
261
|
<Tooltip
|
|
252
|
-
data-testid=
|
|
262
|
+
data-testid={`${id}-add-row-above-tooltip`}
|
|
253
263
|
title="Add row above"
|
|
254
264
|
placement="top"
|
|
255
265
|
enterDelay={1000}
|
|
256
266
|
arrow
|
|
257
267
|
>
|
|
258
|
-
<IconButton
|
|
268
|
+
<IconButton
|
|
259
269
|
key="addRowAbove"
|
|
260
270
|
onClick={() => editor.chain().focus().addRowBefore().run()}
|
|
271
|
+
data-testId={`${id}-add-row-above-button`}
|
|
261
272
|
>
|
|
262
273
|
<AddRowAboveIcon style={iconStyle}/>
|
|
263
274
|
</IconButton>
|
|
264
275
|
</Tooltip>
|
|
265
276
|
<Tooltip
|
|
266
|
-
data-testid=
|
|
277
|
+
data-testid={`${id}-add-row-below-tooltip`}
|
|
267
278
|
title="Add row below"
|
|
268
279
|
placement="top"
|
|
269
280
|
enterDelay={1000}
|
|
@@ -271,6 +282,7 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
271
282
|
>
|
|
272
283
|
<IconButton
|
|
273
284
|
key="addRowBelow"
|
|
285
|
+
data-testId={`${id}-add-row-below-button`}
|
|
274
286
|
onClick={() => editor.chain().focus().addRowAfter().run()}
|
|
275
287
|
>
|
|
276
288
|
<AddRowBelowIcon style={iconStyle}/>
|
|
@@ -278,7 +290,7 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
278
290
|
</Tooltip>
|
|
279
291
|
|
|
280
292
|
<Tooltip
|
|
281
|
-
data-testid=
|
|
293
|
+
data-testid={`${id}-remove-row-tooltip`}
|
|
282
294
|
title="Remove row"
|
|
283
295
|
placement="top"
|
|
284
296
|
enterDelay={1000}
|
|
@@ -286,13 +298,14 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
286
298
|
>
|
|
287
299
|
<IconButton
|
|
288
300
|
key="deleteRow"
|
|
301
|
+
data-testId={`${id}-delete-row-below-button`}
|
|
289
302
|
onClick={() => editor.chain().focus().deleteRow().run()}
|
|
290
303
|
>
|
|
291
304
|
<DeleteRowIcon style={iconStyle}/>
|
|
292
305
|
</IconButton>
|
|
293
306
|
</Tooltip>
|
|
294
307
|
<Tooltip
|
|
295
|
-
data-testid=
|
|
308
|
+
data-testid={`${id}-add-column-right-tooltip`}
|
|
296
309
|
title="Add column right"
|
|
297
310
|
placement="top"
|
|
298
311
|
enterDelay={1000}
|
|
@@ -300,13 +313,14 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
300
313
|
>
|
|
301
314
|
<IconButton
|
|
302
315
|
key="addColumnRight"
|
|
316
|
+
data-testId={`${id}-add-column-right-button`}
|
|
303
317
|
onClick={() => editor.chain().focus().addColumnAfter().run()}
|
|
304
318
|
>
|
|
305
319
|
<AddColumnRightIcon style={iconStyle}/>
|
|
306
320
|
</IconButton>
|
|
307
321
|
</Tooltip>
|
|
308
322
|
<Tooltip
|
|
309
|
-
data-testid=
|
|
323
|
+
data-testid={`${id}-add-column-left-tooltip`}
|
|
310
324
|
title="Add column left"
|
|
311
325
|
placement="top"
|
|
312
326
|
enterDelay={1000}
|
|
@@ -315,13 +329,14 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
315
329
|
<IconButton
|
|
316
330
|
key="addColumnLeft"
|
|
317
331
|
onClick={() => editor.chain().focus().addColumnBefore().run()}
|
|
332
|
+
data-testId={`${id}-add-column-left-button`}
|
|
318
333
|
>
|
|
319
334
|
<AddColumnLeftIcon style={iconStyle}/>
|
|
320
335
|
</IconButton>
|
|
321
336
|
</Tooltip>
|
|
322
337
|
|
|
323
338
|
<Tooltip
|
|
324
|
-
data-testid=
|
|
339
|
+
data-testid={`${id}-remove-column-tooltip`}
|
|
325
340
|
title="Remove column"
|
|
326
341
|
placement="top"
|
|
327
342
|
enterDelay={1000}
|
|
@@ -330,13 +345,14 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
330
345
|
<IconButton
|
|
331
346
|
key="deleteColumn"
|
|
332
347
|
onClick={() => editor.chain().focus().deleteColumn().run()}
|
|
348
|
+
data-testId={`${id}-delete-column-right-button`}
|
|
333
349
|
>
|
|
334
350
|
<DeleteColumnIcon style={iconStyle}/>
|
|
335
351
|
</IconButton>
|
|
336
352
|
</Tooltip>
|
|
337
353
|
|
|
338
354
|
<Tooltip
|
|
339
|
-
data-testid=
|
|
355
|
+
data-testid={`${id}-remove-table-tooltip`}
|
|
340
356
|
title="Remove table"
|
|
341
357
|
placement="top"
|
|
342
358
|
enterDelay={1000}
|
|
@@ -345,6 +361,7 @@ const MenuBar = ({editor, disabled}) => {
|
|
|
345
361
|
<IconButton
|
|
346
362
|
key="deleteTable"
|
|
347
363
|
onClick={() => editor.chain().focus().deleteTable().run()}
|
|
364
|
+
data-testId={`${id}-delete-table-button`}
|
|
348
365
|
style={{borderRight: "solid 1px #9c9c9c"}}
|
|
349
366
|
>
|
|
350
367
|
<DeleteTableIcon style={iconStyle}/>
|
|
@@ -407,6 +424,7 @@ const RichTextEditor = ({
|
|
|
407
424
|
<div className="rich-text-editor" data-testid={`${kebabCase(id)}-rich-text-editor`}>
|
|
408
425
|
<InputLabel
|
|
409
426
|
id={`${id}-label`}
|
|
427
|
+
data-testid={`${id}-label`}
|
|
410
428
|
shrink
|
|
411
429
|
required={required}
|
|
412
430
|
error={error}
|
|
@@ -429,38 +447,53 @@ const RichTextEditor = ({
|
|
|
429
447
|
);
|
|
430
448
|
}
|
|
431
449
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
450
|
+
|
|
451
|
+
const editor = useEditor({
|
|
452
|
+
parseOptions: {
|
|
453
|
+
preserveWhitespace: 'full',
|
|
454
|
+
},
|
|
455
|
+
extensions: [
|
|
456
|
+
StarterKit,
|
|
457
|
+
Gapcursor,
|
|
458
|
+
Table.configure({
|
|
459
|
+
resizable: true,
|
|
460
|
+
HTMLAttributes: {
|
|
461
|
+
class: "rich-text-table",
|
|
462
|
+
},
|
|
463
|
+
}),
|
|
464
|
+
TableRow,
|
|
465
|
+
TableHeader,
|
|
466
|
+
TableCell,
|
|
467
|
+
Underline,
|
|
468
|
+
Strike.extend({
|
|
469
|
+
strike: false, // disable default strike through
|
|
470
|
+
renderHTML({HTMLAttributes}) {
|
|
471
|
+
return ["del", HTMLAttributes, 0];
|
|
472
|
+
},
|
|
473
|
+
}),
|
|
474
|
+
],
|
|
475
|
+
editorProps: {
|
|
476
|
+
attributes: {
|
|
477
|
+
tabIndex: '0',
|
|
478
|
+
role: 'textbox',
|
|
479
|
+
id,
|
|
480
|
+
'data-testid': `${id}-rich-text-editor-content`,
|
|
481
|
+
'aria-invalid': error ? "true" : undefined,
|
|
482
|
+
'aria-labelledby': `${id}-label`,
|
|
483
|
+
'aria-describedby': helperText ? `${id}-helper-text` : undefined,
|
|
484
|
+
'aria-multiline': "true",
|
|
485
|
+
'aria-required': required ? "true" : undefined,
|
|
486
|
+
'className': `${error ? "has-error" : ""}`
|
|
453
487
|
},
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
});
|
|
488
|
+
},
|
|
489
|
+
shouldRerenderOnTransaction: false,
|
|
490
|
+
content,
|
|
491
|
+
editable: !disabled,
|
|
492
|
+
onUpdate: ({editor}) => {
|
|
493
|
+
const newValue = editor.getHTML();
|
|
494
|
+
onChange?.(newValue);
|
|
495
|
+
},
|
|
496
|
+
});
|
|
464
497
|
|
|
465
498
|
React.useEffect(() => {
|
|
466
499
|
if (editor && content !== editor.getHTML()) {
|
|
@@ -492,6 +525,7 @@ const RichTextEditor = ({
|
|
|
492
525
|
>
|
|
493
526
|
<InputLabel
|
|
494
527
|
id={`${id}-label`}
|
|
528
|
+
data-testid={`${id}-label`}
|
|
495
529
|
shrink
|
|
496
530
|
required={required}
|
|
497
531
|
error={error}
|
|
@@ -502,8 +536,7 @@ const RichTextEditor = ({
|
|
|
502
536
|
>
|
|
503
537
|
{label}
|
|
504
538
|
</InputLabel>
|
|
505
|
-
|
|
506
|
-
{helperText && (
|
|
539
|
+
{helperText ? (
|
|
507
540
|
<FormHelperText
|
|
508
541
|
tabIndex={0}
|
|
509
542
|
aria-live="polite"
|
|
@@ -522,22 +555,11 @@ const RichTextEditor = ({
|
|
|
522
555
|
>
|
|
523
556
|
{helperText}
|
|
524
557
|
</FormHelperText>
|
|
525
|
-
|
|
558
|
+
) : null}
|
|
526
559
|
<>
|
|
527
|
-
<MenuBar editor={editor} disabled={disabled}/>
|
|
560
|
+
<MenuBar editor={editor} disabled={disabled} id={id}/>
|
|
528
561
|
<EditorContent
|
|
529
|
-
id={id}
|
|
530
|
-
tabIndex={0}
|
|
531
|
-
data-testid="rich-text-editor-content"
|
|
532
562
|
editor={editor}
|
|
533
|
-
aria-labelledby={`${id}-label`}
|
|
534
|
-
aria-describedby={
|
|
535
|
-
helperText ? `${id}-helper-text` : undefined
|
|
536
|
-
}
|
|
537
|
-
aria-multiline="true"
|
|
538
|
-
aria-required={required || undefined}
|
|
539
|
-
aria-invalid={error || undefined}
|
|
540
|
-
className={`${error ? "has-error" : ""}`}
|
|
541
563
|
/>
|
|
542
564
|
</>
|
|
543
565
|
</div>
|
|
@@ -561,6 +583,7 @@ RichTextEditor.propTypes = {
|
|
|
561
583
|
MenuBar.propTypes = {
|
|
562
584
|
editor: PropTypes.any,
|
|
563
585
|
disabled: PropTypes.bool,
|
|
586
|
+
id: PropTypes.string,
|
|
564
587
|
};
|
|
565
588
|
|
|
566
589
|
export default RichTextEditor;
|