Not Signed In - NSC
by Richard Hunter
HTML
<form novalidate name="form" class="container">
<img src="" />
<div class="content">
<div class="row1">
<h1 class="desktop">
[%% heading %%] {{hello}}
</h1>
<h1 class="mobile">
[%% mobileHeading %%]
</h1>
<svg id="Layer_1" width="30" height="30" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 991.43 991.43">
<defs>
</defs>
<title>Independent</title>
<path fill="#e30d24" class="cls-1" d="M500,4.28C226.23,4.28,4.28,226.23,4.28,500S226.23,995.71,500,995.71,995.71,773.78,995.71,500,773.78,4.28,500,4.28" transform="translate(-4.28 -4.28)"></path>
<path fill="#fff" class="cls-2"...
CSS
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
@font-face {
font-family: "Independent Serif";
src: url("https://assets.independent.co.uk/fonts/Independent-Serif-Bold.woff2") format("woff2"),
url("https://assets.independent.co.uk/fonts/Independent-Serif-Bold.woff") format("woff");
font-weight: bold;
font-style: normal;
}
/* Independent Sans */
@font-face {
font-family: "Independent Sans Regular";
src: url("https://assets.independent.co.uk/fonts/Independent-Sans-Regular.woff2") format("woff2"),
url("https://assets.independent.co.uk/fonts/Independent-Sans-Regular.woff") format("woff");
font-weight: 400;
font-style: normal;
}
.container {
border: solid 1px #d3d3d3;
background-color: #fff;
display: flex;
flex-direction: row;
}
.content {
font-family: Independent Sans Regular;
}
h1 {
color: #222;
font-family: "Independent Serif";
margin: 0;
margin-right: 8px;
}
.row1,
.row2 {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}
.row1 {
align-items: flex-start;
}
input[type=text] {
flex-grow: 3;
width: 100%;
height: 38px;
border-radius: 4px;
border: solid 1px #bdbdbd;
padding-left: 12px;
padding-right: 12px;
color: #4e4e4e;
outline: none;
}
input[type=text]:focus {
outline: none;
border-color: #276fbf;
}
input[type=text].touched.ng-dirty.ng-invalid {
border-color: #a20021;
}
input[type=text]:focus.ng-dirty.touched.ng-valid {
border-color: #157f1f;
}
svg {
flex-shrink: 0;
display: block;
}
/* what is correct font family? */
button {
flex-shrink: 0;
background: #ec1a2e;
font-family: "Independent Sans", sans-serif;
color: #fff;
background: #ec1a2e;
border-radius: 6px;
font-weight: bold;
border: none;
appearance: none;
cursor: pointer;
text-transform: uppercase;
font-size: 13px;
line-height: 20px;
margin-left: 16px;
transition: all 0.4 linear;
}
button:hover {
background: #a51220;
}
button:disabled {
...
JavaScript
/* Angular 1.2 doesn't support touched and untouched states so we have to do this ourselves */
function validateEmail() {
const EMAIL_REGEX = /^(?=(.{1,64}@.{1,255}))([!#$%&'*+\-\/=?\^_`{|}~a-zA-Z0-9}]{1,64}(\.[!#$%&'*+\-\/=?\^_`{|}~a-zA-Z0-9]{0,}){0,})@((\[(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}\])|([a-zA-Z0-9-]{1,63}(\.[a-zA-Z0-9-]{2,63}){1,}))$/;
return EMAIL_REGEX.test(email);
}
const formState = {
inputField: {
dirty: false,
touched: false,
valid: false,
},
};
const emailInput = document.getElementById('email-input');
function updateView() {
if (formState.inputField.dirty) {
emailInput.classList.add('dirty');
} else {
emailInput.classList.remove('dirty');
}
if (formState.inputField.valid) {
emailInput.classList.remove('invalid');
} else {
emailInput.classList.add('invalid');
}
}
emailInput.addEventListener('blur', () => {
formState.inputField.touched = true;
updateView();
});
emailInput.addEventListener('change', () => {
formState.inputField.dirty = true;
updateView();
});
emailInput.addEventListener('input', () => {
formState.inputfield.valid = validateEmail(event.target.value);
updateView();
});