Skip to content

Commit

Permalink
Merge pull request #925 from DTS-STN/102644-new-forms-alert
Browse files Browse the repository at this point in the history
102644 new forms alert
  • Loading branch information
numbap authored Jul 19, 2023
2 parents c98c268 + 23ae09d commit 4ea0f97
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/components/ContextualAlert/ContextualAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ export function ContextualAlert(props) {
>
{asHtml ? (
<h3
className="ds-heading3"
className="ds-heading3 ds-ml-1"
dangerouslySetInnerHTML={{ __html: message_heading }}
/>
) : (
<h3 className="ds-heading3">{message_heading}</h3>
<h3 className="ds-heading3 ds-ml-1">{message_heading}</h3>
)}
{asHtml ? (
<div
className="ds-body ds-pt-[12px]"
className="ds-body ds-ml-0.5"
dangerouslySetInnerHTML={{ __html: message_body }}
/>
) : (
<div className="ds-body ds-pt-[12px]">{message_body}</div>
<div className="ds-body ds-ml-0.5">{message_body}</div>
)}
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/FormCheckBox/FormCheckBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function FormCheckBox(props) {
helpText={formLabelProps.helpText}
hasHint={hasHint}
hintProps={hintProps}
id={id}
/>
{checkBoxList.map((value, index) => {
let style = index === size - 1 ? "ds-pb-0" : "md:ds-pb-8px ds-pb-24px";
Expand Down
5 changes: 3 additions & 2 deletions src/components/FormDatePicker/FormDatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function FormDatePicker(props) {
: "ds-border-multi-neutrals-grey85a focus:ds-border-multi-blue-blue60f focus:ds-shadow-text-input";

return (
<>
<div id={id}>
{hasLabel ? (
<FormLabel
label={formLabelProps.label}
Expand All @@ -146,6 +146,7 @@ export function FormDatePicker(props) {
helpText={formLabelProps.helpText}
hasHint={hasHint}
hintProps={hintProps}
id={id}
/>
) : null}
<div id={id} className="datePicker ds-relative ds-flex ds-flex-wrap">
Expand Down Expand Up @@ -222,7 +223,7 @@ export function FormDatePicker(props) {
{hasError ? (
<FormError errorMessage={formErrorProps.errorMessage} />
) : null}
</>
</div>
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/FormError/FormError.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import errorImage from "../../assets/error.svg";
export function FormError(props) {
return (
<div
id={props.id}
id={`${props.id}-error`}
className="ds-alertWrapper ds-mt-1.5 ds-text-specific-red-red50b ds-leading-26px ds-font-medium ds-font-body ds-flex"
>
<div className="ds-block">
Expand Down
75 changes: 75 additions & 0 deletions src/components/FormErrorSummary/FormErrorSummary.js
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 src/components/FormErrorSummary/FormErrorSummary.stories.js
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,
};
1 change: 1 addition & 0 deletions src/components/FormLabel/FormLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function FormLabel(props) {
<label
className={`ds-flex ds-text-multi-neutrals-grey100 ds-items-center ds-leading-24px ds-text-xl lg:ds-text-p ds-font-body ds-relative`}
htmlFor={props.id}
id={`${props.id}-label`}
>
<span className="ds-inline ds-text-form-input-gray lg:ds-text-xl ds-font-bold ds-flex ds-items-center">
<p className={props.noneBoldLabel ? "ds-font-normal" : ""}>
Expand Down
6 changes: 3 additions & 3 deletions src/components/FormMultiTextField/FormMultiTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export function FormMultiTextField(props) {
? "ds-border-specific-red-red50b"
: "ds-border-multi-neutrals-grey85a focus:ds-border-multi-blue-blue60f focus-visible:ds-border-multi-blue-blue60f";
return (
<div className={`block leading-tight mb-12`}>
<div className={`block leading-tight mb-12`} id={props.id}>
{props.label && (
<FormLabel
id={props.id}
id={`${props.id}-textarea`}
label={props.label}
required={props.required}
requiredText={props.requiredText}
Expand All @@ -53,7 +53,7 @@ export function FormMultiTextField(props) {
)}
<textarea
className={`ds-min-h-76px ds-resize-none ${sizeOfField} ${props.className} ds-text-input ds-leading-33px ds-rounded ds-outline-0 ds-text-mobileh5 ds-text-multi-neutrals-grey100 ds-text-form-input-gray ds-border ds-py-5px ds-px-14px ${validationClass}`}
id={props.id}
id={`${props.id}-textarea`}
name={props.name}
placeholder={props.placeholder}
onChange={onChange}
Expand Down
4 changes: 2 additions & 2 deletions src/components/FormRadioButton/FormRadioButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function FormRadioButton(props) {
? "ds-border-specific-red-red50b focus:ds-border-multi-blue-blue60f focus:ds-shadow-text-input"
: "ds-border-multi-neutrals-grey85a focus:ds-border-multi-blue-blue60f focus:ds-shadow-text-input";
return (
<>
<div id={props.id}>
{props.label && (
<FormLabel
id={props.id}
Expand Down Expand Up @@ -73,7 +73,7 @@ export function FormRadioButton(props) {
)
)}
{props.hasError && <FormError errorMessage={props.errorText} />}
</>
</div>
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/FormTextField/FormTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export function FormTextField(props) {
};

return (
<div className={`ds-block ds-leading-tight ds-mb-10px`}>
<div className={`ds-block ds-leading-tight ds-mb-10px`} id={props.id}>
{props.label && (
<FormLabel
id={props.id}
id={`${props.id}-textarea`}
label={props.label}
required={props.required}
requiredText={props.requiredText}
Expand All @@ -75,7 +75,7 @@ export function FormTextField(props) {
<input
className={classname}
maxLength={maxLength}
id={props.id}
id={`${props.id}-textarea`}
aria-describedby={props.describedBy}
name={props.name}
placeholder={props.placeholder}
Expand Down
7 changes: 7 additions & 0 deletions src/components/FormTextField/FormTextField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ describe("FormTextField", () => {
// expect(inputElem.value).toBe("h");
});

// it("renders text field with with Error", () => {
// render(<RequiredWithError {...RequiredWithError.args} />);
// expect(screen.getByText(RequiredWithError.args.label).classList).toContain(
// "ds-text-form-input-gray"
// );
// });

it("has no accessibility violations", async () => {
const { container } = render(<Primary {...Primary.args} />);
const results = await axe(container);
Expand Down
1 change: 1 addition & 0 deletions src/components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export function Header(props) {

Header.defaultProps = {
lang: "en",
id: Math.random(),
isAuthenticated: true,
useParentContainer: false,
searchProps: {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export { FormTextField } from "./components/FormTextField/FormTextField";
export { FormError } from "./components/FormError/FormError";
export { FormLabel } from "./components/FormLabel/FormLabel";
export { AccordionForm } from "./components/AccordionForm/AccordionForm";
export { FormAlertMessage } from "./components/FormAlertMessage/FormAlertMessage";
export { FormRadioButton } from "./components/FormRadioButton/FormRadioButton";
export { FormCheckBox } from "./components/FormCheckBox/FormCheckBox";
export { FormMultiTextField } from "./components/FormMultiTextField/FormMultiTextField";
Expand Down

0 comments on commit 4ea0f97

Please sign in to comment.