-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* style: 날짜에 hover 스타일 추가 Dae-Hwa/airbnb/#19 * refactor: Day 컴포넌트 분리 - 분리하면서 null인 날짜는 <Blink />를 반환하도록 변경 - 그래서 hover를 막을 수 있었다. Dae-Hwa/airbnb/#19 * feat: 캘린더 날짜 선택 기능을 위한 상태 세팅 중 - Day.tsx에서 계속 useContext로 상태를 못받아서 디버깅해본 결과, CalendarContext라는 이름의 컨텍스트가 CalendarModal에도 중복으로 있어서 덮어씌워짐을 확인했다. - 그래서 일단 SearchBar에는 CalendarContextRaccoon이라고 이름 지어놓음.. - 콘솔에 warning 뜨는 것도 없애기 위해 테이블 관련 태그도 모두 div로 바꿈 Dae-Hwa/airbnb/#19 * refactor: 캘린더와 관련된 상태를 SearchBar에서 모두 provide - 기존에 SearchBar와 CalendarModal 두 군데로 쪼개져 있던 CalendarContext를 하나로 합침 - 사용하지 않는 import 제거 Dae-Hwa/airbnb/#19 * feat: 날짜 클릭 이벤트 및 로직 추가 Dae-Hwa/airbnb/#19 * feat: 선택된 날짜 styling - month 넘어갈 때 gradient, 체크인 체크아웃 날짜에 회색 박스 이어지게 하는 것 부족하지만 일단 이렇게만 해놓고 넘어가기로.. Dae-Hwa/airbnb/#19 * feat: 캘린더 과거 날짜 disabled 처리 Dae-Hwa/airbnb/#19
- Loading branch information
1 parent
29721bf
commit e734380
Showing
9 changed files
with
206 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { ReactElement, useContext } from 'react'; | ||
|
||
import styled from 'styled-components' | ||
import moment, { Moment } from 'moment'; | ||
|
||
import { CalendarContext } from '@components/searchBar/SearchBar' | ||
import { CalendarContextType } from '@components/searchBar/SearchBar' | ||
import { DayContainerProps } from '@components/searchBar/searchBarTypes'; | ||
|
||
type DayProps = { | ||
day: Moment; | ||
handleClickDate: () => void | ||
} | ||
|
||
function useCalendarState(): CalendarContextType { | ||
const state = useContext(CalendarContext); | ||
if(!state) throw new Error('에러발생~! state가 없습니다.🙅🏻'); | ||
return state; | ||
} | ||
|
||
function Day({ day }: DayProps): ReactElement { | ||
const { | ||
checkInMoment, | ||
setCheckInMoment, | ||
checkOutMoment, | ||
setCheckOutMoment | ||
} = useCalendarState(); | ||
|
||
const isSelected = () => { | ||
if(day.isSame(checkInMoment) || day.isSame(checkOutMoment)) return true; | ||
return false; | ||
} | ||
|
||
const isBetween = () => { | ||
return (day.isBetween(checkInMoment, checkOutMoment)) | ||
} | ||
|
||
const isBefore = () => { | ||
if(day.isSame(moment().startOf('day'))) return false; | ||
else return day.isBefore(moment()); | ||
} | ||
|
||
const handleClickDate = (): void => { | ||
if(!checkInMoment && !checkOutMoment) { | ||
setCheckInMoment(day); | ||
} | ||
|
||
if(checkInMoment && !checkOutMoment) { | ||
if(day.isSame(checkInMoment)) { | ||
setCheckOutMoment(day); | ||
} | ||
if(day.isBefore(checkInMoment)) { | ||
setCheckInMoment(day); | ||
} | ||
if(day.isAfter(checkInMoment)) { | ||
setCheckOutMoment(day); | ||
} | ||
} | ||
|
||
if(checkInMoment && checkOutMoment) { | ||
if(day.isSame(checkInMoment)) { | ||
setCheckOutMoment(day); | ||
} | ||
if(day.isBefore(checkInMoment)) { | ||
setCheckInMoment(day); | ||
setCheckOutMoment(null); | ||
} | ||
if(day.isAfter(checkInMoment)) { | ||
setCheckOutMoment(day) | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{day !== null | ||
? <DayContainer disabled={isBefore()} onClick={handleClickDate} isSelected={isSelected()} isBetween={isBetween()}> | ||
{day && day.format('D').toString()} | ||
</DayContainer> | ||
: <Blank />} | ||
</> | ||
) | ||
} | ||
|
||
const DayContainer = styled.button<DayContainerProps>` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 48px; | ||
height: 48px; | ||
font-weight: bold; | ||
font-size: ${({ theme }) => theme.fontSizes.XS}; | ||
background-color: ${({ theme, isSelected, isBetween }) => isSelected ? theme.colors.gray1 : isBetween ? theme.colors.gray6 : 'transparent'}; | ||
color: ${({ theme, isSelected }) => isSelected ? theme.colors.white : theme.colors.gray1}; | ||
border-radius: ${({ theme, isBetween }) => isBetween ? 0 : theme.borders.M}; | ||
&:disabled:hover { | ||
cursor: default; | ||
border: none; | ||
} | ||
&:hover { | ||
border: 1px solid ${({ theme }) => theme.colors.black}; | ||
border-radius: ${({ theme }) => theme.borders.M}; | ||
cursor: pointer; | ||
} | ||
&:disabled { | ||
color: ${({theme}) => theme.colors.gray4}; | ||
} | ||
` | ||
|
||
const Blank = styled.div` | ||
width: 48px; | ||
height: 48px; | ||
` | ||
|
||
export default Day |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.