Skip to content

Commit

Permalink
Merge pull request #40 from Strong-Potato/33-feat-add-list-slide
Browse files Browse the repository at this point in the history
Feat: add list slide
  • Loading branch information
Yamyam-code authored Jan 7, 2024
2 parents e2f1e82 + feb4dab commit eb5326c
Show file tree
Hide file tree
Showing 22 changed files with 518 additions and 142 deletions.
18 changes: 0 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@use "@/sass" as *;

.container {
display: flex;
gap: 16px;
@include slide_button_container;

padding: 0 20px;

overflow-x: scroll;
.slide_box {
@include slide_list_container;
gap: 16px;
}
}
39 changes: 35 additions & 4 deletions src/components/Home/RecommendedItemList/RecommendedItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { useEffect, useState } from "react";

import styles from "./RecommendedItemList.module.scss";

import useComponentSize from "@/hooks/useComponetSize";

import SlideButton from "@/components/SlideButton/SlideButton";

import { getData } from "@/mocks/handlers/home";

import RecommendedItem from "./RecommendedItem/RecommendedItem";
Expand All @@ -14,6 +18,8 @@ interface PropsType {

function RecommendedItemList(apiNum: PropsType) {
const [data, setData] = useState<RecommendedItemDataType[]>();
const [slideLocation, setSlideLocation] = useState<number>(0);
const [componentRef, size] = useComponentSize();

useEffect(() => {
getData<RecommendedItemDataType[] | undefined>(
Expand All @@ -24,10 +30,35 @@ function RecommendedItemList(apiNum: PropsType) {

return (
<div className={styles.container}>
{data &&
data.map((data, i) => (
<RecommendedItem data={data} key={data.title + i} />
))}
{data && (
<SlideButton
// ref의 left값 state
slideLocation={slideLocation}
// left값 setState
setSlideLocation={setSlideLocation}
// 리스트 목록 아이템의 width
itemWidth={144}
// 리스트의 갭
flexGap={16}
// 아이템 갯수
itemNumber={data.length}
// 목록 전체 넓이
slideSize={size}
/>
)}
<div
className={styles.slide_box}
ref={componentRef}
style={{
overflow: size.width < 450 ? "scroll" : "visible",
left: slideLocation + "px",
}}
>
{data &&
data.map((data, i) => (
<RecommendedItem data={data} key={data.title + i} />
))}
</div>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@use "@/sass" as *;

.container {
display: flex;
gap: 8px;
@include slide_button_container;

padding: 0 20px;

overflow-x: scroll;
.slide_box {
@include slide_list_container;
gap: 8px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { useEffect, useState } from "react";

import styles from "./RecommendedLocationList.module.scss";

import useComponentSize from "@/hooks/useComponetSize";

import SlideButton from "@/components/SlideButton/SlideButton";

import { getData } from "@/mocks/handlers/home";

import RecommendedLocation from "./RecommendedLocation/RecommendedLocation";
Expand All @@ -10,6 +14,8 @@ import { LocationDataType } from "@/types/home";

function RecommendedLocationList() {
const [data, setData] = useState<LocationDataType[]>();
const [slideLocation, setSlideLocation] = useState<number>(0);
const [componentRef, size] = useComponentSize();

useEffect(() => {
getData<LocationDataType[] | undefined>(
Expand All @@ -20,10 +26,29 @@ function RecommendedLocationList() {

return (
<div className={styles.container}>
{data &&
data.map((data, i) => (
<RecommendedLocation data={data} key={data.location + i} />
))}
{data && (
<SlideButton
slideLocation={slideLocation}
setSlideLocation={setSlideLocation}
itemWidth={122}
flexGap={8}
itemNumber={data.length}
slideSize={size}
/>
)}
<div
className={styles.slide_box}
ref={componentRef}
style={{
overflow: size.width < 450 ? "scroll" : "visible",
left: slideLocation + "px",
}}
>
{data &&
data.map((data, i) => (
<RecommendedLocation data={data} key={data.location + i} />
))}
</div>
</div>
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Home/TabBar/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ function TabBar() {
<Link to="/search">
<IoSearchSharp />
</Link>
<AiOutlineBell />
<Link to="/alarm">
<AiOutlineBell />
</Link>
</div>
</div>
);
Expand Down
10 changes: 5 additions & 5 deletions src/components/Home/TripSpaceAtHome/TripSpaceAtHome.module.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@use "@/sass" as *;

.container {
display: flex;
gap: 8px;
@include slide_button_container;

padding: 0 20px;

overflow-x: scroll;
.slide_box {
@include slide_list_container;
gap: 8px;
}
}
37 changes: 31 additions & 6 deletions src/components/Home/TripSpaceAtHome/TripSpaceAtHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { useEffect, useState } from "react";

import styles from "./TripSpaceAtHome.module.scss";

import useComponentSize from "@/hooks/useComponetSize";

import SlideButton from "@/components/SlideButton/SlideButton";

import { getData } from "@/mocks/handlers/home";

import TripSpaceItem from "./TripSpaceItem/TripSpaceItem";
Expand All @@ -10,6 +14,8 @@ import { TripSpaceDataType } from "@/types/home";

function TripSpaceAtHome() {
const [data, setData] = useState<TripSpaceDataType[]>();
const [slideLocation, setSlideLocation] = useState<number>(0);
const [componentRef, size] = useComponentSize();

const dataNull = {
tripTitle: "아직 여행 일정이 없어요",
Expand All @@ -24,13 +30,32 @@ function TripSpaceAtHome() {

return (
<div className={styles.container}>
{data ? (
data.map((data, i) => (
<TripSpaceItem data={data} key={data.tripTitle + i} />
))
) : (
<TripSpaceItem data={dataNull} key={dataNull.tripTitle} />
{data && (
<SlideButton
slideLocation={slideLocation}
setSlideLocation={setSlideLocation}
itemWidth={323}
flexGap={8}
itemNumber={data.length}
slideSize={size}
/>
)}
<div
className={styles.slide_box}
ref={componentRef}
style={{
overflow: size.width < 450 ? "scroll" : "visible",
left: slideLocation + "px",
}}
>
{data ? (
data.map((data, i) => (
<TripSpaceItem data={data} key={data.tripTitle + i} />
))
) : (
<TripSpaceItem data={dataNull} key={dataNull.tripTitle} />
)}
</div>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MdArrowForwardIos } from "react-icons/md";
import { Link } from "react-router-dom";

import styles from "./TripSpaceItem.module.scss";

Expand All @@ -11,7 +12,7 @@ interface PropsData {
function TripSpaceItem(data: PropsData) {
const imageAlt = `${data.data.tripTitle}의 사진`;
return (
<div className={styles.container}>
<Link to="/carryout" className={styles.container}>
<div className={styles.img_box}>
<img
className={styles.trip_img}
Expand All @@ -30,7 +31,7 @@ function TripSpaceItem(data: PropsData) {
<MdArrowForwardIos />
</div>
)}
</div>
</Link>
);
}

Expand Down
Loading

0 comments on commit eb5326c

Please sign in to comment.