8.bodypart card / category

.import React from "react";

import { Stack, Typography } from "@mui/material";

import Icon from "../../assets/icons/gym.png";

const BodyPart = ({ item, bodyPart, setBodyPart }) => {
  return (
    <Stack
      type="button"
      alignItems="center"
      justifyContent="center"
      spacing={4.7}
      className="bodyPart-card"
      sx={{
        borderTop: bodyPart === item ? "4px solid #ff2625" : "",
        backgroundColor: "#fff",
        borderBottomLeftRadius: "20px",
        width: "270px",
        height: "280px",
        cursor: "pointer",
        boxShadow: "0 0 25px rgba(0,0,0,0.2)",
      }}
      onClick={() => {
        setBodyPart(item);
        window.scrollTo({ top: 1800, left: 100, behavior: "smooth" });
      }}
    >
      <img
        src={Icon}
        alt="dumbBell"
        style={{ width: "40px", height: "40px" }}
      />
      <Typography
        fontSize="24px"
        fontWeight="bold"
        color="#3a1212"
        textTransform="capitalize"
      >
        {item}
      </Typography>
    </Stack>
  );
};

export default BodyPart;

.our bodyparts=[all,...fetched_bodyparts]

so data passed as prop ie, data= bodyparts

item= mapped ie each item of data

and state bodypart is set to 'all' initially so ,

at ist map item = bodypart = 'all'

so, .borderTop: bodyPart === item ? "4px solid #ff2625" : "",.will make red border at top of first item/bodypart/category card

..   onClick={() => {

        setBodyPart(item);
        window.scrollTo({ top: 1800, left: 100, behavior: "smooth" });
      }}

This part will set bodypart = item clicked eg if waist card is clicked then

bodypart = waist so now waist card will hap border top of red color.

window.scrollTo({ top: 1800, left: 100, behavior: "smooth" } this line will scroll down

the page when clicked on card.

.

.

.

.

 

Comments

Popular posts from this blog

5. Create SearchExercise Section

9.exerxise card

7. Horizontal Scroll bar