-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
210 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"extends": "expo/tsconfig.base", | ||
"compilerOptions": { | ||
"jsx": "preserve", | ||
"strict": true | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,26 @@ | ||
import styled from 'styled-components/native'; | ||
|
||
const DAY_PADDING = 10; | ||
export const DAY_SIZE = 40; | ||
|
||
const CALENDAR_WIDTH = 300; | ||
|
||
export const Calendar = styled.View` | ||
width: ${CALENDAR_WIDTH}px; | ||
border: solid 1px #F2F2F2; | ||
border-radius: 10px; | ||
padding: 8px; | ||
`; | ||
|
||
export const Row = styled.View` | ||
flex-direction: row; | ||
export const DaysContainer = styled.View` | ||
flex-flow: row wrap; | ||
`; | ||
|
||
export const Day = styled.TouchableOpacity` | ||
padding: ${DAY_PADDING}px; | ||
export const DayLink = styled.View` | ||
width: ${DAY_SIZE}px; | ||
height: ${DAY_SIZE}px; | ||
align-items: center; | ||
justify-content: center; | ||
`; | ||
|
||
export const Day = styled.Text` | ||
`; |
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 |
---|---|---|
@@ -1,31 +1,51 @@ | ||
import { memo, useState } from 'react'; | ||
import * as S from './Calendar.style'; | ||
import { ReactNode, memo, useState } from 'react'; | ||
import { useCalendar } from './hooks/useCalendar'; | ||
import { DaysWeek } from './components'; | ||
import { DaysWeek, Button, MonthCurrent } from './components'; | ||
import * as S from './Calendar.style'; | ||
|
||
export interface CalendarProps { | ||
min?: Date; | ||
max?: Date; | ||
value?: Date; | ||
monthLabel?: Array<ReactNode>; | ||
weekLabel?: Array<ReactNode>; | ||
} | ||
|
||
export const Calendar = memo(({ min, max, value }: CalendarProps) => { | ||
const { | ||
buildCalendarDay, | ||
buildMonth, | ||
dayOfWeekAsString, | ||
monthsAsString | ||
} = useCalendar(); | ||
export const Calendar = memo(({ | ||
min, | ||
max, | ||
value, | ||
monthLabel, | ||
weekLabel | ||
}: CalendarProps) => { | ||
const { buildMonth } = useCalendar(); | ||
const [calendarDate, setCalendarDate] = useState<Date>(value || new Date()); | ||
|
||
const month = buildMonth(calendarDate, { min, max, value }); | ||
|
||
return ( | ||
<S.Calendar> | ||
<DaysWeek /> | ||
{month.forEach((item, index) => { | ||
const day = index + 1; | ||
<S.Day key={day}>{index + 1}</S.Day> | ||
})} | ||
<MonthCurrent | ||
monthLabel={monthLabel} | ||
calendarDate={calendarDate} | ||
updateCalendarDate={(d) => setCalendarDate(d)} | ||
/> | ||
<DaysWeek weekLabel={weekLabel} /> | ||
<S.DaysContainer> | ||
{month.map((item, index ) => { | ||
const { date, isDisabled, isObsolete, isSelected } = item; | ||
const day = date.getDate(); | ||
return ( | ||
<S.DayLink key={index}> | ||
<Button.Text | ||
disabled={isDisabled || isObsolete} | ||
fontWeight={isSelected ? 'bold' : 'normal'} | ||
> | ||
{day} | ||
</Button.Text> | ||
</S.DayLink> | ||
); | ||
})} | ||
</S.DaysContainer> | ||
</S.Calendar> | ||
); | ||
}) |
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,10 @@ | ||
import styled from 'styled-components/native'; | ||
import { ButtonProps } from './Button'; | ||
|
||
export const Button = styled.TouchableOpacity<ButtonProps>` | ||
opacity: ${({ disabled }) => (disabled ? 0.3 : 1)}; | ||
`; | ||
|
||
export const Label = styled.Text<{ fontWeight?: 'bold' | 'normal' }>` | ||
font-weight: ${({ fontWeight }) => fontWeight || 'normal'}; | ||
`; |
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,26 @@ | ||
import { ReactNode, memo } from 'react'; | ||
import * as S from './Button.style'; | ||
|
||
export interface ButtonProps { | ||
children?: ReactNode; | ||
disabled?: boolean; | ||
onPress?: () => void; | ||
} | ||
|
||
const ButtonBase = memo(({ children, disabled, onPress }: ButtonProps) => { | ||
return ( | ||
<S.Button disabled={disabled} onPress={onPress}> | ||
{children} | ||
</S.Button> | ||
); | ||
}); | ||
|
||
export const Button = (props: ButtonProps) => <ButtonBase {...props} /> | ||
Button.Text = ({ children, fontWeight, ...props }: ButtonProps & | ||
{ fontWeight?: 'bold' | 'normal'; }) => ( | ||
<ButtonBase {...props}> | ||
<S.Label fontWeight={fontWeight}> | ||
{children} | ||
</S.Label> | ||
</ButtonBase> | ||
); |
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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import styled from 'styled-components/native'; | ||
import { DAY_SIZE } from '../../Calendar.style'; | ||
|
||
export const DaysWeekContainer = styled.View` | ||
flex-direction: row; | ||
`; | ||
|
||
export const DayWeekContainer = styled.View` | ||
width: ${DAY_SIZE}px; | ||
height: ${DAY_SIZE}px; | ||
align-items: center; | ||
justify-content: center; | ||
`; | ||
|
||
export const DayWeek = styled.Text` | ||
font-weight: 800; | ||
`; |
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,12 @@ | ||
import styled from 'styled-components/native'; | ||
|
||
export const MonthCurrent = styled.View` | ||
flex-direction: row; | ||
width: 100%; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 0 5px; | ||
`; | ||
|
||
export const MonthYear = styled.Text` | ||
`; |
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,51 @@ | ||
import { ReactNode, memo } from 'react'; | ||
import { FontAwesome } from '@expo/vector-icons'; | ||
import { Button } from '../Button/Button'; | ||
import { useCalendar } from '../../hooks/useCalendar'; | ||
import * as S from './MonthCurrent.style'; | ||
|
||
interface MonthCurrentProps { | ||
calendarDate: Date; | ||
monthLabel?: Array<ReactNode>; | ||
updateCalendarDate: (d: Date) => void; | ||
} | ||
|
||
export const MonthCurrent = memo(({ | ||
calendarDate, | ||
monthLabel, | ||
updateCalendarDate | ||
}: MonthCurrentProps) => { | ||
const { monthsAsString } = useCalendar(); | ||
const currentMonth = calendarDate.getMonth(); | ||
const monthName = monthsAsString(currentMonth, monthLabel); | ||
|
||
const updateMonth = (monthIncrement: number) => { | ||
const newDate = new Date(calendarDate); | ||
newDate.setMonth(newDate.getMonth() + monthIncrement); | ||
updateCalendarDate(newDate); | ||
} | ||
|
||
const updateYear = (yearIncrement: number) => { | ||
const newDate = new Date(calendarDate); | ||
newDate.setFullYear(newDate.getFullYear() + yearIncrement); | ||
updateCalendarDate(newDate); | ||
} | ||
|
||
return ( | ||
<S.MonthCurrent> | ||
<Button onPress={() => updateYear(-1)}> | ||
<FontAwesome name="angle-double-left" color="black" /> | ||
</Button> | ||
<Button onPress={() => updateMonth(-1)}> | ||
<FontAwesome name="angle-left" color="black" /> | ||
</Button> | ||
<S.MonthYear>{monthName} {String(calendarDate.getFullYear())}</S.MonthYear> | ||
<Button onPress={() => updateMonth(1)}> | ||
<FontAwesome name="angle-right" color="black" /> | ||
</Button> | ||
<Button onPress={() => updateYear(1)}> | ||
<FontAwesome name="angle-double-right" color="black" /> | ||
</Button> | ||
</S.MonthCurrent> | ||
); | ||
}) |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './DaysWeek/DaysWeek'; | ||
export * from './Button/Button'; | ||
export * from './DaysWeek/DaysWeek'; | ||
export * from './MonthCurrent/MonthCurrent'; |
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.