Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RENO-3681: NewsletterSignup Component #1422

Merged
merged 43 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cde951b
NewsletterSignup as Refactored FeedbackBox
aarnold101 Sep 8, 2023
6e6b373
NewsletterSignup as exposed Form
aarnold101 Sep 8, 2023
d7427a7
React EmailSubscription as DS Component
aarnold101 Sep 8, 2023
8710deb
NewsLetterSignup add getSectionColors function, and other advances
aarnold101 Sep 14, 2023
0b2b4a9
Merge branch 'development' into RENO-3681/newslettersignup-component
aarnold101 Sep 14, 2023
735e4c7
NewsletterSignup Functional Layout
aarnold101 Sep 20, 2023
00f217b
NewsletterSignup w/o onSubmit funtionality
aarnold101 Sep 22, 2023
706bf00
NewsletterSignup Near Complete Functionality
aarnold101 Sep 22, 2023
e7952c1
NewsletterSignup Updates & Fixes
aarnold101 Sep 25, 2023
5983419
NewsletterSignup Tests Round 1
aarnold101 Sep 26, 2023
3bd8d9d
NewsletterSignup w/o 3-second Timer
aarnold101 Sep 26, 2023
ac17c39
code cleanup
nypl-wluisi Sep 26, 2023
747b451
more code cleanup
nypl-wluisi Sep 27, 2023
4b33145
NewsletterSignup Update w/ Testing
aarnold101 Sep 28, 2023
8d53b28
Merge branch 'development' into RENO-3681/newslettersignup-component
aarnold101 Sep 28, 2023
f9dc57d
NewsletterSignup Snapshot Update
aarnold101 Sep 28, 2023
bcbb3b4
NewsletterSignup Minor Updates
aarnold101 Sep 28, 2023
117de84
NewsletterSignup Snapshot Update
aarnold101 Sep 28, 2023
8c603a9
code/storybook clean up
isastettler Oct 4, 2023
39670cc
fix darkmode, update storybook
isastettler Oct 4, 2023
e10e3de
add onChange and onSubmit test
isastettler Oct 5, 2023
26be513
fix onSubmit test, fix dark mode border bug
isastettler Oct 5, 2023
f7532ca
update confirmation props, update storybook, tests and Snapshots acco…
isastettler Oct 5, 2023
fa0c034
update storybook, add privacyPolicyLink prop
isastettler Oct 6, 2023
11aafed
fix title storybook bug, updated styles
isastettler Oct 6, 2023
87cc43d
fix descriptionText bug
isastettler Oct 10, 2023
7d141cc
fix "blogs" border color, add test for html props passed
isastettler Oct 10, 2023
f6bdbe9
add NewsletterSignup to component export file
isastettler Oct 10, 2023
abbe6eb
Add working onSubmit function and update .mdx
aarnold101 Oct 10, 2023
a4460e1
Merge branch 'development' into RENO-3681/newslettersignup-component
aarnold101 Oct 10, 2023
2b15b97
add props for error message, update styling and tests, add Newsletter…
isastettler Oct 11, 2023
9b31ea7
update storybook stories, fix typo
isastettler Oct 11, 2023
650e487
add interavtive example to storybook
isastettler Oct 11, 2023
cfcab79
add actions for onChange and onSubmit
isastettler Oct 11, 2023
8e5430f
remove styling, fix typos
isastettler Oct 12, 2023
d34bcc7
update as per PR comments
isastettler Oct 12, 2023
d926063
update snapshots
isastettler Oct 12, 2023
d99e940
Merge branch 'development' into RENO-3681/newslettersignup-component
isastettler Oct 12, 2023
1e634b1
update props, comments as discussed, update test and doc accordingly
isastettler Oct 12, 2023
3a56d1f
update breakpoints, remove reduntant content
isastettler Oct 12, 2023
917feb0
update breakpoint - the one that got away
isastettler Oct 12, 2023
3f42b6a
change html tags to ds components
isastettler Oct 12, 2023
77c31d7
update Text styles, fix typo for privacyPolicyLink, update tests
isastettler Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions src/components/NewsletterSignup/NewsletterSignup.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { ArgTypes, Canvas, Description, Meta, Source } from "@storybook/blocks";

import * as NewsletterSignupStories from "./NewsletterSignup.stories";
import Link from "../Link/Link";

<Meta of={NewsletterSignupStories} />

# NewsletterSignup

| Component Version | DS Version |
| ----------------- | ------------ |
| Added | `Prerelease` |
| Latest | `Prerelease` |

## Table of Contents

- {<Link href="#overview" target="_self">Overview</Link>}
- {<Link href="#component-props" target="_self">Component Props</Link>}
- {<Link href="#accessibility" target="_self">Accessibility</Link>}

## Overview

<Description of={NewsletterSignupStories} />

## Component Props

<Canvas of={NewsletterSignupStories.WithControls} />

<ArgTypes of={NewsletterSignupStories.WithControls} />

## Accessibility

The `NewsletterSignup` component is a complex component built from various Reservoir
DS and Chakra components.

Within the `NewsletterSignup` component, the DS `form` component wraps around two DS `FormField` components.
Those`FormField` components hold a DS `TextInput` component of `type="email"` and a DS `Button` component of `type="submit"` respectively.
Each of these components has their own accessibility features documented in their respective Storybook pages.
isastettler marked this conversation as resolved.
Show resolved Hide resolved

When the form is submitted, focus is set to the confirmation message or the
error message if an error occurs.

Resources:

- [DS Form Accessibility](../?path=/docs/components-form-elements-form--docs#accessibility)
- [DS Button Accessibility](../?path=/docs/components-form-elements-button--docs#accessibility)
- [DS TextInput Accessibility](../?path=/docs/components-form-elements-textinput--docs#accessibility)

## JSX Elements passed to descriptionText Prop

Alternatively to a `descriptionText` of type `string`, a HTML Element or React component can be passed. When passing a JSX Element, the consuming app is responsible
to assure its accessibility.

_NOTE: This is applicable for all component props accepting HTML/JSX elements._

<Canvas of={NewsletterSignupStories.DescriptionUsingJSXElements} />

## Form Submission Data

Submitted form data can be retrieved when the `NewsletterSignup` component is
submitted through the required `onSubmit` prop. This prop expects a function and
it will be called when the form is submitted. Similar to other DS form-components
that have function props, the data from the component will be returned in the
function's argument. In this case, it will be a single object.

The submitted form data will be passed as an object that the parent component
can use. The returned object will always contain the "email" field.

Below is an example callback function named `onSubmit` that is passed to the
`NewsletterSignup` component's `onSubmit` prop and how the view is controlled
in the data submission process. The form data will be returned through
the function's argument as an object, called `values` in the example below.

<Source
code={`
const [view, setView] = React.useState("form");
const onSubmit = async (values) => {
e.preventDefault();
setView("submitting");
const endpoint = "...";
//Form the request for sending data to the server.
const options = {
method: "POST",
headers: {Content-Type: "application/json"},
body: JSON.stringify(values),
};
//Send the form and await response.
try {
const response = await fetch(endpoint, options);
const result = await response.json();
setView("confirmation");
} catch (error) {
setView("error");
}
};

//....

<NewsletterSignup onChange={onChange} onSubmit={onSubmit} view={view} />

`}
language="jsx"
/>

## Interactive Example with onChange and onSubmit

_NOTE: open the browser console to see the values logged in the example below._

The input value typed into the `TextInput` of the `NewsletterSignup` component can be accessed by the
functions passed to the `onChange` and `onSubmit` prop.

Both the `onChange` and `onSubmit` callback functions can retrieved the submitted value as `event.target.email.value`
through the `event` object passed as the single argument.

The following example logs the `event.target.email.value` to the console on each `onChange` call and upon
clicking the Submit button which triggers the `onSubmit` function and simulate a submission.
The component will transition through a `"submitting"` view to an alternating `"confirmation"`, `"error"` or "invalid Email" view.

<Source
code={`
function NewsletterSignupOnSubmitExampleComponent() {
const [view, setView] = React.useState("form");
const [inputVal, setInputVal] = React.useState("");
const handleChange = (event) => {
console.log(\`onChange Email Input value: \${event.target.value}\`);
setInputVal(event.target.value);
};
const handleSubmit = (event) => {
event.preventDefault();
console.log(\`onSubmit Email Input value: \${event.target.email.value}\`);
};
return (
<NewsletterSignup
id="interactive"
view={view}
isInvalidEmail={counter === 3}
valueEmail={inputVal}
onChange={handleChange}
onSubmit={handleSubmit}
confirmationHeading="Thank you for signing up!"
confirmationText="You can update your email subscription preferences at any time using the links at the bottom of the email."
/>
);
} `}
language="jsx"
/>

<Canvas of={NewsletterSignupStories.NewsletterSignupOnSubmitExample} />

## Component States

<Canvas of={NewsletterSignupStories.ComponentStates} />
Loading
Loading