@madie/madie-design-system 1.2.62 → 2.0.1

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.
Files changed (156) hide show
  1. package/.babelrc +14 -2
  2. package/.eslintrc.js +1 -1
  3. package/.storybook/.babelrc +2 -1
  4. package/.storybook/main.js +3 -11
  5. package/.storybook/preview.js +1 -1
  6. package/components/Accordion/index.jsx +32 -36
  7. package/components/AutoComplete/AutoComplete.jsx +2 -17
  8. package/components/Button/Button.stories.js +0 -7
  9. package/components/Button/index.js +34 -44
  10. package/components/DateField/DateField.jsx +2 -15
  11. package/components/DateField/DateField.stories.jsx +23 -10
  12. package/components/DateTimeField/DateTimeField.jsx +7 -11
  13. package/components/DateTimeField/DateTimeField.stories.jsx +29 -19
  14. package/components/InputLabel/index.jsx +1 -6
  15. package/components/Instant/Instant.stories.js +14 -6
  16. package/components/Instant/index.jsx +0 -16
  17. package/components/Link/index.js +14 -33
  18. package/components/MadieAlert/MadieAlert.stories.js +35 -29
  19. package/components/MadieAlert/index.jsx +5 -44
  20. package/components/MadieConfirmDialog/MadieConfirmDialog.stories.js +17 -32
  21. package/components/MadieConfirmDialog/index.jsx +0 -8
  22. package/components/MadieDeleteDialog/MadieDeleteDialog.stories.js +9 -24
  23. package/components/MadieDeleteDialog/index.jsx +0 -7
  24. package/components/MadieDialog/MadieDialog.stories.js +45 -121
  25. package/components/MadieDialog/index.jsx +4 -23
  26. package/components/MadieDiscardDialog/MadieDiscardDialog.stories.js +5 -12
  27. package/components/MadieDiscardDialog/index.jsx +0 -7
  28. package/components/MadieSpinner/MadieSpinner.stories.js +1 -9
  29. package/components/MadieSpinner/index.jsx +0 -5
  30. package/components/MadieTooltip/MadieTooltip.stories.js +7 -2
  31. package/components/MadieTooltip/index.jsx +0 -6
  32. package/components/MadieTooltipIcon/index.jsx +0 -5
  33. package/components/Modal/Modal.jsx +31 -43
  34. package/components/Modal/Modal.stories.js +18 -89
  35. package/components/Modal/index.jsx +6 -8
  36. package/components/NumberInput/NumberInput.stories.js +50 -67
  37. package/components/NumberInput/index.jsx +0 -13
  38. package/components/Pagination/index.jsx +0 -17
  39. package/components/Popover/Popover.stories.js +6 -14
  40. package/components/Popover/index.js +0 -23
  41. package/components/RadioButton/RadioButton.jsx +5 -15
  42. package/components/RadioButton/RadioButton.stories.jsx +6 -2
  43. package/components/ReadOnlyTextField/ReadOnlyTextField.stories.js +3 -8
  44. package/components/ReadOnlyTextField/index.jsx +1 -9
  45. package/components/RichTextEditor/RichTextEditor.stories.js +10 -8
  46. package/components/RichTextEditor/index.jsx +14 -30
  47. package/components/SanitizedContent/index.jsx +0 -8
  48. package/components/Search/Search.stories.js +2 -4
  49. package/components/Search/index.js +26 -40
  50. package/components/Select/Select.stories.js +59 -164
  51. package/components/Select/index.jsx +2 -17
  52. package/components/Tabs/Tab.js +29 -25
  53. package/components/Tabs/TabPanel.js +15 -19
  54. package/components/Tabs/Tabs.stories.js +43 -211
  55. package/components/Tabs/index.js +10 -28
  56. package/components/TextArea/TextArea.stories.js +87 -113
  57. package/components/TextArea/index.jsx +2 -14
  58. package/components/TextField/TextField.stories.js +100 -129
  59. package/components/TextField/index.jsx +2 -17
  60. package/components/TimeField/TimeField.jsx +0 -10
  61. package/components/TimeField/TimeField.stories.js +18 -8
  62. package/components/Toast/Toast.stories.js +42 -102
  63. package/components/Toast/index.jsx +0 -14
  64. package/components/TruncateText/TruncateText.stories.js +22 -17
  65. package/components/TruncateText/index.js +0 -8
  66. package/components/hooks/useGetConfig.js +2 -2
  67. package/components/{index.js → index.mjs} +37 -57
  68. package/dist/index.js +3 -1
  69. package/dist/index.js.LICENSE.txt +16 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/react/index.html +1 -1
  72. package/dist/react/index.mjs +103 -0
  73. package/dist/react/{index.js.LICENSE.txt → index.mjs.LICENSE.txt} +3 -52
  74. package/dist/react/index.mjs.map +1 -0
  75. package/dist/react/package.json +1 -0
  76. package/eslint.config.cjs +59 -0
  77. package/index.js +7 -9
  78. package/jest.config.mjs +10 -0
  79. package/lib/Chevron.jsx +2 -10
  80. package/package.json +57 -82
  81. package/styles/_main.scss +4 -3
  82. package/test/components/Accordion.test.js +1 -1
  83. package/test/components/AutoComplete.test.js +11 -6
  84. package/test/components/Button.test.js +13 -19
  85. package/test/components/DateField.test.js +25 -29
  86. package/test/components/DateTimeField.test.js +21 -25
  87. package/test/components/Instant.test.js +1 -1
  88. package/test/components/MadieAlert.test.js +22 -22
  89. package/test/components/MadieConfirmDialog.test.js +42 -64
  90. package/test/components/MadieDeleteDialog.test.js +51 -69
  91. package/test/components/MadieDialog.test.js +13 -13
  92. package/test/components/MadieDiscardDialog.test.js +28 -45
  93. package/test/components/MadieSpinner.test.js +12 -17
  94. package/test/components/Modal.test.js +115 -0
  95. package/test/components/Pagination.test.js +2 -2
  96. package/test/components/RadioButton.test.js +7 -7
  97. package/test/components/ReadOnlyTextField.test.js +4 -2
  98. package/test/components/RichTextEditor.test.js +90 -6
  99. package/test/components/Search.test.js +75 -0
  100. package/test/components/Select.test.js +97 -107
  101. package/test/components/Tabs.test.js +22 -24
  102. package/test/components/TextArea.test.js +78 -92
  103. package/test/components/TextField.test.js +128 -147
  104. package/test/components/Toast.test.js +67 -78
  105. package/test/components/TruncateText.test.js +75 -0
  106. package/test/components/index.test.js +23 -0
  107. package/webpack.config.mjs +79 -0
  108. package/webpack.config.react.mjs +72 -0
  109. package/.eslintignore +0 -5
  110. package/components/Alert/Alert.stories.js +0 -70
  111. package/components/Alert/index.js +0 -55
  112. package/components/Breadcrumb/Breadcrumb.md +0 -28
  113. package/components/Breadcrumb/Breadcrumb.stories.js +0 -76
  114. package/components/Breadcrumb/index.js +0 -92
  115. package/components/CalloutBox/CalloutBox.stories.js +0 -94
  116. package/components/CalloutBox/index.js +0 -109
  117. package/components/Card/Card.stories.js +0 -163
  118. package/components/Card/index.js +0 -144
  119. package/components/Dropdown/Dropdown.stories.js +0 -94
  120. package/components/Dropdown/index.js +0 -85
  121. package/components/Error/Collapsible.jsx +0 -93
  122. package/components/Error/ErrorUI.jsx +0 -31
  123. package/components/Error/error.js +0 -26
  124. package/components/FlashNotification/FlashNotificationUI.jsx +0 -91
  125. package/components/FlashNotification/index.js +0 -30
  126. package/components/Footer/Footer.stories.js +0 -20
  127. package/components/Footer/FooterUI.jsx +0 -137
  128. package/components/Footer/LegacyFooterUI.jsx +0 -204
  129. package/components/Footer/SocialLinks.jsx +0 -63
  130. package/components/Footer/Subscribe.jsx +0 -34
  131. package/components/Footer/footer.js +0 -30
  132. package/components/Infotip/Infotip.jsx +0 -75
  133. package/components/Infotip/Infotip.stories.js +0 -52
  134. package/components/Infotip/InfotipIcon.jsx +0 -41
  135. package/components/Infotip/index.js +0 -3
  136. package/components/Link/Link.stories.js +0 -82
  137. package/components/NotificationBanner/NotificationBanner.stories.js +0 -23
  138. package/components/NotificationBanner/index.js +0 -279
  139. package/components/Spinner/index.js +0 -9
  140. package/components/TextInput/TextInput.stories.js +0 -118
  141. package/components/TextInput/index.js +0 -137
  142. package/components/Tooltip/Tooltip.jsx +0 -88
  143. package/components/Tooltip/Tooltip.stories.js +0 -80
  144. package/components/Tooltip/index.js +0 -3
  145. package/components/Tooltip/position.js +0 -76
  146. package/components/UnwrappedSpinner/index.js +0 -8
  147. package/dist/browser.js +0 -1
  148. package/dist/react/index.js +0 -185
  149. package/dist/react/index.js.map +0 -1
  150. package/jest.config.js +0 -17
  151. package/test/components/ErrorUI.test.js +0 -32
  152. package/test/components/FooterUI.test.js +0 -122
  153. package/test/components/Infotip.test.js +0 -76
  154. package/test/components/Tooltip.test.js +0 -147
  155. package/webpack.config.js +0 -124
  156. package/webpack.config.react.js +0 -104
@@ -1,163 +0,0 @@
1
- import React from "react";
2
- import { withKnobs } from "@storybook/addon-knobs";
3
-
4
- import Card from "./index";
5
-
6
- export default {
7
- title: "Card",
8
- component: Card,
9
- decorators: [withKnobs],
10
- };
11
-
12
- export const Default = () => {
13
- return (
14
- <div className="qpp-u-padding--12 qpp-u-width--33">
15
- <Card
16
- title="Card Heading"
17
- eyebrow="Eyebrow"
18
- description="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet justo et lacus lacinia tristique. Nulla dignissim ipsum sit amet posuere interdum."
19
- cta={{
20
- text: "Call to Action",
21
- href: "#",
22
- }}
23
- />
24
- </div>
25
- );
26
- };
27
-
28
- export const CustomButton = () => (
29
- <div className="qpp-u-padding--12 qpp-u-width--33">
30
- <Card
31
- title="Card Heading"
32
- eyebrow="Eyebrow"
33
- description="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet justo et lacus lacinia tristique. Nulla dignissim ipsum sit amet posuere interdum."
34
- cta={
35
- <button
36
- className="qpp-c-button"
37
- onClick={() => console.log("I've been clicked")}
38
- style={{
39
- padding: "0.75rem 1rem",
40
- }}
41
- >
42
- Click me
43
- </button>
44
- }
45
- />
46
- </div>
47
- );
48
-
49
- export const Image = () => (
50
- <div className="qpp-u-padding--12 qpp-u-width--33">
51
- <Card
52
- title="Card Heading"
53
- description="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet justo et lacus lacinia tristique. Nulla dignissim ipsum sit amet posuere interdum."
54
- eyebrow="Eyebrow"
55
- cta={{
56
- text: "Call to Action",
57
- href: "#",
58
- }}
59
- img={{
60
- url: "https://qpp.cms.gov/images/public/images/resource-data-submission-mips.png",
61
- alt: "Card image alt",
62
- }}
63
- />
64
- </div>
65
- );
66
-
67
- export const SmallImageCard = () => (
68
- <div className="qpp-u-padding--12 wrap qpp-u-width--25">
69
- <Card
70
- title="Card Heading"
71
- eyebrow="Eyebrow"
72
- description="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet justo et lacus lacinia tristique. Nulla dignissim ipsum sit amet posuere interdum."
73
- size="small"
74
- cta={{
75
- text: "Call to Action",
76
- href: "#",
77
- }}
78
- img={{
79
- url: "https://qpp.cms.gov/images/public/images/resource-data-submission-mips.png",
80
- alt: "Card image alt",
81
- }}
82
- />
83
- </div>
84
- );
85
-
86
- export const MediumImageCard = () => (
87
- <div className="qpp-u-padding--12 wrap qpp-u-width--33">
88
- <Card
89
- title="Card Heading"
90
- eyebrow="Eyebrow"
91
- description="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet justo et lacus lacinia tristique. Nulla dignissim ipsum sit amet posuere interdum."
92
- size="medium"
93
- cta={{
94
- text: "Call to Action",
95
- href: "#",
96
- }}
97
- img={{
98
- url: "https://qpp.cms.gov/images/public/images/resource-data-submission-mips.png",
99
- alt: "Card image alt",
100
- }}
101
- />
102
- </div>
103
- );
104
-
105
- export const LargeImageCard = () => (
106
- <div className="qpp-u-padding--12 wrap qpp-u-width--100">
107
- <Card
108
- title="Card Heading"
109
- eyebrow="Eyebrow"
110
- variant="flag"
111
- description="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet justo et lacus lacinia tristique. Nulla dignissim ipsum sit amet posuere interdum."
112
- size="large"
113
- cta={{
114
- text: "Call to Action",
115
- href: "#",
116
- }}
117
- img={{
118
- url: "https://qpp.cms.gov/images/public/images/resource-data-submission-mips.png",
119
- alt: "Card image alt",
120
- }}
121
- />
122
- </div>
123
- );
124
-
125
- export const ResponsiveFlagCard = () => (
126
- <div className="qpp-u-padding--12 wrap qpp-u-width--100">
127
- <Card
128
- title="Card Heading"
129
- eyebrow="Eyebrow"
130
- responsive
131
- variant="flag"
132
- description="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet justo et lacus lacinia tristique. Nulla dignissim ipsum sit amet posuere interdum."
133
- size="large"
134
- cta={{
135
- text: "Call to Action",
136
- href: "#",
137
- }}
138
- img={{
139
- url: "https://qpp.cms.gov/images/public/images/resource-data-submission-mips.png",
140
- alt: "Card image alt",
141
- }}
142
- />
143
- </div>
144
- );
145
-
146
- export const BackgroundImageCard = () => (
147
- <div className="qpp-u-padding--12 wrap qpp-u-width--33">
148
- <Card
149
- className="qpp-c-card--medium qpp-c-card--image qpp-c-xs-card--flag qpp-c-sm-card--default qpp-u-flex--auto qpp-u-sm-flex--1"
150
- title="QPP Access User Guide"
151
- description="Download zip file"
152
- cta={{
153
- text: "Call to Action",
154
- href: "#",
155
- }}
156
- img={{
157
- url: "https://qpp.cms.gov/images/public/images/resource-pdf.png",
158
- alt: "Card image alt",
159
- useBgImage: true,
160
- }}
161
- />
162
- </div>
163
- );
@@ -1,144 +0,0 @@
1
- import React from "react";
2
- import PropTypes from "prop-types";
3
- import FeatherIcon from "feather-icons-react";
4
-
5
- const Card = ({
6
- children,
7
- className,
8
- cta,
9
- description,
10
- eyebrow,
11
- img,
12
- parentTag,
13
- responsive,
14
- routerComponent,
15
- size,
16
- title,
17
- variant,
18
- }) => {
19
- const classes = [
20
- "qppds",
21
- "qpp-c-card",
22
- size && `qpp-c-card--${size}`,
23
- img && "qpp-c-card--image",
24
- variant === "flag" && responsive && "qpp-c-xs-card--flag",
25
- variant === "flag" && !responsive && "qpp-c-card--flag",
26
- className,
27
- ]
28
- .filter(Boolean)
29
- .join(" ");
30
-
31
- const Container = parentTag || "div";
32
- const HeadingComponent = title?.headingLevel || "h3";
33
- const LinkComponent = routerComponent || "a";
34
-
35
- return (
36
- <Container className={classes}>
37
- <div className="qpp-c-card__content">
38
- <div className="qpp-c-card__header">
39
- {title && (
40
- <HeadingComponent className="h3 qpp-c-card__title">
41
- {typeof title === "object" ? title.text : title}
42
- </HeadingComponent>
43
- )}
44
- {eyebrow && (
45
- <span className="l2 qpp-c-card__eyebrow">
46
- {eyebrow}
47
- </span>
48
- )}
49
- </div>
50
- {description && (
51
- <div className="qpp-c-card__body">
52
- <p className="p1">{description}</p>
53
- </div>
54
- )}
55
- {children && <div className="qpp-c-card__body">{children}</div>}
56
- {cta && (
57
- <div className="qpp-c-card__cta">
58
- {React.isValidElement(cta) ? (
59
- cta
60
- ) : (
61
- <LinkComponent
62
- href={cta.href}
63
- className="qpp-c-button qpp-c-button--text qpp-c-button--icon-after"
64
- {...cta}
65
- >
66
- {cta.text}{" "}
67
- <FeatherIcon
68
- icon={cta.icon || "chevron-right"}
69
- />
70
- </LinkComponent>
71
- )}
72
- </div>
73
- )}
74
- </div>
75
- {img &&
76
- (() => {
77
- const { useBgImage, url, alt, ...restImg } = img;
78
- return (
79
- <div className="qpp-c-card__media">
80
- {useBgImage ? (
81
- <div
82
- role="img"
83
- style={{ backgroundImage: `url(${url})` }}
84
- aria-label={alt}
85
- {...restImg}
86
- />
87
- ) : (
88
- <img src={url} alt={alt} {...restImg} />
89
- )}
90
- </div>
91
- );
92
- })()}
93
- </Container>
94
- );
95
- };
96
-
97
- Card.propTypes = {
98
- children: PropTypes.node,
99
- className: PropTypes.string,
100
- cta: PropTypes.oneOfType([
101
- PropTypes.node,
102
- PropTypes.shape({
103
- href: PropTypes.string,
104
- text: PropTypes.string,
105
- icon: PropTypes.string,
106
- }),
107
- ]),
108
- description: PropTypes.string,
109
- eyebrow: PropTypes.string,
110
- img: PropTypes.shape({
111
- url: PropTypes.string,
112
- alt: PropTypes.string,
113
- useBgImage: PropTypes.bool,
114
- }),
115
- parentTag: PropTypes.string,
116
- responsive: PropTypes.bool,
117
- routerComponent: PropTypes.func,
118
- size: PropTypes.oneOf(["small", "medium", "large"]),
119
- title: PropTypes.oneOfType([
120
- PropTypes.string,
121
- PropTypes.shape({
122
- text: PropTypes.string,
123
- headingLevel: PropTypes.string,
124
- }),
125
- ]),
126
- variant: PropTypes.oneOf(["default", "flag"]),
127
- };
128
-
129
- Card.defaultProps = {
130
- children: null,
131
- className: null,
132
- cta: null,
133
- description: null,
134
- eyebrow: null,
135
- img: null,
136
- parentTag: null,
137
- responsive: false,
138
- routerComponent: null,
139
- size: null,
140
- title: null,
141
- variant: "default",
142
- };
143
-
144
- export default Card;
@@ -1,94 +0,0 @@
1
- import React from "react";
2
- import Dropdown from "./index";
3
- import { withKnobs } from "@storybook/addon-knobs";
4
-
5
- export default {
6
- title: "Dropdown",
7
- component: Dropdown,
8
- decorators: [withKnobs],
9
- };
10
-
11
- export const DropdownField = () => (
12
- <Dropdown
13
- id="id-example"
14
- value="value-example"
15
- name="name-example"
16
- ariaLabel="arial label example"
17
- options={[
18
- { name: "Name 1", value: "Value 1" },
19
- { name: "Name 2", value: "Value 2" },
20
- { name: "Name 3", value: "Value 3" },
21
- ]}
22
- />
23
- );
24
-
25
- export const DropdownFieldAutoWidth = () => (
26
- <Dropdown
27
- id="id-example"
28
- value="value-example"
29
- name="name-example"
30
- ariaLabel="arial label example"
31
- className="qpp-u-width--auto"
32
- options={[
33
- { name: "Name 1", value: "Value 1" },
34
- { name: "Name 2", value: "Value 2" },
35
- { name: "Name 3", value: "Value 3" },
36
- ]}
37
- />
38
- );
39
-
40
- export const DisabledDropdown = () => (
41
- <Dropdown
42
- disabled
43
- id="id-example"
44
- value="value-example"
45
- name="name-example"
46
- ariaLabel="arial label example"
47
- options={[
48
- { name: "Name 1", value: "Value 1" },
49
- { name: "Name 2", value: "Value 2" },
50
- { name: "Name 3", value: "Value 3" },
51
- ]}
52
- />
53
- );
54
-
55
- export const DropdownBigVariant = () => (
56
- <Dropdown
57
- id="id-example"
58
- value="value-example"
59
- name="name-example"
60
- ariaLabel="arial label example"
61
- size="big"
62
- options={[
63
- { name: "Name 1", value: "Value 1" },
64
- { name: "Name 2", value: "Value 2" },
65
- { name: "Name 3", value: "Value 3" },
66
- ]}
67
- />
68
- );
69
-
70
- export const DropdownWithDisabledOption = () => (
71
- <Dropdown
72
- id="id-example"
73
- value="value-example"
74
- name="name-example"
75
- ariaLabel="arial label example"
76
- options={[
77
- { disabled: true, name: "Select Category", value: "default" },
78
- { name: "Name 1", value: "Value 1" },
79
- { name: "Name 2", value: "Value 2" },
80
- ]}
81
- />
82
- );
83
-
84
- export const DropdownUsingChildrenProp = () => (
85
- <Dropdown
86
- id="id-example"
87
- value="value-example"
88
- name="name-example"
89
- ariaLabel="arial label example"
90
- >
91
- <option value="Value 1">Name 1</option>
92
- <option value="Value 2">Name 2</option>
93
- </Dropdown>
94
- );
@@ -1,85 +0,0 @@
1
- import React from "react";
2
- import PropTypes from "prop-types";
3
-
4
- const Dropdown = ({
5
- className,
6
- id,
7
- ariaLabelledBy,
8
- ariaLabel,
9
- onChange,
10
- dataTestId,
11
- name,
12
- dataType,
13
- disabled,
14
- size,
15
- options,
16
- children,
17
- parentElement,
18
- ...rest
19
- }) => {
20
- const dropdownClass = [
21
- "qpp-c-dropdown",
22
- size === "big" && "qpp-c-dropdown--big",
23
- className,
24
- ]
25
- .filter(Boolean)
26
- .join(" ");
27
-
28
- return (
29
- <select
30
- id={id}
31
- aria-labelledby={ariaLabelledBy}
32
- aria-label={ariaLabel}
33
- className={dropdownClass || ""}
34
- onChange={onChange}
35
- data-testid={dataTestId}
36
- name={name}
37
- disabled={disabled}
38
- data-type={dataType}
39
- {...rest}
40
- >
41
- {children}
42
- {options.map(({ disabled, name, value }) => (
43
- <option disabled={disabled} key={value} value={value}>
44
- {name}
45
- </option>
46
- ))}
47
- </select>
48
- );
49
- };
50
-
51
- Dropdown.propTypes = {
52
- children: PropTypes.node,
53
- className: PropTypes.string,
54
- id: PropTypes.string,
55
- ariaLabelledBy: PropTypes.string,
56
- ariaLabel: PropTypes.string,
57
- onChange: PropTypes.func,
58
- value: PropTypes.string,
59
- defaultValue: PropTypes.string,
60
- dataTestId: PropTypes.string,
61
- name: PropTypes.string,
62
- dataType: PropTypes.string,
63
- disabled: PropTypes.bool,
64
- size: PropTypes.oneOf(["big"]),
65
- options: PropTypes.array,
66
- parentElement: PropTypes.string,
67
- };
68
-
69
- Dropdown.defaultProps = {
70
- children: false,
71
- className: "qpp-u-width--100",
72
- id: null,
73
- ariaLabelledBy: null,
74
- ariaLabel: null,
75
- onChange: () => null,
76
- dataTestId: null,
77
- name: null,
78
- dataType: null,
79
- disabled: false,
80
- size: null,
81
- options: [],
82
- parentElement: "span",
83
- };
84
-
85
- export default Dropdown;
@@ -1,93 +0,0 @@
1
- import React, { Component } from "react";
2
- import PropTypes from "prop-types";
3
-
4
- class Collapsible extends Component {
5
- constructor(props) {
6
- super(props);
7
-
8
- this.state = {
9
- isExpanded: false,
10
- };
11
-
12
- this._toggleExpanded = this.toggleExpanded.bind(this);
13
- this._renderShowButton = this.renderShowButton.bind(this);
14
- this._renderHideButton = this.renderHideButton.bind(this);
15
- }
16
-
17
- toggleExpanded() {
18
- this.setState({
19
- isExpanded: !this.state.isExpanded,
20
- });
21
- }
22
-
23
- renderShowButton() {
24
- return (
25
- <span className="collapsible-show-label">
26
- {this.props.showLabel}
27
- </span>
28
- );
29
- }
30
-
31
- renderHideButton() {
32
- if (this.props.hideLabel) {
33
- return (
34
- <span className="collapsible-hide-label">
35
- {this.props.hideLabel}
36
- </span>
37
- );
38
- } else {
39
- return "";
40
- }
41
- }
42
-
43
- render() {
44
- const isArray = Array.isArray(this.props.content);
45
- const isHidden = this.state.isExpanded ? undefined : true;
46
-
47
- return (
48
- <div className="collapsible-container">
49
- <button
50
- onClick={this._toggleExpanded}
51
- className="collapsible-summary"
52
- type="button"
53
- aria-expanded={this.state.isExpanded ? true : false}
54
- >
55
- {this._renderShowButton()}
56
- {this._renderHideButton()}
57
- </button>
58
-
59
- <div className="collapsible-details" hidden={isHidden}>
60
- {isArray ? (
61
- <ul className="items">
62
- {this.props.content.map((c) => (
63
- <li key={c.contentTitle}>
64
- <p>
65
- <b>{c.contentTitle}</b>
66
- </p>
67
- <p>{c.content}</p>
68
- </li>
69
- ))}
70
- </ul>
71
- ) : (
72
- <div>
73
- <p>
74
- <b>{this.props.contentTitle}</b>
75
- </p>
76
- <p>{this.props.content}</p>
77
- </div>
78
- )}
79
- </div>
80
- </div>
81
- );
82
- }
83
- }
84
-
85
- Collapsible.propTypes = {
86
- showLabel: PropTypes.string.isRequired,
87
- hideLabel: PropTypes.string.isRequired,
88
- content: PropTypes.oneOfType([PropTypes.array, PropTypes.string])
89
- .isRequired,
90
- contentTitle: PropTypes.string,
91
- };
92
-
93
- export default Collapsible;
@@ -1,31 +0,0 @@
1
- import React from "react";
2
- import Collapsible from "./Collapsible";
3
- import PropTypes from "prop-types";
4
-
5
- const ErrorUI = (props) => {
6
- let errorTitle = `${props.type || "Error"} ${props.code || ""}`;
7
- let errorDetails = props.message;
8
-
9
- return (
10
- <section className="page-error">
11
- <div className="responsive-container">
12
- <h1>We’re sorry.</h1>
13
- <p className="h2">We cannot access this page.</p>
14
- <Collapsible
15
- showLabel="Open technical details about the error"
16
- hideLabel="Close technical details about the error"
17
- contentTitle={errorTitle}
18
- content={errorDetails}
19
- />
20
- </div>
21
- </section>
22
- );
23
- };
24
-
25
- ErrorUI.propTypes = {
26
- code: PropTypes.string,
27
- message: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
28
- type: PropTypes.string,
29
- };
30
-
31
- export default ErrorUI;
@@ -1,26 +0,0 @@
1
- import React from "react";
2
- import { render } from "react-dom";
3
- import ErrorUI from "./ErrorUI";
4
-
5
- /**
6
- * Renders the QPP Error Page content.
7
- */
8
- export default class ErrorPage {
9
- /**
10
- * @param {Object} options - An object containing content and config data
11
- * @param {String} options.type - The error type
12
- * @param {String} options.code - The error code
13
- * @param {String} options.message - The error message
14
- * @param {HTMLElement} options.rootElement - Elem inside which to render
15
- */
16
- constructor(options) {
17
- render(
18
- <ErrorUI
19
- type={options.type}
20
- code={options.code}
21
- message={options.message}
22
- />,
23
- options.rootElement
24
- );
25
- }
26
- }