-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
187 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
import { ContextualAlert } from "../ContextualAlert/ContextualAlert"; | ||
|
||
export function FormErrorSummary(props) { | ||
const { | ||
message_heading, | ||
id, | ||
alert_icon_id, | ||
alert_icon_alt_text, | ||
error_list, | ||
whiteBG, | ||
} = props; | ||
|
||
return ( | ||
<ContextualAlert | ||
id={`${id}-alert`} | ||
alert_icon_alt_text={alert_icon_id} | ||
alert_icon_id={alert_icon_alt_text} | ||
message_heading={message_heading} | ||
whiteBG={whiteBG} | ||
type="danger" | ||
message_body={[ | ||
<ol className="ds-list-decimal ds-pl-7" key="errors"> | ||
{error_list.map(({ line, id }, i) => ( | ||
<a href={`#${id}`}> | ||
<li className="ds-body" key={i}> | ||
<p className="ds-underline ds-text-multi-blue-blue70b ds-underline-offset-2 ds-decoration-1 ds-list-inside"> | ||
{line} | ||
</p> | ||
</li> | ||
</a> | ||
))} | ||
</ol>, | ||
]} | ||
/> | ||
); | ||
} | ||
|
||
FormErrorSummary.propTypes = { | ||
/** | ||
* component id | ||
*/ | ||
id: PropTypes.string.isRequired, | ||
|
||
/** | ||
* id for the alert icon | ||
*/ | ||
alert_icon_id: PropTypes.string.isRequired, | ||
|
||
/** | ||
* Alternate text for the alert icon | ||
*/ | ||
alert_icon_alt_text: PropTypes.string.isRequired, | ||
|
||
/** | ||
* heading text | ||
*/ | ||
message_heading: PropTypes.string.isRequired, | ||
|
||
/** | ||
* An array of plaintext error messages and corresponding DOM ids for anchor links | ||
*/ | ||
|
||
error_list: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string, | ||
line: PropTypes.string, | ||
}) | ||
).isRequired, | ||
/** | ||
* If true the background will be white, default is transparent. | ||
*/ | ||
whiteBG: PropTypes.bool, | ||
}; |
30 changes: 30 additions & 0 deletions
30
src/components/FormErrorSummary/FormErrorSummary.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FormErrorSummary } from "./FormErrorSummary"; | ||
export default { | ||
title: "Components/FormErrorSummary", | ||
component: FormErrorSummary, | ||
}; | ||
|
||
const Template = (args) => <FormErrorSummary {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
|
||
Default.args = { | ||
id: "formerrors", | ||
error_list: [ | ||
{ line: "Last name is required", id: "last_name" }, | ||
{ | ||
line: "Email address must be in the format of example@email.com", | ||
id: "email", | ||
}, | ||
{ line: "Password must include both numbers and letters", id: "password" }, | ||
{ | ||
line: "A valid postal code is required for your selected city", | ||
id: "postal_code", | ||
}, | ||
], | ||
message_heading: | ||
"The form could not be submitted because 4 errors were found", | ||
alert_icon_alt_text: "danger icon", | ||
alert_icon_id: "danger icon", | ||
whiteBG: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.