From 369f3e19ebb682726beb59d791c2359e746d1ebe Mon Sep 17 00:00:00 2001 From: LSJ Date: Fri, 17 May 2024 19:58:20 +0900 Subject: [PATCH] wip --- components/atoms/CalendarDayBox.tsx | 29 +++++++++++++ components/molecules/Calendar.tsx | 54 ++++++++++++++---------- components/molecules/DatePointButton.tsx | 46 +++++++++++--------- utils/dateTimeUtils.ts | 8 ++-- 4 files changed, 90 insertions(+), 47 deletions(-) create mode 100644 components/atoms/CalendarDayBox.tsx diff --git a/components/atoms/CalendarDayBox.tsx b/components/atoms/CalendarDayBox.tsx new file mode 100644 index 000000000..3aca4c110 --- /dev/null +++ b/components/atoms/CalendarDayBox.tsx @@ -0,0 +1,29 @@ +import { Box, Flex } from "@chakra-ui/react"; +import dayjs from "dayjs"; +import "dayjs/locale/ko"; +import { dayjsToFormat } from "../../utils/dateTimeUtils"; +import DatePointButton from "../molecules/DatePointButton"; + +interface CalendarDayBoxProps { + date: string; + func: (date: number) => void; + selectedDate: string; + pointType?: "mint"; +} + +function CalendarDayBox({ date, func, selectedDate, pointType }: CalendarDayBoxProps) { + const dayjsDate = dayjs(date); + return ( + + {dayjsToFormat(dayjsDate, "ddd")} + func(dayjsDate.date())} + isSelected={date === selectedDate} + pointType={pointType} + /> + + ); +} + +export default CalendarDayBox; diff --git a/components/molecules/Calendar.tsx b/components/molecules/Calendar.tsx index 22936c893..815f558fe 100644 --- a/components/molecules/Calendar.tsx +++ b/components/molecules/Calendar.tsx @@ -1,15 +1,15 @@ -import { Flex, Grid } from "@chakra-ui/react"; +import { Box, Flex, Grid } from "@chakra-ui/react"; import dayjs, { Dayjs } from "dayjs"; import { getTextSwitcherProps } from "../../pageTemplates/home/studyController/StudyController"; -import { getCalendarDates } from "../../utils/dateTimeUtils"; +import { dayjsToStr, getCalendarDates } from "../../utils/dateTimeUtils"; +import CalendarDayBox from "../atoms/CalendarDayBox"; import DatePointButton from "./DatePointButton"; import BetweenTextSwitcher from "./navs/BetweenTextSwitcher"; interface CalendarProps { type: "week" | "month"; selectedDate: Dayjs; - func: (date: number) => void; } @@ -19,32 +19,40 @@ function Calendar({ type, selectedDate, func }: CalendarProps) { const textSwitcherProps = getTextSwitcherProps(selectedDate, func); const calendarArr = getCalendarDates(type, selectedDate); - + console.log(calendarArr); return ( <> - - {DAYS.map((day, idx) => ( - - {day} - - ))} - + <> {type === "week" ? ( - - {calendarArr.map((dateStr, idx) => { - const date = dayjs(dateStr).date(); - return ( - - func(date)} - isSelected={date === selectedDate.date()} - /> + + {calendarArr.map((date, idx) => ( + + + + ))} + {/* + {DAYS.map((day, idx) => ( + + {day} - ); - })} + ))} + + + {calendarArr.map((dateStr, idx) => { + const date = dayjs(dateStr).date(); + return ( + + + + ); + })} + */} ) : ( diff --git a/components/molecules/DatePointButton.tsx b/components/molecules/DatePointButton.tsx index 1e2e79fa9..d54c872cb 100644 --- a/components/molecules/DatePointButton.tsx +++ b/components/molecules/DatePointButton.tsx @@ -1,7 +1,7 @@ import { Box, Flex } from "@chakra-ui/react"; import styled from "styled-components"; -interface DatePointButtonProps { +export interface DatePointButtonProps { date: number; func: () => void; isSelected?: boolean; @@ -10,28 +10,32 @@ interface DatePointButtonProps { function DatePointButton({ date, func, isSelected }: DatePointButtonProps) { function PointDot() { - return - - -} + return ( + + + + ); + } function TodayCircle({ date }: { date: number }) { - return - {date} - -} + return ( + + {date} + + ); + } return (