@madie/madie-design-system 1.2.58 → 1.2.60
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/MadieAlert/index.jsx +1 -0
- package/components/RichTextEditor/RichTextEditor.stories.js +21 -1
- package/components/RichTextEditor/index.jsx +26 -9
- package/components/Select/index.jsx +0 -9
- package/dist/browser.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.js +2 -2
- package/dist/react/index.js.LICENSE.txt +2 -0
- package/dist/react/index.js.map +1 -1
- package/package.json +2 -2
- package/test/components/RichTextEditor.test.js +62 -0
|
@@ -13,7 +13,7 @@ export default {
|
|
|
13
13
|
export const TextEditor = () => {
|
|
14
14
|
const [value, setValue] = useState("test");
|
|
15
15
|
|
|
16
|
-
const handleChange = (
|
|
16
|
+
const handleChange = (selectedVal) => {
|
|
17
17
|
setValue(selectedVal);
|
|
18
18
|
};
|
|
19
19
|
return (
|
|
@@ -22,6 +22,26 @@ export const TextEditor = () => {
|
|
|
22
22
|
required={true}
|
|
23
23
|
onChange={handleChange}
|
|
24
24
|
content={value}
|
|
25
|
+
disabled={false}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const ReadOnlyTextEditor = () => {
|
|
31
|
+
const [value, setValue] = useState(
|
|
32
|
+
"<p>This is <strong>readonly</strong> content</p>"
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const handleChange = (selectedVal) => {
|
|
36
|
+
setValue(selectedVal);
|
|
37
|
+
};
|
|
38
|
+
return (
|
|
39
|
+
<RichTextEditor
|
|
40
|
+
label="Test Text Editor"
|
|
41
|
+
required={true}
|
|
42
|
+
onChange={handleChange}
|
|
43
|
+
content={value}
|
|
44
|
+
disabled={true}
|
|
25
45
|
/>
|
|
26
46
|
);
|
|
27
47
|
};
|
|
@@ -11,7 +11,6 @@ import TableHeader from "@tiptap/extension-table-header";
|
|
|
11
11
|
import TableRow from "@tiptap/extension-table-row";
|
|
12
12
|
import Underline from "@tiptap/extension-underline";
|
|
13
13
|
import StarterKit from "@tiptap/starter-kit";
|
|
14
|
-
import { Markdown } from "tiptap-markdown";
|
|
15
14
|
import { IconButton } from "@mui/material";
|
|
16
15
|
import FormatBoldIcon from "@mui/icons-material/FormatBold";
|
|
17
16
|
import FormatItalicIcon from "@mui/icons-material/FormatItalic";
|
|
@@ -21,13 +20,15 @@ import FormatListBulletedIcon from "@mui/icons-material/FormatListBulleted";
|
|
|
21
20
|
import FormatListNumberedIcon from "@mui/icons-material/FormatListNumbered";
|
|
22
21
|
import TableChartIcon from "@mui/icons-material/TableChart";
|
|
23
22
|
import { Tooltip } from "@mui/material";
|
|
23
|
+
import { kebabCase } from "lodash";
|
|
24
|
+
import DOMPurify from "dompurify";
|
|
24
25
|
|
|
25
26
|
const MenuBar = ({ editor }) => {
|
|
26
27
|
if (!editor) {
|
|
27
28
|
return null;
|
|
28
29
|
}
|
|
29
30
|
return (
|
|
30
|
-
<div className="control-group">
|
|
31
|
+
<div className="control-group" data-testid="rich-text-editor-toolbar">
|
|
31
32
|
<div className="button-group">
|
|
32
33
|
<Tooltip
|
|
33
34
|
data-testid="bold-tooltip"
|
|
@@ -174,12 +175,12 @@ const RichTextEditor = ({
|
|
|
174
175
|
label,
|
|
175
176
|
onChange,
|
|
176
177
|
content,
|
|
178
|
+
disabled,
|
|
177
179
|
}) => {
|
|
178
180
|
const editor = useEditor(
|
|
179
181
|
{
|
|
180
182
|
extensions: [
|
|
181
183
|
StarterKit,
|
|
182
|
-
Markdown,
|
|
183
184
|
Gapcursor,
|
|
184
185
|
Table.configure({
|
|
185
186
|
resizable: true,
|
|
@@ -192,21 +193,23 @@ const RichTextEditor = ({
|
|
|
192
193
|
shouldRerenderOnTransaction: false,
|
|
193
194
|
content,
|
|
194
195
|
onUpdate: ({ editor }) => {
|
|
195
|
-
const newValue = editor.
|
|
196
|
+
const newValue = editor.getHTML();
|
|
196
197
|
onChange(newValue);
|
|
197
|
-
console.log(newValue);
|
|
198
198
|
},
|
|
199
199
|
},
|
|
200
200
|
[content]
|
|
201
201
|
);
|
|
202
202
|
return (
|
|
203
|
-
<div
|
|
203
|
+
<div
|
|
204
|
+
className="rich-text-editor"
|
|
205
|
+
data-testid={`${kebabCase(label)}-rich-text-editor`}
|
|
206
|
+
>
|
|
204
207
|
<InputLabel
|
|
205
208
|
shrink
|
|
206
209
|
required={required}
|
|
207
210
|
error={error}
|
|
208
211
|
htmlFor={id}
|
|
209
|
-
style={{ marginBottom: 0, height: 16 }} // force a
|
|
212
|
+
style={{ marginBottom: 0, height: 16 }} // force a height
|
|
210
213
|
sx={[
|
|
211
214
|
{
|
|
212
215
|
backgroundColor: "transparent",
|
|
@@ -241,8 +244,21 @@ const RichTextEditor = ({
|
|
|
241
244
|
>
|
|
242
245
|
{label}
|
|
243
246
|
</InputLabel>
|
|
244
|
-
|
|
245
|
-
|
|
247
|
+
{disabled ? (
|
|
248
|
+
<p
|
|
249
|
+
data-testid={`${id}-value`}
|
|
250
|
+
aria-labelledby={label}
|
|
251
|
+
dangerouslySetInnerHTML={{
|
|
252
|
+
__html: content ? DOMPurify.sanitize(content) : "-",
|
|
253
|
+
}}
|
|
254
|
+
/>
|
|
255
|
+
|
|
256
|
+
) : (
|
|
257
|
+
<>
|
|
258
|
+
<MenuBar editor={editor}/>
|
|
259
|
+
<EditorContent editor={editor}/>
|
|
260
|
+
</>
|
|
261
|
+
)}
|
|
246
262
|
</div>
|
|
247
263
|
);
|
|
248
264
|
};
|
|
@@ -254,6 +270,7 @@ RichTextEditor.propTypes = {
|
|
|
254
270
|
label: PropTypes.string,
|
|
255
271
|
onChange: PropTypes.func,
|
|
256
272
|
content: PropTypes.any,
|
|
273
|
+
disabled: PropTypes.bool,
|
|
257
274
|
};
|
|
258
275
|
|
|
259
276
|
MenuBar.propTypes = {
|
|
@@ -31,15 +31,6 @@ const Select = ({
|
|
|
31
31
|
);
|
|
32
32
|
return (
|
|
33
33
|
<FormControl error={error} fullWidth>
|
|
34
|
-
{/* to deal with multiple height helper text in a single row*/}
|
|
35
|
-
<div
|
|
36
|
-
style={{
|
|
37
|
-
width: 1,
|
|
38
|
-
display: "flex",
|
|
39
|
-
flexDirection: "column",
|
|
40
|
-
flexGrow: 1,
|
|
41
|
-
}}
|
|
42
|
-
/>
|
|
43
34
|
<InputLabel
|
|
44
35
|
// {/* has init at .2rem/3.2 px bottom. passing sx breaks style. */}
|
|
45
36
|
id={`${id}-label`}
|