[TIL/React] 2023/08/23

์›๋ฏผ๊ด€ยท2023๋…„ 8์›” 23์ผ

[TIL]

๋ชฉ๋ก ๋ณด๊ธฐ
102/213

src/pages/EventPage.js ๐ŸŸก

import React, { useState } from "react";
import styled from "styled-components";
import { events } from "../data/EventList";

const CardContainer = styled.div`
  display: flex;
  overflow-x: scroll;
  width: 100%;
  height: 200px;
  cursor: grab;
  background-color: #424242;
`;

const Card = styled.div`
  height: 100%;
  margin: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  transition: transform 0.3s ease;

  &:hover {
    transform: scale(1.1);
    cursor: pointer;
  }
`;

const EventCardWrapper = styled.div``;

const EventCardImg = styled.img`
  width: 400px;
  height: 400px;
`;

const EventPage = () => {
  const [isMousePressed, setIsMousePressed] = useState(false);
  const [containerScrollLeft, setContainerScrollLeft] = useState(0);
  const [startMouseX, setStartMouseX] = useState(0);

  const handleMousePress = (e) => {
    setIsMousePressed(true);
    setStartMouseX(e.pageX - e.currentTarget.offsetLeft);
    setContainerScrollLeft(e.currentTarget.scrollLeft);
    console.log(e.currentTarget.scrollLeft);
  };

  const handleMouseMove = (e) => {
    if (!isMousePressed) return;
    const currentMouseX = e.pageX - e.currentTarget.offsetLeft;
    e.currentTarget.scrollLeft =
      containerScrollLeft - (currentMouseX - startMouseX);
  };

  const handleMouseRelease = () => setIsMousePressed(false);

  return (
    <CardContainer
      style={{ height: "1000px" }}
      onMouseDown={handleMousePress}
      onMouseMove={handleMouseMove}
      onMouseUp={handleMouseRelease}
      onMouseLeave={handleMouseRelease}
    >
      {events?.map((event) => (
        <Card key={event.id}>
          <EventCardWrapper>
            <EventCardImg src={event.image} alt={event.title} />
            <h3
              style={{
                color: "rgb(255, 255, 255)",
                fontWeight: "bolder",
                textAlign: "center",
              }}
            >
              {event.title}
            </h3>
            <p
              style={{
                color: "rgb(155, 155, 155)",
                fontWeight: "bolder",
                textAlign: "center",
              }}
            >
              {event.subtitle}
            </p>
          </EventCardWrapper>
        </Card>
      ))}
    </CardContainer>
  );
};

export default EventPage;

src/data/EventList.js ๐ŸŸก

import { eventImg } from "../images";

export const events = [
  {
    id: "1",
    image: eventImg.eventImg1,
    title: "2023 ์—ฌ๋ฆ„ ์„ ๋ฌผ์„ธํŠธ",
    subtitle:
      "์–ผ๋ฆฌ๋ฒ„๋“œ ๊ธฐ๊ฐ„, ์ตœ๋Œ€ 7% ํ• ์ธ๋œ ๊ฐ€๊ฒฉ์œผ๋กœ ์ดˆ์‹ ์„ ํ•œ ๊ฐ์‚ฌ์˜ ๋งˆ์Œ์„ ์ „ํ•˜์„ธ์š”!",
  },
  {
    id: "2",
    image: eventImg.eventImg2,
    title: "ํ‘ธ์งํ•œ ๋ฐ”๋ฒ ํ ํŒŒํ‹ฐ ์ด๋ฒคํŠธ",
    subtitle: "์ตœ๋Œ€ 15,000์› ํ• ์ธ๋ฐ›๊ณ  ํ‘ธ์งํ•œ ๋ฐ”๋ฒ ํ ํŒŒํ‹ฐ๋ฅผ ์ค€๋น„ํ•˜์„ธ์š”!",
  },
  {
    id: "3",
    image: eventImg.eventImg3,
    title: "์นœ๊ตฌ ์ดˆ๋Œ€ ์ด๋ฒคํŠธ",
    subtitle: "์ฆ๊ฑฐ์šด ์ผ์ƒ์˜ ๋ณ€ํ™” '์ดˆ์‹ ์„ '์„ ์†Œ์ค‘ํ•œ ์‚ฌ๋žŒ์—๊ฒŒ ์•Œ๋ ค์ฃผ์„ธ์š”!",
  },
  {
    id: "4",
    image: eventImg.eventImg4,
    title: "์•ฑ ์„ค์น˜ ์ด๋ฒคํŠธ",
    subtitle: "์ •์œก๊ฐ ์•ฑ ์„ค์น˜ํ•˜๊ณ  ์ดˆ์‹ ์„ ํ•œ ์ผ์ƒ์„ ๋ˆ„๋ ค๋ณด์„ธ์š”!",
  },
  {
    id: "5",
    image: eventImg.eventImg5,
    title: "์ƒํ’ˆ ๋ฆฌ๋ทฐ ํ˜œํƒ",
    subtitle: "๋งŒ์กฑํ•˜์‹  ๋งˆ์Œ์„ ๋‹ด์•„ ์ƒํ’ˆ ๋ฆฌ๋ทฐ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.",
  },
  {
    id: "6",
    image: eventImg.eventImg6,
    title: "์‹ ์„ ํ”Œ๋žœ ๋ฐฐ์†ก ํ˜œํƒ",
    subtitle: "ํ•œ ๋ฒˆ ๋ฐฐ์†ก๋น„๋กœ 4ํšŒ ๋ฌด๋ฃŒ๋ฐฐ์†ก",
  },
  {
    id: "7",
    image: eventImg.eventImg1,
    title: "2023 ์—ฌ๋ฆ„ ์„ ๋ฌผ์„ธํŠธ",
    subtitle:
      "์–ผ๋ฆฌ๋ฒ„๋“œ ๊ธฐ๊ฐ„, ์ตœ๋Œ€ 7% ํ• ์ธ๋œ ๊ฐ€๊ฒฉ์œผ๋กœ ์ดˆ์‹ ์„ ํ•œ ๊ฐ์‚ฌ์˜ ๋งˆ์Œ์„ ์ „ํ•˜์„ธ์š”!",
  },
  {
    id: "8",
    image: eventImg.eventImg2,
    title: "ํ‘ธ์งํ•œ ๋ฐ”๋ฒ ํ ํŒŒํ‹ฐ ์ด๋ฒคํŠธ",
    subtitle: "์ตœ๋Œ€ 15,000์› ํ• ์ธ๋ฐ›๊ณ  ํ‘ธ์งํ•œ ๋ฐ”๋ฒ ํ ํŒŒํ‹ฐ๋ฅผ ์ค€๋น„ํ•˜์„ธ์š”!",
  },
  {
    id: "9",
    image: eventImg.eventImg3,
    title: "์นœ๊ตฌ ์ดˆ๋Œ€ ์ด๋ฒคํŠธ",
    subtitle: "์ฆ๊ฑฐ์šด ์ผ์ƒ์˜ ๋ณ€ํ™” '์ดˆ์‹ ์„ '์„ ์†Œ์ค‘ํ•œ ์‚ฌ๋žŒ์—๊ฒŒ ์•Œ๋ ค์ฃผ์„ธ์š”!",
  },
  {
    id: "10",
    image: eventImg.eventImg4,
    title: "์•ฑ ์„ค์น˜ ์ด๋ฒคํŠธ",
    subtitle: "์ •์œก๊ฐ ์•ฑ ์„ค์น˜ํ•˜๊ณ  ์ดˆ์‹ ์„ ํ•œ ์ผ์ƒ์„ ๋ˆ„๋ ค๋ณด์„ธ์š”!",
  },
  {
    id: "11",
    image: eventImg.eventImg5,
    title: "์ƒํ’ˆ ๋ฆฌ๋ทฐ ํ˜œํƒ",
    subtitle: "๋งŒ์กฑํ•˜์‹  ๋งˆ์Œ์„ ๋‹ด์•„ ์ƒํ’ˆ ๋ฆฌ๋ทฐ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.",
  },
  {
    id: "12",
    image: eventImg.eventImg6,
    title: "์‹ ์„ ํ”Œ๋žœ ๋ฐฐ์†ก ํ˜œํƒ",
    subtitle: "ํ•œ ๋ฒˆ ๋ฐฐ์†ก๋น„๋กœ 4ํšŒ ๋ฌด๋ฃŒ๋ฐฐ์†ก",
  },
];

src/images/index.js ๐ŸŸก

import logo from "./logo.jpeg";
import backgroundImg from "./background.png";
import termsImg from "./terms.jpeg";
import porkImg from "./porkbelly-fresh-list.png";
import chickenImg from "./chickef-cut-list.png";
import porkcutletImg from "./porkcutlet-sirloin-list.png";
import eggImg from "./egg-fresh-list.png";
import milkImg from "./milk-fresh-list.png";
import hanuroundImg from "./baby-hanuround-bmix-list.png";
import carthegardenImg from "./carthegarden.jpeg";
import eventImg1 from "./eventImg1.png";
import eventImg2 from "./eventImg2.png";
import eventImg3 from "./eventImg3.png";
import eventImg4 from "./eventImg4.png";
import eventImg5 from "./eventImg5.png";
import eventImg6 from "./eventImg6.png";

const eventImg = {
  eventImg1,
  eventImg2,
  eventImg3,
  eventImg4,
  eventImg5,
  eventImg6,
};

export {
  logo,
  backgroundImg,
  termsImg,
  porkImg,
  chickenImg,
  porkcutletImg,
  eggImg,
  milkImg,
  hanuroundImg,
  carthegardenImg,
  eventImg,
};

ํ˜„์žฌ ๋ชจ์Šต ๐ŸŸก

hover๋˜๋ฉด ์•ฝ๊ฐ„ ์ปค์ง„๋‹ค.

ํšŒ๊ณ  ๐ŸŸข

'์ด์ƒ๋„ ์ดํ•˜๋„ ์•„๋‹ˆ๋‹ค'๋ผ๋Š” ํ‘œํ˜„์€ ๊ณผ๋Œ€ํ‰๊ฐ€์™€ ๊ณผ์†Œํ‰๊ฐ€๋ฅผ ๋ง‰์œผ๋ ค๋Š” ์˜๋„๋กœ ์ž์ฃผ ์‚ฌ์šฉํ•œ๋‹ค. '์ด์ ์˜ ๋‹จ์–ด๋“ค'์ด๋ผ๋Š” ์ฑ…์—์„œ๋Š” ํ•ด๋‹น ํ‘œํ˜„์ด, ์‹ค์ƒ ์•„๋ฌด๊ฒƒ๋„ ๋งํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋Œ€๋ถ€๋ถ„์ด๋ผ, ๋ฉ€์ฉกํ•œ ๋ฌธ์žฅ์— ์ƒํˆฌ์ ์œผ๋กœ ๋ฌด์˜๋ฏธํ•œ ๋‹จ์–ด๋“ค์„ ๋ง๋ถ™์ด๋Š” ๋ฏผ๋ง์Šค๋Ÿฌ์šด ๋ง์žฅ๋‚œ์ด๋ผ๊ณ  ์„œ์ˆ ํ•œ๋‹ค.

์šฐ๋ฆฌ๋Š” '์ด์ƒ๋„ ์ดํ•˜๋„ ์•„๋‹ˆ๋‹ค'๋ผ๋Š” ํ‘œํ˜„์„ ์‚ฌ์šฉํ•  ๋•Œ, ๊ณผ๋Œ€ํ‰๊ฐ€๋˜๊ธฐ ์‰ฌ์šด ๋Œ€์ƒ์˜ ๊ฐ€์น˜๋ฅผ ํŠน์ • ๊ธฐ์ค€์ ์— ๊ณ ์ •ํ•˜๋Š” ์—ญํ• ์— ์ง‘์ค‘ํ•œ๋‹ค. ๋ฐ˜๋ฉด ๊ณผ์†Œํ‰๊ฐ€๋˜๋Š” ๋Œ€์ƒ์„ ์˜นํ˜ธํ•˜๋Š” ์—ญํ• ์€ ๋“ฑํ•œ์‹œํ•˜๋Š” ๊ฒฝํ–ฅ์ด ์žˆ๋‹ค.

๋ฌด์˜๋ฏธํ•œ ๋ง์žฅ๋‚œ๊นŒ์ง€๋Š” ์•„๋‹ˆ๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค. ์Šค์Šค๋กœ์— ๋Œ€ํ•œ(ํ˜น์€ ๋ฌด์—‡์ธ๊ฐ€์— ๋Œ€ํ•œ) ํ‰๊ฐ€๊ฐ€ ์•ผ๋ฐ•ํ•ด์งˆ ๋•Œ ๊ณผ์†Œํ‰๊ฐ€๋ฅผ ๋ง‰์•„์คŒ์œผ๋กœ์จ ๋ฉ˜ํƒˆ์„ ์ ์ •์„ ์œผ๋กœ ์œ ์ง€ํ•ด ์ค€๋‹ค. ๋‚ด ์ƒ๊ฐ ๊ทธ ์ด์ƒ๋„ ์ดํ•˜๋„ ์•„๋‹ˆ๋‹ค.

profile
Write a little every day, without hope, without despair โœ๏ธ

0๊ฐœ์˜ ๋Œ“๊ธ€