Skip to content

Commit

Permalink
feat: 시작, 끝 날짜 선택 후 재선택 시 초기화
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo-o committed Aug 26, 2024
1 parent 9d79c22 commit 1e840cc
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions packages/wow-ui/src/components/Picker/RangeDatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import { Flex } from "@styled-system/jsx";
import { forwardRef, useState } from "react";
import type { PropsBase, PropsRange } from "react-day-picker";
import type {
DateRange,
Modifiers,
PropsBase,
PropsRange,
} from "react-day-picker";
import { DayPicker } from "react-day-picker";

import DateDropDown from "@/components/Picker/DateDropDown";
Expand All @@ -21,7 +26,7 @@ const RangeDatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
{
className,
classNames,
selected,
selected: prevSelected,
onSelect,
label,
placeholder = "YYYY-MM-DD",
Expand All @@ -30,9 +35,21 @@ const RangeDatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
ref
) => {
const [open, setOpen] = useState<boolean>(false);
const strDate = selected && {
from: selected.from && changeDateToString(selected.from),
to: selected.to && changeDateToString(selected?.to),
const handleSelectDate = (
selected: DateRange | undefined,
triggerDate: Date,
modifiers: Modifiers,
e: React.MouseEvent | React.KeyboardEvent
) => {
if (!onSelect) return;
if (prevSelected && prevSelected.from !== prevSelected.to)
onSelect(undefined, triggerDate, modifiers, e);
else onSelect(selected, triggerDate, modifiers, e);
};

const strDate = prevSelected && {
from: prevSelected.from && changeDateToString(prevSelected.from),
to: prevSelected.to && changeDateToString(prevSelected?.to),
};

return (
Expand Down Expand Up @@ -60,8 +77,8 @@ const RangeDatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
classNames={{ ...pickerClassNames, ...classNames }}
components={pickerComponents}
mode="range"
selected={selected}
onSelect={onSelect}
selected={prevSelected}
onSelect={handleSelectDate}
{...rest}
/>
)}
Expand Down

0 comments on commit 1e840cc

Please sign in to comment.