Skip to content
New issue

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

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

Already on GitHub? # to your account

Add newsletter form and basic button #112

Merged
merged 1 commit into from
May 17, 2018

Conversation

craigcook
Copy link
Member

This adds a newsletter subscription form molecule as it appears on the home page. We'll probably come up with a handful of variants in due time. It also adds a basic button style that we probably need to expand upon, but the form needed a button so we might as well make it an atom.

Marking this WIP initially since there should be some discussion around the button style as well as how to handle the # form functionality.

Right now this uses a slight reformulation of the basket-client.js from https://github.com/mozilla/basket-example/ but upon further thought I think we should keep the Protocol component minimal and refer people to that external repo for the subscription functionality. I'm working on that next so updates to this PR are forthcoming.

https://demo2--mozilla-protocol.netlify.com/patterns/organisms/newsletter.html
https://demo2--mozilla-protocol.netlify.com/demos/newsletter.html

@craigcook craigcook added the WIP 🚧 Work In Progress label May 15, 2018
@craigcook craigcook requested a review from alexgibson May 15, 2018 18:45
@alexgibson
Copy link
Member

Is src/static/img/placeholder.png used anywhere?

@alexgibson
Copy link
Member

alexgibson commented May 16, 2018

RTL styles are a little wonky https://screenshots.firefox.com/qShhAExCQZXpa4gN/localhost

@alexgibson
Copy link
Member

src/newsletter-image.png seems like it may be a leftover?

Copy link
Member

@alexgibson alexgibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of questions and a few nits, but otherwise looks great!

text-align: center;
}

.mzp-c-button {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be worth having as a button style atom itself, as opposed to something specific to the newsletter form?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite possibly, but I think Vince/Jennifer are still working on some button styles so I don't know if this will stick.

<p>
<label for="privacy" class="mzp-u-inline">
<input type="checkbox" id="privacy" name="privacy" required aria-required="true">
I’m okay with Mozilla handling my info as explained in <a href="#">this Privacy Notice</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we link to the actual privacy policy in the example?

</fieldset>
</form>

<div id="newsletter-thanks" class="mzp-c-newsletter-thanks">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to see these styles in the example without the form being functional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've set up the demo page to show different states of the form (normal, errors, success).

var formControls = document.querySelectorAll('.mzp-c-newsletter-form input, .mzp-c-newsletter-form select');

function emailFormShowDetails() {
if (window.getComputedStyle(formDetails).display === 'none') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than use thesegetComputedStyle calls, it may be slightly more performant to use a boolean variable to determine if the form has expanded? e.g.

if (!formExpanded) {
    formDetails.style.display = 'block';
    formExpanded = true;
}

Copy link
Member

@alexgibson alexgibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of nits, but otherwise this looks good to me. r+wc! 🗞


for (var i = 0; i < formControls.length; i++) {
formControls[i].addEventListener('focus', function() {
emailFormShowDetails();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add if (!formExpanded) { } here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The emailFormShowDetails function already checks for it, but we need to check if the form is expanded on the submit button just for the sake of e.preventDefault. I'm sure there's a more elegant way to do this... I'm not good at JavaScript.

var formControls = document.querySelectorAll('.mzp-c-newsletter-form input, .mzp-c-newsletter-form select');
var formExpanded;

if (window.getComputedStyle(formDetails).display === 'none') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is condition falsy then the value for formExpanded will be null instead of true. Maybe something like this could work?

var formExpanded = window.getComputedStyle(formDetails).display === 'none' ? false : true;

<p>With errors.</p>

<div class="mzp-qa-newsletter-errors">
<aside class="mzp-c-newsletter">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: indentation

@craigcook craigcook removed the WIP 🚧 Work In Progress label May 17, 2018
@alexgibson alexgibson merged commit 56649c3 into mozilla:master May 17, 2018
@craigcook craigcook deleted the newsletter-form branch May 17, 2018 16:35
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants