Sloth247 / e-commerce-product-website

A frontend part of e-commerce website with React.js and Splide.js for slider

Home Page:https://e-commerce-product-website.vercel.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Frontend Mentor - E-commerce product page solution

This is a solution to the E-commerce product page challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Note: Delete this note and update the table of contents based on what sections you keep.

Overview

The challenge

Users should be able to:

  • View the optimal layout for the site depending on their device's screen size
  • See hover states for all interactive elements on the page
  • Open a lightbox gallery by clicking on the large product image
  • Switch the large product image by clicking on the small thumbnail images
  • Add items to the cart
  • View the cart and remove items from it

Screenshot

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox
  • CSS Grid
  • Sass/Scss
  • Mobile-first workflow
  • TypeScript
  • React - JS library
  • Splide.js - slider library

What I learned

I made svgs accessible by the following code;

export default function PlusIcon() {
  return (
    <svg
      width="12"
      height="12"
      xmlns="http://www.w3.org/2000/svg"
      xmlnsXlink="http://www.w3.org/1999/xlink"
      aria-labelledby="plus"
    >
      <title id="plus">Plus</title>
      <defs>
        <path
          d="M12 7.023V4.977a.641.641 0 0 0-.643-.643h-3.69V.643A.641.641 0 0 0 7.022 0H4.977a.641.641 0 0 0-.643.643v3.69H.643A.641.641 0 0 0 0 4.978v2.046c0 .356.287.643.643.643h3.69v3.691c0 .356.288.643.644.643h2.046a.641.641 0 0 0 .643-.643v-3.69h3.691A.641.641 0 0 0 12 7.022Z"
          id="b"
        />
      </defs>
      <use fill="#FF7E1B" fillRule="nonzero" xlinkHref="#b" />
    </svg>
  );
}

min attribute on input did not work in Content.tsx, so I used function handleInput to disable minus button and prevent the input amount from becoming minus value when the amount is less than 1.

const handleInput = () => {
  if (amount < 1) {
    setAmount(0);
  } else {
    setAmount(amount - 1);
  }
};
<input
  type="number"
  name="amount"
  id="amount"
  value={amount}
  min="0"
  onChange={(e) => setAmount(Number(e.target.value))}
/>

I also learnt methods on splide.js. I used go() to change slide by clicking thumbnails and sync() to syncronize the slide on main page and on modal.

Continued development

To achieve high level of accessibility, I used splide.js, however it ended up with so many errors pointed out by Deque University. I know achieving a good accessibility for slider is hard, but I want to try other frameworks or suggest not to use slider as much as possible.

This project is only frontend part of the website, following the task given by frontend mentor. I would like to try similar website as full-stack app and elavorate to bigger website.

I used prop drilling, so my code got a little messy but I can keep track what I was doing. I can use context or redux next time.

Useful resources

Author

About

A frontend part of e-commerce website with React.js and Splide.js for slider

https://e-commerce-product-website.vercel.app/


Languages

Language:SCSS 50.0%Language:TypeScript 44.5%Language:HTML 5.5%