Skip to content

Commit

Permalink
Merge pull request #61 from ghojeong/fe/47/new-calendar
Browse files Browse the repository at this point in the history
[FE] 캘린더 UI 기초틀 완성
  • Loading branch information
ha3158987 authored May 28, 2021
2 parents 86ae4b5 + be22654 commit 9595433
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 109 deletions.
56 changes: 12 additions & 44 deletions frontend/src/components/SearchBar/Calendar/CalendarModal.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import { useRecoilValue } from 'recoil';
import * as S from "components/SearchBar/Calendar/CalendarStyles";
import moment, { Moment } from "moment";
import 'moment/locale/ko';
moment.locale('ko');
import MonthlyCalendar from 'components/SearchBar/Calendar/MonthlyCalendar';

const CalendarModal = () => {
const value = moment(); //현재 날짜값 가져오기
const startDay = value.clone().startOf("month").startOf("week");//clone을 해주는 이유 = 원본 now Date를 보존하기 위해.
const endDay = value.clone().endOf("month").endOf("week");
const day = startDay.clone().subtract(1, "day"); //시작일에서 하루 빼기
const calendar:Array<Moment[]> = [];

//들어오는 day 값이 endDay 이전 값인지 체크.
const createCalendar = () => {
while(day.isBefore(endDay, "day")) {
calendar.push(Array(7).fill(0).map(() => day.add(1, "day").clone()));
}
//format()을 하면 moment 객체에서 string으로 바꿔줌.
//[[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [],,]
return calendar.map(week =>
<div className="calendar">
{week.map((day) => {
<div>{day.format("D").toString()}</div>
})}
</div>
)
}

console.log(startDay.format("D").toString(), endDay.format("D").toString(), day.format("D").toString());
const monthTypes: string[] = ["PREVIOUS", "CURRENT", "NEXT", "MONTH_AFTER_NEXT"];

return (
<S.CalendarModalLayout>
Expand All @@ -36,26 +13,17 @@ const CalendarModal = () => {
<button>자유로운 일정</button>
</div>
</S.CalendarSelector>
<S.CalendarLayout>
<S.CurrentMonth>
<div>
<S.LeftArrowBtn>
<S.RiArrowLeftSLine/>
</S.LeftArrowBtn>
<div className="year_and_month">{startDay.format("YYYY")}{startDay.format("MM")}</div>
</div>
<S.CalendarMatrix></S.CalendarMatrix>
</S.CurrentMonth>
<S.NextMonth>
<div>
<div className="year_and_month">{endDay.format("YYYY")}{endDay.format("MM")}</div>
<S.RightArrowBtn>
<S.LeftArrowBtn>
<S.RiArrowLeftSLine/>
</S.LeftArrowBtn>
<S.RightArrowBtn>
<S.RiArrowRightSLine/>
</S.RightArrowBtn>
</div>
<S.CalendarMatrix></S.CalendarMatrix>
</S.NextMonth>
</S.CalendarLayout>
<S.MonthlyCalendarContainer>
{monthTypes.map((_, idx) =>
<MonthlyCalendar monthType={monthTypes[idx]}/>
)}
</S.MonthlyCalendarContainer>
</S.CalendarModalLayout>
);
};
Expand Down
107 changes: 57 additions & 50 deletions frontend/src/components/SearchBar/Calendar/CalendarStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ const CalendarModalLayout = styled.div`
background: #ffffff;
box-shadow: rgb(0 0 0 / 20%) 0px 6px 20px;
border-radius: 40px;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
`;

const CalendarSelector = styled.div`
Expand All @@ -32,9 +29,10 @@ const CalendarSelector = styled.div`
& > button {
border-radius: 100px;
border: none;
font-size: 0.9rem;
font-size: 1.3rem;
font-weight: 600;
line-height: 1.8rem;
font-weight: 400;
font-weight: 600;
background: #fff;
color: rgb(34, 34, 34);
padding: 3px 14px;
Expand All @@ -43,32 +41,35 @@ const CalendarSelector = styled.div`
cursor: pointer;
&:last-child {
background-color: #e6e6e6;
font-weight: 600;
&:hover {
background-color: #fff;
transition: background-color 0.4s;
}
&:not(hover) {
transition: background-color 0.2s;
}
}
}
}
`;

const CalendarLayout = styled.div`
outline: red solid 1px;
width: 90%;
margin: 1.6rem;
/* outline: red solid 1px; */
/*margin: 1.6rem;*/
padding: 1.5rem;
font-size: 1.6rem;
font-weight: 600;
display: flex;
.calendar {
.title-container {
width: 100%;
}
`;

const LeftArrowBtn = styled.button`
position: absolute;
left: 0;
top: 0;
left: 3rem;
top: 2rem;
width: 2rem;
height: 2rem;
border: none;
Expand All @@ -78,17 +79,16 @@ const LeftArrowBtn = styled.button`
&:hover {
background-color: rgb(247, 247, 247);
}
& > svg {
height: 1.2rem;
width: 1.2rem;
height: 2.5rem;
width: 2.5rem;
}
`;

const RightArrowBtn = styled.button`
position: absolute;
right: 0;
top: 0;
right: 3rem;
top: 2rem;
width: 2rem;
height: 2rem;
border: none;
Expand All @@ -100,58 +100,66 @@ const RightArrowBtn = styled.button`
}
& > svg {
height: 1.2rem;
width: 1.2rem;
height: 2.5rem;
width: 2.5rem;
}
`;

const CurrentMonth = styled.div`
display: flex;
border: 1px solid green;
width: 50%;
text-align: center;
flex-direction: column;
/*border: 1px solid green;*/
.calendar-container {
width: 100%;
}
&:first-child {
position: relative;
display: flex;
border: 1px solid pink;
align-items: center;
}
.year_and_month {
padding-top: 0.5rem;
margin: 0 auto;
width: auto;
text-align: center;
height: 2rem;
}
`;

const NextMonth = styled.div`
display: flex;
border: 1px solid green;
width: 50%;
text-align: center;
flex-direction: column;
&:last-child {
position: relative;
display: flex;
border: 1px solid pink;
align-items: center;
.days {
width: 100%;
font-weight: 300;
font-size: 1.2rem;
display: grid;
grid-template-columns: repeat(7, 1fr);
& > span {
display: flex;
align-items: center;
height: 2em;
padding: 0.5rem 1rem;
}
}
.year_and_month {
padding-top: 0.5rem;
margin: 0 auto;
width: auto;
height: 2rem;
.dates {
display: grid;
grid-template-columns: repeat(7, 1fr);
justify-items: center; //grid
& > div {
display: flex;
align-items: center; //flex
height: 5rem;
}
}
`;
const CalendarMatrix = styled.div`
border: 1px solid blue;
width: 100%;
`;

const MonthlyCalendarContainer = styled.div`
//각 달의 달력들을 가로로 쭈욱 가지고 있는 애
display: grid;
width: 200%;
grid-template-columns: repeat(4, 1fr);
`

export {
CalendarModalLayout,
Expand All @@ -160,8 +168,7 @@ export {
LeftArrowBtn,
RightArrowBtn,
CurrentMonth,
NextMonth,
CalendarMatrix,
RiArrowLeftSLine,
RiArrowRightSLine,
MonthlyCalendarContainer
};
37 changes: 37 additions & 0 deletions frontend/src/components/SearchBar/Calendar/MonthlyCalendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useRecoilValue } from 'recoil';
import { calendarModalState } from 'recoil/Atoms';
import * as S from "components/SearchBar/Calendar/CalendarStyles";

interface MonthProps {
monthType: string
}

const MonthlyCalendar:React.FunctionComponent<MonthProps> = ({monthType}) => {
const { year, month, today} = useRecoilValue(calendarModalState);
const daysOfWeek: string[] = ["일", "월", "화", "수", "목", "금", "토"];
const startDay: number = new Date(year, month, 1).getDay();
const endDate: number = new Date(year, month, 0).getDate();
const emptyDates: (number | string)[] = Array(startDay).fill("");
const filledDates = Array.from({ length : endDate },(_, i) => i + 1);
const dates = [...emptyDates, ...filledDates];
const calendarTemplate = dates.map((date, idx) => <div key={'date-' + idx}>{date}</div>)
console.log(monthType);

return (
<S.CalendarLayout>
<div className="title-container">
<S.CurrentMonth>
<div className="calendar-container">

<div className="year_and_month">{year}{month}</div>
<div className="days">{daysOfWeek.map(day => <span>{day}</span>)}</div>
<div className="dates">{calendarTemplate}</div>
</div>
</S.CurrentMonth>
</div>
</S.CalendarLayout>
);
};

export default MonthlyCalendar;

65 changes: 65 additions & 0 deletions frontend/src/components/SearchBar/Calendar/Old.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export {};
/*
import * as S from "components/SearchBar/Calendar/CalendarStyles";
import moment, { Moment } from "moment";
import 'moment/locale/ko';
moment.locale('ko');

const CalendarModal = () => {
const value = moment(); //현재 날짜값 가져오기
const startDay = value.clone().startOf("month").startOf("week");//clone을 해주는 이유 = 원본 now Date를 보존하기 위해.
const endDay = value.clone().endOf("month").endOf("week");
const day = startDay.clone().subtract(1, "day"); //시작일에서 하루 빼기
const calendar:Array<Moment[]> = [];

//들어오는 day 값이 endDay 이전 값인지 체크.
const createCalendar = () => {
while(day.isBefore(endDay, "day")) {
calendar.push(Array(7).fill(0).map(() => day.add(1, "day").clone()));
}
//format()을 하면 moment 객체에서 string으로 바꿔줌.
//[[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [],,]
return calendar.map(week =>
<div className="calendar">
{week.map((day) => {
<div>{day.format("D").toString()}</div>
})}
</div>
)
}

console.log(startDay.format("D").toString(), endDay.format("D").toString(), day.format("D").toString());

return (
<S.CalendarModalLayout>
<S.CalendarSelector>
<div>
<button>달력</button>
<button>자유로운 일정</button>
</div>
</S.CalendarSelector>
<S.CalendarLayout>
<S.CurrentMonth>
<div>
<S.LeftArrowBtn>
<S.RiArrowLeftSLine/>
</S.LeftArrowBtn>
<div className="year_and_month">{startDay.format("YYYY")}년 {startDay.format("MM")}월</div>
</div>
</S.CurrentMonth>
<S.NextMonth>
<div>
<div className="year_and_month">{endDay.format("YYYY")}년 {endDay.format("MM")}월</div>
<S.RightArrowBtn>
<S.RiArrowRightSLine/>
</S.RightArrowBtn>
</div>
</S.NextMonth>
</S.CalendarLayout>
</S.CalendarModalLayout>
);
};

export default CalendarModal;

*/
11 changes: 3 additions & 8 deletions frontend/src/components/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@ import {
useSetRecoilState,
} from "recoil";
import React, { useState, useEffect } from "react";
import { searchBarClickState, checkInClickState } from "recoil/Atoms";
import { searchBarClickState } from "recoil/Atoms";

const SearchBar = () => {
// const Reset = useResetRecoilState(searchBarClickState);
const setsSearchBarClick = useSetRecoilState(searchBarClickState);
const checkInTest = useRecoilValue(checkInClickState);

useEffect(() => {
console.log(checkInTest);
if (checkInTest) document.body.addEventListener("click", ClosePopup);
return function cleanup() {
document.body.removeEventListener("click", ClosePopup);
};
}, [checkInTest]);
document.body.addEventListener("click", ClosePopup);
}, []);

const ClosePopup = (e: MouseEvent): void => {
console.log(33);
Expand Down
Loading

0 comments on commit 9595433

Please sign in to comment.