diff --git a/app/page.tsx b/app/page.tsx index cdcaef8..862cbac 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -100,6 +100,13 @@ export default function Playground() { start: new Date(), end: new Date(new Date().setDate(new Date().getDate() + 8)) } + }, + last6Months: { + text: "Last 6 months", + period: { + start: new Date(new Date().setMonth(new Date().getMonth() - 6)), + end: new Date() + } } }, footer: { diff --git a/src/components/Datepicker.tsx b/src/components/Datepicker.tsx index 044bde2..12da59f 100644 --- a/src/components/Datepicker.tsx +++ b/src/components/Datepicker.tsx @@ -334,6 +334,7 @@ const Datepicker = (props: DatepickerType) => { toggleClassName, toggleIcon, updateFirstDate: (newDate: Date) => firstGotoDate(newDate), + updateLastDate: (newDate: Date) => secondGotoDate(newDate), value }; }, [ @@ -368,7 +369,8 @@ const Datepicker = (props: DatepickerType) => { toggleClassName, toggleIcon, value, - firstGotoDate + firstGotoDate, + secondGotoDate ]); const containerClassNameOverload = useMemo(() => { diff --git a/src/components/Shortcuts.tsx b/src/components/Shortcuts.tsx index 5fbeea2..ad0358e 100644 --- a/src/components/Shortcuts.tsx +++ b/src/components/Shortcuts.tsx @@ -18,6 +18,7 @@ const ItemTemplate = memo((props: ItemTemplateProps) => { period, changePeriod, updateFirstDate, + updateLastDate, dayHover, changeDayHover, hideDatepicker, @@ -53,6 +54,7 @@ const ItemTemplate = memo((props: ItemTemplateProps) => { ); if (item.start) updateFirstDate(item.start); + if (item.end) updateLastDate(item.end); hideDatepicker(); }, [ @@ -64,7 +66,8 @@ const ItemTemplate = memo((props: ItemTemplateProps) => { input, period.end, period.start, - updateFirstDate + updateFirstDate, + updateLastDate ] ); diff --git a/src/contexts/DatepickerContext.ts b/src/contexts/DatepickerContext.ts index 1110859..29af9d9 100644 --- a/src/contexts/DatepickerContext.ts +++ b/src/contexts/DatepickerContext.ts @@ -69,6 +69,7 @@ interface DatepickerStore { toggleIcon?: (open: boolean) => ReactNode; updateFirstDate: (date: Date) => void; + updateLastDate: (date: Date) => void; value: DateValueType; } @@ -122,6 +123,7 @@ const DatepickerContext = createContext({ toggleIcon: undefined, updateFirstDate: () => {}, + updateLastDate: () => {}, value: null });