Skip to content
Open

Pro1 #31

Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added .DS_Store
Binary file not shown.
123 changes: 123 additions & 0 deletions newsletter-sign-up-with-success-message-main/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
body {
height: 100vh;
margin: 0;
padding: 0;
background-color: #2c2e47;
Copy link
Member

Choose a reason for hiding this comment

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

colors should come from css vairables

font-family: Arial, sans-serif;
}

.maincontainer {
margin-top: 32%;
Copy link
Member

Choose a reason for hiding this comment

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

Will this be responsive?

height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.center {
padding: 20px;
width: 750px;
background: white;
border-radius: 20px;
display: flex;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
Copy link
Member

Choose a reason for hiding this comment

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

Same comment about the color in here and in every other place

overflow: hidden;
margin-bottom: 20px;
}

#successCard {
display: none;
flex-direction: column;
align-items: center;
justify-content: center;
width: 381px;
}

.text {
flex: 1;
padding: 40px;
}

.text h1 {
Copy link
Member

Choose a reason for hiding this comment

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

You could give the h1 class making it more specific

margin-top: 0;
font-size: 32px;
font-weight: 700;
}

.text p {
color: #555;
margin-bottom: 15px;
}

.text ul {
list-style: none;
padding: 0;
margin-bottom: 30px;
}

.text ul li {
margin-bottom: 10px;
display: flex;
align-items: center;
gap: 10px;
}

.text label {
font-size: 12px;
font-weight: bold;
display: block;
margin-bottom: 6px;
}

.text input {
width: 100%;
padding: 12px;
margin-bottom: 20px;
border-radius: 6px;
border: 1px solid #ccc;
font-size: 14px;
}

#subscribeBtn {
width: 110%;
Copy link
Member

Choose a reason for hiding this comment

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

Can you use class instead? id will override all of the other css rules made by class.
Also, why do you need this element to be larger than his parent?

padding: 14px;
border-radius: 6px;
border: none;
background-color: #1d223a;
color: white;
font-size: 14px;
cursor: pointer;
font-weight: bold;
transition: 0.3s ease;
}

#subscribeBtn.valid {
background: linear-gradient(to right, #ff6f91, #ff9671);
}

#dismissBtn:hover {
opacity: 0.9;
}

#errorMsg {
display: none;
color: red;
font-size: 9px;
margin-bottom: 5px;
text-align: right;
margin-right: -23px;
}

#dismissBtn {
width: 110%;
padding: 14px;
border-radius: 6px;
border: none;
background-color: #1d223a;
color: white;
font-size: 14px;
cursor: pointer;
font-weight: bold;
margin-top: 20px;
}
71 changes: 40 additions & 31 deletions newsletter-sign-up-with-success-message-main/index.html
Original file line number Diff line number Diff line change
@@ -1,52 +1,61 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device -->

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" sizes="32x32" href="./assets/images/favicon-32x32.png">

<title>Frontend Mentor | Newsletter sign-up form with success message</title>

<!-- Feel free to remove these styles or customise in your own stylesheet 👍 -->
<style>
.attribution { font-size: 11px; text-align: center; }
.attribution a { color: hsl(228, 45%, 44%); }
</style>
<link rel="stylesheet" href="index.css">
<title>Newsletter Sign-up</title>
</head>

<body>

<!-- Sign-up form start -->
<div class="maincontainer">
Copy link
Member

Choose a reason for hiding this comment

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

You could use the main tag


Stay updated!
<div id="formCard" class="center">
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need both id and class?
Also if this element represent the form use form tag


Join 60,000+ product managers receiving monthly updates on:
<div class="text">
<h1>Stay updated!</h1>
<p>Join 60,000+ product managers receiving monthly updates on:</p>

Product discovery and building what matters
Measuring to ensure updates are a success
And much more!
<ul>
<li><img src="./assets/images/icon-list.svg" class="list-icon"> Product discovery and building what matters</li>
Copy link
Member

Choose a reason for hiding this comment

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

You should add alt attribute for accessibility

<li><img src="./assets/images/icon-list.svg" class="list-icon"> Measuring to ensure updates are a success</li>
<li><img src="./assets/images/icon-list.svg" class="list-icon"> And much more!</li>
</ul>

Email address
email@company.com
<label>Email address</label>
<p id="errorMsg">Valid email required</p>
<input id="emailInput" type="email" placeholder="email@company.com">

Subscribe to monthly newsletter
<button id="subscribeBtn">Subscribe to monthly newsletter</button>
</div>

<!-- Sign-up form end -->
<div class="imager">
<img src="./assets/images/illustration-sign-up-desktop.svg" alt="Sign Up Illustration">
Copy link
Member

Choose a reason for hiding this comment

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

This is good usage of alt

</div>

<!-- Success message start -->
</div>

Thanks for subscribing!
<div id="successCard" class="center">
<div class="success-content">
<img src="./assets/images/icon-success.svg" class="success-icon" alt="">

A confirmation email has been sent to ash@loremcompany.com.
Please open it and click the button inside to confirm your subscription.
<h1>Thanks for subscribing!</h1>

Dismiss message
<p>
A confirmation email has been sent.
Please open it and click the button inside to confirm your subscription.
</p>

<button id="dismissBtn">Dismiss message</button>
</div>
</div>

<!-- Success message end -->

<div class="attribution">
Challenge by <a href="https://www.frontendmentor.io?ref=challenge" target="_blank">Frontend Mentor</a>.
Coded by <a href="#">Your Name Here</a>.
</div>

<script src="index.js"></script>
</body>
</html>

</html>
50 changes: 50 additions & 0 deletions newsletter-sign-up-with-success-message-main/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const input = document.getElementById("emailInput");
const error = document.getElementById("errorMsg");
const btn = document.getElementById("subscribeBtn");
const formCard = document.querySelector("#formCard");
const successCard = document.querySelector("#successCard");

input.addEventListener("input", function () {
const email = input.value;

if (!email.includes("@")) {
btn.classList.remove("valid");
return;
}

const [, domain] = email.split("@");
Copy link
Member

Choose a reason for hiding this comment

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

What are you doing in here? how is this syntax called? and why are you doing it only to access the second array elemnt?

You could access the array that split is returning arr[1]


if (domain === "gmail.com" || domain === "colman.com") {
Copy link
Member

Choose a reason for hiding this comment

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

Hardcoded strings should be saved inside constants

btn.classList.add("valid");
} else {
Copy link
Member

Choose a reason for hiding this comment

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

You could add return here to avoid the else

btn.classList.remove("valid");
}
});

btn.onclick = function () {
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to do it like this? you are already using even listeners, dont override the default on click function

const email = input.value;

if (!email.includes("@")) {
error.style.display = "block";
Copy link
Member

Choose a reason for hiding this comment

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

Never style stuff from your js, use it via classes and css

return;
}

const parts = email.split("@");
const domain = parts[1];

if (domain !== "gmail.com" && domain !== "colman.com") {
error.style.display = "block";
return;
}

error.style.display = "none";
formCard.style.display = "none";
successCard.style.display = "flex";
};

const dismissBtn = document.getElementById("dismissBtn");
Copy link
Member

Choose a reason for hiding this comment

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

You should place all of your elements on the top of the file


dismissBtn.onclick = function () {
successCard.style.display = "none";
formCard.style.display = "flex";
};