Skip to content

Commit ca082f5

Browse files
committed
Implimentation a type of Date value
1 parent 468aeab commit ca082f5

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/components/Datepicker.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ import { COLORS, DEFAULT_COLOR } from "../constants";
99
import DatepickerContext from "../contexts/DatepickerContext";
1010
import { formatDate, nextMonth, previousMonth } from "../helpers";
1111
import useOnClickOutside from "../hooks";
12-
import { Period } from "../types";
12+
import { Period, DateValueType } from "../types";
1313

1414
import { Arrow, VerticalDash } from "./utils";
1515

1616
interface Props {
1717
primaryColor?: string;
18-
value: {
19-
startDate: string | Date | null;
20-
endDate: string | Date | null;
21-
} | null;
22-
onChange: (
23-
value: { startDate: string | Date | null; endDate: string | Date | null } | null
24-
) => void;
18+
value: DateValueType;
19+
onChange: (value: DateValueType) => void;
2520
useRange?: boolean;
2621
showFooter?: boolean;
2722
showShortcuts?: boolean;

src/contexts/DatepickerContext.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import dayjs from "dayjs";
22
import React, { createContext } from "react";
33

4-
import { Configs, Period } from "../types";
5-
6-
type DateRange = {
7-
startDate: string | Date | null;
8-
endDate: string | Date | null;
9-
} | null;
4+
import { Configs, Period, DateValueType } from "../types";
105

116
interface DatepickerStore {
127
asSingle?: boolean;
@@ -22,12 +17,12 @@ interface DatepickerStore {
2217
inputText: string;
2318
changeInputText: (text: string) => void;
2419
updateFirstDate: (date: dayjs.Dayjs) => void;
25-
changeDatepickerValue: (value: DateRange) => void;
20+
changeDatepickerValue: (value: DateValueType) => void;
2621
showFooter?: boolean;
2722
placeholder?: string | null;
2823
separator?: string;
2924
i18n: string;
30-
value: DateRange;
25+
value: DateValueType;
3126
disabled?: boolean;
3227
inputClassName?: string | null;
3328
containerClassName?: string | null;

src/types/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ export interface ShortcutsItem {
2525
end: string;
2626
};
2727
}
28+
29+
export type DateType = string | null | Date;
30+
31+
export type DateValueType = {
32+
startDate: DateType;
33+
endDate: DateType;
34+
} | null;

0 commit comments

Comments
 (0)