├── design ├── active-states.jpg ├── mobile-design.jpg ├── desktop-design.jpg ├── desktop-preview.jpg ├── complete-state-mobile.jpg └── complete-state-desktop.jpg ├── images ├── bg-card-back.png ├── bg-card-front.png ├── favicon-32x32.png ├── bg-main-desktop.png ├── bg-main-mobile.png ├── card-logo.svg └── icon-complete.svg ├── .gitignore ├── style-guide.md ├── LICENSE ├── script.js ├── index.html ├── style.css └── README.md /design/active-states.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/design/active-states.jpg -------------------------------------------------------------------------------- /design/mobile-design.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/design/mobile-design.jpg -------------------------------------------------------------------------------- /images/bg-card-back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/images/bg-card-back.png -------------------------------------------------------------------------------- /images/bg-card-front.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/images/bg-card-front.png -------------------------------------------------------------------------------- /images/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/images/favicon-32x32.png -------------------------------------------------------------------------------- /design/desktop-design.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/design/desktop-design.jpg -------------------------------------------------------------------------------- /design/desktop-preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/design/desktop-preview.jpg -------------------------------------------------------------------------------- /images/bg-main-desktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/images/bg-main-desktop.png -------------------------------------------------------------------------------- /images/bg-main-mobile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/images/bg-main-mobile.png -------------------------------------------------------------------------------- /design/complete-state-mobile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/design/complete-state-mobile.jpg -------------------------------------------------------------------------------- /design/complete-state-desktop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/all-my-frontend-mini-projects/interactive-card-form_frontend_project/HEAD/design/complete-state-desktop.jpg -------------------------------------------------------------------------------- /images/card-logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /images/icon-complete.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Avoid accidental upload of the Sketch and Figma design files 2 | ##################################################### 3 | ## Please do not remove lines 5 and 6 - thanks! 🙂 ## 4 | ##################################################### 5 | *.sketch 6 | *.fig 7 | 8 | # Avoid accidental XD upload if you convert the design file 9 | ############################################### 10 | ## Please do not remove line 12 - thanks! 🙂 ## 11 | ############################################### 12 | *.xd 13 | 14 | # Avoid your project being littered with annoying .DS_Store files! 15 | .DS_Store 16 | .prettierignore -------------------------------------------------------------------------------- /style-guide.md: -------------------------------------------------------------------------------- 1 | # Front-end Style Guide 2 | 3 | ## Layout 4 | 5 | The designs were created to the following widths: 6 | 7 | - Mobile: 375px 8 | - Desktop: 1440px 9 | 10 | ## Colors 11 | 12 | ### Primary 13 | 14 | - Linear gradient (active input border): hsl(249, 99%, 64%) to hsl(278, 94%, 30%) 15 | - Red (input errors): hsl(0, 100%, 66%) 16 | 17 | ### Neutral 18 | 19 | - White: hsl(0, 0%, 100%) 20 | - Light grayish violet: hsl(270, 3%, 87%) 21 | - Dark grayish violet: hsl(279, 6%, 55%) 22 | - Very dark violet: hsl(278, 68%, 11%) 23 | 24 | ## Typography 25 | 26 | ### Body Copy 27 | 28 | - Font size: 18px 29 | 30 | ### Font 31 | 32 | - Family: [Space Grotesk](https://fonts.google.com/specimen/Space+Grotesk) 33 | - Weights: 500 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2024, Sarthak Sachdev 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | const cardNumberText = document.getElementById("card-number"); 2 | const holderNameText = document.getElementById("holder-name-text"); 3 | const expirationDate = document.getElementById("exp-date"); 4 | const cvcText = document.getElementById("cvc-text"); 5 | const cardForm = document.getElementById("card-form"); 6 | const holderNameInput = document.getElementById("holder-name-input"); 7 | const holderError = document.getElementById("holder-error"); 8 | const holderCardNumberInput = document.getElementById("card-number-input"); 9 | const cardNumberError = document.getElementById("number-error"); 10 | const monthInput = document.getElementById("month"); 11 | const yearInput = document.getElementById("year"); 12 | const dateError = document.getElementById("date-error"); 13 | const cvcInput = document.getElementById("cvc"); 14 | const cvcError = document.getElementById("cvc-error"); 15 | const successDialog = document.getElementById("success-dialog"); 16 | const continueBtn = document.getElementById("continue-btn"); 17 | 18 | const nameValidation = () => { 19 | let isNameValid = true; 20 | let isNumberValid = true; 21 | let isDateValid = true; 22 | let isCvcValid = true; 23 | let isFormValid; 24 | 25 | const holderName = holderNameInput.value; 26 | const cvc = cvcInput.value; 27 | const holderNumber = holderCardNumberInput.value; 28 | 29 | const nameRegex = /[0-9]+/i; 30 | const numberRegex = /[0-9]+/i; 31 | 32 | if (nameRegex.test(holderName)) { 33 | holderError.innerText = "Wrong format, text only"; 34 | isNameValid = false; 35 | } if (!holderName) { 36 | holderError.innerText = "Can't be blank"; 37 | isNameValid = false; 38 | } 39 | 40 | 41 | if (!numberRegex.test(holderNumber)) { 42 | cardNumberError.innerText = "Wrong format, numbers only"; 43 | isNumberValid = false; 44 | } 45 | if (!holderNumber) { 46 | cardNumberError.innerText = "Can't be blank"; 47 | isNumberValid = false; 48 | } 49 | 50 | if (!numberRegex.test(month.value) || !numberRegex.test(year.value)) { 51 | dateError.innerText = "Wrong format, numbers only"; 52 | } 53 | if (!month.value || !year.value) { 54 | dateError.innerText = "Can't be blank"; 55 | isDateValid = false; 56 | } 57 | 58 | if (!cvc) { 59 | cvcError.innerText = "Can't be blank"; 60 | isCvcValid = false; 61 | } 62 | 63 | if (isCvcValid && isDateValid && isNameValid && isNumberValid) { 64 | isFormValid = true; 65 | } else { 66 | isFormValid = false; 67 | } 68 | return isFormValid; 69 | } 70 | 71 | cardForm.addEventListener("submit", (e) => { 72 | e.preventDefault(); 73 | if (nameValidation()) { 74 | holderNameText.innerText = holderNameInput.value; 75 | expirationDate.innerText = `${monthInput.value}/${yearInput.value}`; 76 | cvcText.innerText = cvcInput.value; 77 | const holderCardNumber = holderCardNumberInput.value.replace(" ", "").match(/.{1,4}/g).join(" "); 78 | cardNumberText.innerText = holderCardNumber; 79 | cardForm.classList.add("hidden"); 80 | successDialog.classList.remove("hidden"); 81 | } else { 82 | alert("Please fill the form properly."); 83 | return; 84 | } 85 | }) 86 | 87 | continueBtn.addEventListener("click", () => { 88 | successDialog.classList.add("hidden"); 89 | cardForm.classList.remove("hidden"); 90 | }) 91 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 13 | 14 | Frontend Mentor | Interactive card details form 15 | 16 | 17 | 18 | 19 |
20 |
21 |
22 | card-logo 23 |

0000 0000 0000 0000

24 |
25 | Jane Appleseed 26 | 00/00 27 |
28 |
29 |
30 |
31 | 000 32 |
33 |
34 |
35 |
36 |
37 |
38 | 41 | 47 | 48 |
49 |
50 | 51 | 58 | 59 |
60 |
61 |
62 | 63 |
64 | 72 | 80 |
81 | 82 |
83 |
84 | 85 | 92 | 93 |
94 |
95 | 96 |
97 | 103 |
104 |
105 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | * { 2 | box-sizing: border-box; 3 | } 4 | 5 | :root { 6 | --white: hsl(0, 0%, 100%); 7 | --light-grayish-violet: hsl(270, 3%, 87%); 8 | --dark-grayish-violet: hsl(279, 6%, 55%); 9 | --very-dark-violet: hsl(278, 68%, 11%); 10 | --red: hsl(0, 100%, 66%); 11 | } 12 | 13 | @font-face { 14 | font-family: "Space Grotesk"; 15 | src: url("./SpaceGrotesk-VariableFont_wght.ttf") format("TrueType"); 16 | } 17 | 18 | body { 19 | font-family: "Space Grotesk"; 20 | min-height: 100vh; 21 | font-size: 18px; 22 | margin: 0; 23 | } 24 | 25 | .card-front { 26 | background: url("./images/bg-card-front.png"); 27 | top: 20%; 28 | left: 20%; 29 | z-index: 100; 30 | } 31 | 32 | .card-back { 33 | background: url("./images/bg-card-back.png"); 34 | top: 50%; 35 | left: 25%; 36 | z-index: 50; 37 | } 38 | 39 | label, 40 | input { 41 | display: block; 42 | } 43 | 44 | #confirm-btn { 45 | display: block; 46 | width: 100%; 47 | padding: 1rem 0.5rem; 48 | font-size: 18px; 49 | font-family: "Space Grotesk"; 50 | background-color: var(--very-dark-violet); 51 | color: white; 52 | border-radius: 5px; 53 | cursor: pointer; 54 | } 55 | 56 | form { 57 | width: 100%; 58 | min-width: 400px; 59 | } 60 | 61 | .flex-row { 62 | display: flex; 63 | justify-content: space-between; 64 | } 65 | 66 | .flex-row input { 67 | width: 4rem; 68 | } 69 | 70 | #date { 71 | gap: 3%; 72 | } 73 | 74 | input { 75 | padding: 0.5rem; 76 | padding-right: 0; 77 | width: 100%; 78 | font-size: 18px; 79 | font-family: "Space Grotesk"; 80 | } 81 | 82 | input:focus { 83 | border-image: linear-gradient(hsl(249, 99%, 64%), hsl(278, 94%, 30%)) 20 stretch; 84 | outline: none; 85 | } 86 | 87 | .card { 88 | background-repeat: no-repeat; 89 | padding: 1rem; 90 | min-width: 447px; 91 | min-height: 245px; 92 | border-radius: 8px; 93 | color: white; 94 | position: absolute; 95 | box-shadow: 1px 1px 3rem black; 96 | } 97 | 98 | .uppercase { 99 | text-transform: uppercase; 100 | } 101 | 102 | main { 103 | display: flex; 104 | min-width: 100%; 105 | } 106 | 107 | #form-container { 108 | display: flex; 109 | align-items: center; 110 | margin-left: 20%; 111 | width: 30%; 112 | } 113 | 114 | #card-background { 115 | background-image: url("./images/bg-main-desktop.png"); 116 | background-size: cover; 117 | min-height: 100vh; 118 | min-width: 40vw; 119 | padding-left: 15rem; 120 | } 121 | 122 | #cvc { 123 | width: 100%; 124 | display: inline-block; 125 | } 126 | 127 | #cvc-container { 128 | position: absolute; 129 | top: 45%; 130 | left: 12%; 131 | } 132 | 133 | .input-container { 134 | margin-bottom: 1rem; 135 | } 136 | 137 | .hidden { 138 | display: none; 139 | } 140 | 141 | #success-dialog { 142 | text-align: center; 143 | } 144 | 145 | #continue-btn { 146 | display: block; 147 | width: 100%; 148 | margin-top: 0.5rem; 149 | background-color: var(--very-dark-violet); 150 | padding: 0.8rem; 151 | color: white; 152 | font-size: 18px; 153 | font-family: "Space Grotesk"; 154 | border-radius: 5px; 155 | cursor: pointer; 156 | } 157 | 158 | .error { 159 | color: var(--red); 160 | } 161 | 162 | /* Footer */ 163 | .attribution { 164 | position: absolute; 165 | bottom: .8rem; 166 | left: 50%; 167 | transform: translateX(-50%); 168 | font-size: 11px; 169 | text-align: center; 170 | color: black; 171 | } 172 | 173 | .attribution a { 174 | color: hsl(228, 45%, 44%); 175 | } 176 | 177 | @media only screen and (max-width:1350px) { 178 | .card { 179 | transform: scale(0.8); 180 | } 181 | 182 | .card-front { 183 | left: 10%; 184 | } 185 | 186 | .card-back { 187 | left: 20%; 188 | } 189 | } 190 | 191 | @media only screen and (max-width:1100px) { 192 | .card { 193 | transform: scale(0.6); 194 | } 195 | 196 | .card-front { 197 | top: 20%; 198 | left: 10%; 199 | } 200 | 201 | .card-back { 202 | top: 45%; 203 | left: 15%; 204 | } 205 | 206 | #card-background { 207 | padding-left: 0; 208 | } 209 | } 210 | 211 | @media only screen and (max-width:1000px) { 212 | main { 213 | flex-direction: column; 214 | } 215 | 216 | .card-front { 217 | top: 5.3rem; 218 | left: -10%; 219 | } 220 | 221 | .card-back { 222 | top: 0rem; 223 | left: 0%; 224 | } 225 | 226 | #card-background { 227 | background-image: url("./images/bg-main-mobile.png"); 228 | padding-left: 0; 229 | min-height: 250px; 230 | } 231 | 232 | #form-container { 233 | display: block; 234 | margin-top: 3rem; 235 | margin-left: 0; 236 | } 237 | 238 | form { 239 | max-width: 100%; 240 | min-width: 90vw; 241 | } 242 | 243 | #cvc { 244 | width: 100%; 245 | } 246 | 247 | #exp-date { 248 | min-width: max-content; 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Interactive Card Details Form 2 | 3 | ## Welcome! 👋 4 | 5 | ## Table of contents 6 | 7 | - [Overview](#overview) 8 | - [The challenge](#the-challenge) 9 | - [How to setup the project](#how-to-setup-the-project) 10 | - [Screenshot](#screenshot) 11 | - [Links](#links) 12 | - [My process](#my-process) 13 | - [Built with](#built-with) 14 | - [What I learned](#what-i-learned) 15 | - [Continued development](#continued-development) 16 | - [Useful resources](#useful-resources) 17 | - [Author](#author) 18 | - [Acknowledgments](#acknowledgments) 19 | 20 | ## Overview 21 | 22 | ### The challenge 23 | 24 | The challenge is to create the Interactive Card Details Form, a beautifully designed form component of a banking website's landing page. Users should be able to- 25 | - Fill in the form and see the card details update in real-time. 26 | - Error messages are displayed if any input field is empty or if the card number, expiry date, or CVC fields are in the wrong format. 27 | - Users should also be able to view the optimal layout depending on their device's screen size and see hover, active, and focus states for interactive elements on the page. 28 | 29 | ### How to setup the project 30 | 31 | To set up the project locally, follow these steps: 32 | 33 | 1. Clone the repository using GitHub Desktop or Git Bash: 34 | ```bash 35 | git clone https://github.com/SartHak-0-Sach/interactive-card-form_frontend_project.git 36 | ``` 37 | 2. Open the project folder in your code editor. 38 | 3. Run the project using a live server extension or deploy it using Netlify, Vercel, or another web hosting and deployment service. 39 | 40 | ### Screenshot 41 | 42 | ![Design Preview](./design/active-states.jpg) 43 | 44 | ### Links 45 | 46 | - Solution URL: [GitHub Repository](https://github.com/SartHak-0-Sach/interactive-card-form_frontend_project) 47 | - Live Site URL: [Live Site](https://interactive-card-frontend-app.netlify.app/) 48 | 49 | ## My process 50 | 51 | ### Built with 52 | 53 | - HTML5 54 | - CSS3 55 | - JavaScript 56 | 57 | You will find all the required assets in the `/design` folder. The assets are already optimized. 58 | 59 | There is also a `style-guide.md` file containing the information you'll need, such as color palette and fonts. 60 | 61 | ### What I learned 62 | 63 | This project can be a great teacher to anyone trying to implement all elements as according to design files and validation using javaScript as shown below- 64 | 65 | ```js 66 | cardForm.addEventListener("submit", (e) => { 67 | e.preventDefault(); 68 | if (nameValidation()) { 69 | holderNameText.innerText = holderNameInput.value; 70 | expirationDate.innerText = `${monthInput.value}/${yearInput.value}`; 71 | cvcText.innerText = cvcInput.value; 72 | const holderCardNumber = holderCardNumberInput.value.replace(" ", "").match(/.{1,4}/g).join(" "); 73 | cardNumberText.innerText = holderCardNumber; 74 | cardForm.classList.add("hidden"); 75 | successDialog.classList.remove("hidden"); 76 | } else { 77 | alert("Please fill the form properly."); 78 | return; 79 | } 80 | }) 81 | ``` 82 | 83 | ### Continued development 84 | 85 | The continuously learning journey of a programmer never ends. This project made me realize that there are many concepts that I need to work upon including fundamentals like flex-box and its properties, to more complex concepts like working with fetch and async await in javascript. These areas are some that I think I need to work more upon in the upcoming future as they highlight some of the most significant regions of web development that are important for every developer to know of. 86 | 87 | These key points mentioned here will help me grow accountable and consistent towards improving at writing good quality code and be a successful full stack developer one day. 88 | 89 | ### Useful resources 90 | 91 | - [Harkirat Singh course notes](https://github.com/SartHak-0-Sach/harkirat-singh-course_code_and_notes) - I have added notes of all lectures along with code and lecture insights of all weeks along with bonus lectures to help you all as much as I can. 92 | - [My development code and notes](https://github.com/SartHak-0-Sach/cwh-web-dev-playlist_code_and_notes) - These are my notes that I made while working on my development skills in initial days and did these courses. Make sure to star the repository if you like it.✨💫 93 | - [MDN documentation hover state for CSS](https://developer.mozilla.org/en-US/docs/Web/CSS/:hover) - This is an amazing article which helped me finally understand hover states. I'd recommend it to anyone still learning this concept. 94 | 95 | ## Author 96 | 97 | Sarthak Sachdev 98 | - Website - [Sarthak Sachdev](https://itsmesarthak.netlify.app/) 99 | - LeetCode - [@sarthak_sachdev](https://leetcode.com/u/sarthak_sachdev/) 100 | - Twitter - [@sarthak_sach69](https://www.twitter.com/sarthak_sach69) 101 | 102 | ## Acknowledgments 103 | 104 | I feel like the solutions provided on the website and the continuous doubt solving by industry experts on discord for free is something that is unmatched by anyone else and need to be acknowledged for their efforts in improving me as a developer by suggesting the best practices in your respective tech stack. 105 | 106 | ## Got feedback for me? 107 | 108 | I love receiving feedback! I am always looking to improve my code and take up new innovative ideas to work upon. So if you have anything you'd like to mention, please email 'hi' at saarsaach30[at]gmail[dot]com. 109 | 110 | If you liked this project make sure to spread the word and share it with all your friends. 111 | 112 | **Happy coding!** ☺️🚀 113 | --------------------------------------------------------------------------------