@madie/madie-design-system 1.2.57 → 1.2.59

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.
@@ -13,7 +13,7 @@ export default {
13
13
  export const TextEditor = () => {
14
14
  const [value, setValue] = useState("test");
15
15
 
16
- const handleChange = (id, selectedVal) => {
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.storage.markdown.getMarkdown();
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 className="rich-text-editor">
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 heignt
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
- <MenuBar editor={editor} />
245
- <EditorContent editor={editor} />
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`}
@@ -1,6 +1,6 @@
1
1
  import React, { useState } from "react";
2
2
  import { withKnobs } from "@storybook/addon-knobs";
3
-
3
+ import "./tabs.scss";
4
4
  import Tabs from "./index";
5
5
  import Tab from "./Tab";
6
6
 
@@ -147,44 +147,46 @@ export const TypeA = () => {
147
147
  />
148
148
  </Tabs>
149
149
  </div>
150
- <div>
151
- Vertical Standard: C
152
- <Tabs
153
- type="C"
154
- value={selected}
155
- onChange={handleChange}
156
- orientation="vertical"
157
- >
158
- <Tab
150
+ <div className={"vertical-standard-type-c-wrapper"}>
151
+ <div className={"vertical-standard-type-c"}>
152
+ <h4>Vertical Standard: C</h4>
153
+ <Tabs
159
154
  type="C"
160
- size="standard"
161
- label="Item One"
162
- value={1}
155
+ value={selected}
156
+ onChange={handleChange}
163
157
  orientation="vertical"
164
- />
165
- <Tab
166
- type="C"
167
- size="standard"
168
- label="Item Two"
169
- value={2}
170
- orientation="vertical"
171
- />
172
- <Tab
173
- type="C"
174
- size="standard"
175
- label="Item Three"
176
- value={3}
177
- orientation="vertical"
178
- />
179
- <Tab
180
- type="C"
181
- size="standard"
182
- label="disabled"
183
- value={4}
184
- disabled
185
- orientation="vertical"
186
- />
187
- </Tabs>
158
+ >
159
+ <Tab
160
+ type="C"
161
+ size="standard"
162
+ label="Item One"
163
+ value={1}
164
+ orientation="vertical"
165
+ />
166
+ <Tab
167
+ type="C"
168
+ size="standard"
169
+ label="Item Two"
170
+ value={2}
171
+ orientation="vertical"
172
+ />
173
+ <Tab
174
+ type="C"
175
+ size="standard"
176
+ label="Item Three"
177
+ value={3}
178
+ orientation="vertical"
179
+ />
180
+ <Tab
181
+ type="C"
182
+ size="standard"
183
+ label="disabled"
184
+ value={4}
185
+ disabled
186
+ orientation="vertical"
187
+ />
188
+ </Tabs>
189
+ </div>
188
190
  </div>
189
191
  <div style={{ width: "fit-content" }}>
190
192
  Standard: D
@@ -1,6 +1,6 @@
1
+ import React from "react";
1
2
  import PropTypes from "prop-types";
2
3
  import { Tabs as MuiTabs } from "@mui/material";
3
- import React from "react";
4
4
 
5
5
  const typeA = {
6
6
  "& .MuiTabs-flexContainer": {
@@ -30,6 +30,15 @@ const typeC = {
30
30
  },
31
31
  };
32
32
 
33
+ const typeCVerticalSelected = {
34
+ "& .MuiTab-root.Mui-selected": {
35
+ borderTop: "solid 1px #8C8C8C",
36
+ borderBottom: "solid 1px #8C8C8C",
37
+ borderRight: "1px solid white",
38
+ width: "calc(100% + 1px)",
39
+ },
40
+ };
41
+
33
42
  const typeD = {
34
43
  backgroundColor: "#FFF",
35
44
  color: "#515151",
@@ -40,39 +49,51 @@ const typeD = {
40
49
  },
41
50
  };
42
51
 
43
- const Tabs = ({ type, size, ...rest }) => {
44
- const baseStyle = {
52
+ const baseStyle = {
53
+ outline: "none",
54
+ fontFamily: "Rubik, sans Sarif",
55
+ fontWeight: 400,
56
+ lineHeight: 19,
57
+ backgroundColor: "transparent",
58
+ "& .Mui-selected": {
45
59
  outline: "none",
46
- fontFamily: "Rubik, sans Sarif",
47
- fontWeight: 400,
48
- lineHeight: 19,
49
- backgroundColor: "transparent",
50
- "& .Mui-selected": {
51
- outline: "none",
52
- fontWeight: 500,
53
- color: "#333 !important",
54
- backgroundColor: "#fff",
55
- },
56
- };
57
- const style = ((type) => {
58
- if (type === "A") {
59
- return { ...baseStyle, ...typeA };
60
- }
61
- if (type === "B") {
62
- return { ...baseStyle, ...typeB };
63
- }
64
- if (type === "C") {
65
- return { ...baseStyle, ...typeC };
66
- }
67
- if (type === "D") {
68
- return { ...baseStyle, ...typeD };
69
- }
70
- })(type);
71
- return <MuiTabs disableRipple sx={style} {...rest} />;
60
+ fontWeight: 500,
61
+ color: "#333 !important",
62
+ backgroundColor: "#fff",
63
+ },
64
+ };
65
+
66
+ const Tabs = ({ type, size, orientation, ...rest }) => {
67
+ let style = { ...baseStyle };
68
+
69
+ switch (type) {
70
+ case "A":
71
+ style = { ...style, ...typeA };
72
+ break;
73
+ case "B":
74
+ style = { ...style, ...typeB };
75
+ break;
76
+ case "C":
77
+ if (orientation === "vertical") {
78
+ style = { ...style, ...typeC, ...typeCVerticalSelected };
79
+ } else {
80
+ style = { ...style, ...typeC };
81
+ }
82
+ break;
83
+ case "D":
84
+ style = { ...style, ...typeD };
85
+ break;
86
+ default:
87
+ break;
88
+ }
89
+
90
+ return (
91
+ <MuiTabs disableRipple orientation={orientation} sx={style} {...rest} />
92
+ );
72
93
  };
73
94
 
74
95
  Tabs.propTypes = {
75
- orientatin: PropTypes.string,
96
+ orientation: PropTypes.string,
76
97
  type: PropTypes.oneOf(["A", "B", "C", "D"]),
77
98
  size: PropTypes.oneOf(["standard", "large"]),
78
99
  ariaLabel: PropTypes.string,
@@ -0,0 +1,13 @@
1
+ // Required to have OverFlow visible for parent component of Tabs
2
+ // in order to add styling for Mui.selected Tabs
3
+ .vertical-standard-type-c-wrapper * {
4
+ overflow: visible !important;
5
+ }
6
+
7
+ .vertical-standard-type-c {
8
+ > h4 {
9
+ padding-top: 16px;
10
+ }
11
+ width: 300px;
12
+ border-right: solid 1px #8C8C8C;
13
+ }
@@ -91,7 +91,7 @@ const TextArea = ({
91
91
  </FormHelperText>
92
92
  )}
93
93
  <TextareaAutosize
94
- style={{ marginTop: "8px", maxWidth: "100%", }}
94
+ style={{ marginTop: "8px", maxWidth: "100%" }}
95
95
  className={
96
96
  error ? "text-area-variable error" : "text-area-variable"
97
97
  }
@@ -100,7 +100,7 @@ const TextArea = ({
100
100
  id={id}
101
101
  {...inputProps}
102
102
  {...rest}
103
- />
103
+ />
104
104
  {maxLength && !disabled && (
105
105
  <span
106
106
  style={{
@@ -44,7 +44,7 @@ const TextField = ({
44
44
 
45
45
  const extendedTextFieldStyles = {
46
46
  borderRadius: "3px",
47
-
47
+
48
48
  border: "none",
49
49
  marginTop: "8px",
50
50
  "& .MuiOutlinedInput-notchedOutline": {