Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

또 다른 컴포넌트 구현 및 스토리북 추가... #19

Merged
merged 29 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fc214f8
💅 style: bookingButton 컴포넌트 구현 및 스토리북 추가 #15
froggy1014 Aug 6, 2024
d4b473e
💅 style: 초기화 버튼 컴포넌트 구현 및 스토리북 추가 #15
froggy1014 Aug 6, 2024
200a468
🔨 settings: button1 Medium 폰트 Typography 추가 #15
froggy1014 Aug 6, 2024
9697eca
💅 style: round 버튼 컴포넌트 구현 및 스토리북 추가 #15
froggy1014 Aug 6, 2024
021709b
💅 style: 평점 컴포넌트에 반개 별 아이콘 추가 #15
froggy1014 Aug 6, 2024
092a952
💅 style: festivalTile 컴포넌트 글자들 사이 gap 추가 #15
froggy1014 Aug 6, 2024
0d6551a
💅 style: pencil Icon 아셋 추가 #15
froggy1014 Aug 6, 2024
6a8cd2e
💅 style: floating Button 컴포넌트 구현 및 스토리북 추가 #15
froggy1014 Aug 6, 2024
b021331
💅 style: 페스티벌 헤더 추가 및 스토리북 추가 외 폴더 구조 변경 #15
froggy1014 Aug 6, 2024
c2ee08b
🔧 chore: 오타 수정 scrap -\> scrab
froggy1014 Aug 6, 2024
ef75fa6
💅 style: 페스티발 카드 컴포넌트 스크랩 버튼 추가 #15
froggy1014 Aug 6, 2024
c1b3085
🔨 settings: 날짜 관련 라이브러리 dayjs 설치 및 radix-ui 모달 설치 #15
froggy1014 Aug 7, 2024
923bb35
✨ feat: 캘린더 컴포넌트 구현 #15
froggy1014 Aug 7, 2024
de446c2
Merge branch 'develop' into feature/implements-component
froggy1014 Aug 7, 2024
b69f285
🔧 chore: 변경된 경로에 따라 import 수정
froggy1014 Aug 7, 2024
b94a8c8
🔨 settings: autoFocuing을 막기위한 react-focus-scope 설치
froggy1014 Aug 7, 2024
9249b6e
💅 style: dialogWrapper 컴포넌트 구현 및 스토리북 추가 #15
froggy1014 Aug 7, 2024
20c564f
💅 style: 캘린더 다이얼로그 구현 및 스토리북 추가 #15
froggy1014 Aug 7, 2024
6662f40
♻️ refactor: iconButton 코드 수정으로 인한 마이그레이션 #15
froggy1014 Aug 7, 2024
675db72
💅 style: 이미지 삭제 아이콘 아셋 추가 #15
froggy1014 Aug 8, 2024
c043826
💅 style: 이미지 업로드 컴포넌트 구현 및 스토리북 추가 #15
froggy1014 Aug 8, 2024
d6b21a3
🔨 settings: radix-ui/react-alert-dialog 설치 #15
froggy1014 Aug 8, 2024
931f77c
💅 style: tailwind animation keyframe 추가
froggy1014 Aug 8, 2024
e73bf66
💅 style: 다이어로그 관련 컴포넌트 구현 및 스토리북 추가 #15
froggy1014 Aug 8, 2024
287cd64
👷 cicd: 스토리북 chromatic URL 생성 코멘트 수정
froggy1014 Aug 8, 2024
7e6c8ae
🔧 chore: dialog Index 파일 생성 #15
froggy1014 Aug 8, 2024
20962e3
🐛 fix: 빌드 에러 수정
froggy1014 Aug 8, 2024
9264a87
🐛 fix: 피드백 반영 #15
froggy1014 Aug 9, 2024
36b2e15
🐛 fix: 빌드에러해결 #15
froggy1014 Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import dayjs, { Dayjs } from "dayjs";
import isBetween from "dayjs/plugin/isBetween";
import isToday from "dayjs/plugin/isToday";
import weekday from "dayjs/plugin/weekday";
import weekOfYear from "dayjs/plugin/weekOfYear";
import React, { useState } from "react";

import { cn } from "@/utils/cn";

import IconButton from "../core/Button/IconButton/IconButton";
import { ArrowLeftSmallIcon, ArrowRightSmallIcon } from "../icons";

dayjs.extend(weekday);
dayjs.extend(weekOfYear);
dayjs.extend(isToday);
dayjs.extend(isBetween);
froggy1014 marked this conversation as resolved.
Show resolved Hide resolved

const Calendar = () => {
const [currentDate, setCurrentDate] = useState(dayjs());
const [startDate, setStartDate] = useState<Dayjs | undefined>(undefined);
froggy1014 marked this conversation as resolved.
Show resolved Hide resolved
const [endDate, setEndDate] = useState<Dayjs | undefined>(undefined);

const generateCalendar = (date: Dayjs) => {
const days = [];
const startOfMonth = date.startOf("month");
const endOfMonth = date.endOf("month");
const startOfWeek = startOfMonth.startOf("week");
const endOfWeek = endOfMonth.endOf("week");

let currentDay = startOfWeek;

while (currentDay.isBefore(endOfWeek) || currentDay.isSame(endOfWeek)) {
days.push({
date: currentDay.format("YYYY-MM-DD"),
isCurrentMonth: currentDay.isBetween(
startOfMonth,
endOfMonth,
"day",
"[]",
),
isToday: currentDay.isToday(),
isInRange:
startDate &&
endDate &&
currentDay.isBetween(startDate, endDate, "day", "[]"),
isStart: startDate && currentDay.isSame(startDate, "day"),
isEnd: endDate && currentDay.isSame(endDate, "day"),
});
currentDay = currentDay.add(1, "day");
}

// ? 항상 달력에 6줄을 보장함.
const totalDays = days.length;
// const weeks = Math.ceil(totalDays / 7);
const extraDays = 6 * 7 - totalDays;

for (let i = 0; i < extraDays; i++) {
days.push({
date: "",
isCurrentMonth: false,
isToday: false,
isInRange: false,
isStart: false,
isEnd: false,
});
}

return days;
};

const calendarDays = generateCalendar(currentDate);

const handlePrevMonth = () => {
setCurrentDate(currentDate.subtract(1, "month"));
};

const handleNextMonth = () => {
setCurrentDate(currentDate.add(1, "month"));
};

const handleDayClick = (date: string) => {
if (!startDate || (startDate && endDate)) {
setStartDate(dayjs(date));
setEndDate(undefined);
} else if (startDate && !endDate) {
if (dayjs(date).isBefore(startDate)) {
setEndDate(startDate);
setStartDate(dayjs(date));
} else {
setEndDate(dayjs(date));
}
}
};

return (
<div className="mx-auto mt-10 max-w-md">
<div className="mb-4 flex items-center justify-center gap-[10px]">
<IconButton
icon={
<ArrowLeftSmallIcon
width={20}
height={20}
className="text-gray-scale-800"
/>
}
onClick={handlePrevMonth}
className="text-lg rounded-full p-2 hover:bg-gray-200"
/>

<span
id="currentMonth"
className="text-caption2-medium text-gray-scale-800"
>
{currentDate.format("YYYY.MM")}
</span>
<IconButton
icon={
<ArrowRightSmallIcon
width={20}
height={20}
className="text-gray-scale-800"
/>
}
onClick={handleNextMonth}
className="text-lg rounded-full p-2 hover:bg-gray-200"
/>
</div>
<div className="grid grid-cols-7">
{["S", "M", "T", "W", "T", "F", "S"].map((day, index) => (
<div
key={index}
className="flex h-12 w-12 items-center justify-center text-caption2-medium text-gray-scale-700"
>
{day}
</div>
))}
{calendarDays.map((day, index) => (
<div
key={index}
onClick={() => handleDayClick(day.date)}
className={cn(
"w-12 h-12 flex justify-center items-center cursor-pointer relative",
day.isCurrentMonth
? "text-gray-scale-700"
: "text-gray-scale-500",
day.isInRange ? "bg-primary-04" : "",
day.isStart ? "bg-primary-01 text-white rounded-full z-[99]" : "",
day.isEnd ? "bg-primary-01 text-white rounded-full z-[99]" : "",
)}
>
{day.date ? dayjs(day.date).date() : ""}
froggy1014 marked this conversation as resolved.
Show resolved Hide resolved
{day.isStart && (
<>
{!!startDate && !!endDate && (
<div className="absolute right-0 top-0 z-[-1] h-[48px] w-[24px] bg-primary-04" />
)}
<div className="absolute right-0 top-0 z-[-1] h-[48px] w-[24px] rounded-br-full rounded-tr-full bg-primary-01" />
</>
)}
{day.isEnd && (
<>
{!!startDate && !!endDate && (
<div className="absolute left-0 top-0 z-[-1] h-[48px] w-[24px] bg-primary-04" />
)}
<div className="absolute left-0 top-0 z-[-1] h-[48px] w-[24px] rounded-bl-full rounded-tl-full bg-primary-01" />
</>
)}
</div>
))}
</div>
</div>
);
};

export default Calendar;
1 change: 1 addition & 0 deletions src/components/core/Button/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Props
const IconButton: FC<Props> = ({ icon, active = false, ...props }) => {
return (
<button
type="button"
className={cn(
"w-auto h-auto duration-300",
"flex items-center justify-center",
Expand Down