oolib 2.170.4 → 2.170.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { DayPicker } from "react-day-picker";
|
|
3
|
-
export type CalendarProps = React.ComponentProps<typeof DayPicker
|
|
3
|
+
export type CalendarProps = React.ComponentProps<typeof DayPicker> & {
|
|
4
|
+
className?: string;
|
|
5
|
+
classNames?: Record<string, string>;
|
|
6
|
+
showOutsideDays?: boolean;
|
|
7
|
+
};
|
|
4
8
|
declare function Calendar({ className, classNames, showOutsideDays, ...props }: CalendarProps): React.JSX.Element;
|
|
5
9
|
declare namespace Calendar {
|
|
6
10
|
var displayName: string;
|
|
@@ -61,18 +61,21 @@ var icons_1 = require("../../icons");
|
|
|
61
61
|
var react_day_picker_1 = require("react-day-picker");
|
|
62
62
|
var twmerge_1 = require("../../utils/twmerge");
|
|
63
63
|
var CaretLeft = icons_1.icons.CaretLeft, CaretRight = icons_1.icons.CaretRight;
|
|
64
|
+
if (!CaretLeft || !CaretRight) {
|
|
65
|
+
console.error('Required icons are not available calender carets');
|
|
66
|
+
}
|
|
64
67
|
function Calendar(_a) {
|
|
65
68
|
var className = _a.className, classNames = _a.classNames, _b = _a.showOutsideDays, showOutsideDays = _b === void 0 ? true : _b, props = __rest(_a, ["className", "classNames", "showOutsideDays"]);
|
|
66
|
-
return (React.createElement(react_day_picker_1.DayPicker, __assign({ showOutsideDays: showOutsideDays, className: (0, twmerge_1.cn)("p-3", className), classNames: __assign({ months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0", month: "space-y-4", caption: "flex justify-center pt-1 relative items-center", caption_label: "text-sm font-medium", nav: "space-x-1 flex items-center", nav_button: "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100", nav_button_previous: "absolute left-1", nav_button_next: "absolute right-1", table: "w-full border-collapse space-y-1", head_row: "flex", head_cell: "text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]", row: "flex w-full mt-2", cell: (0, twmerge_1.cn)("relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md", props.mode === "range"
|
|
69
|
+
return (React.createElement(react_day_picker_1.DayPicker, __assign({ showOutsideDays: showOutsideDays, className: (0, twmerge_1.cn)("p-3", className !== null && className !== void 0 ? className : ''), classNames: __assign({ months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0", month: "space-y-4", caption: "flex justify-center pt-1 relative items-center", caption_label: "text-sm font-medium", nav: "space-x-1 flex items-center", nav_button: "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100", nav_button_previous: "absolute left-1", nav_button_next: "absolute right-1", table: "w-full border-collapse space-y-1", head_row: "flex", head_cell: "text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]", row: "flex w-full mt-2", cell: (0, twmerge_1.cn)("relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md", (props === null || props === void 0 ? void 0 : props.mode) === "range"
|
|
67
70
|
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
|
|
68
71
|
: "[&:has([aria-selected])]:rounded-md"), day: "h-8 w-8 p-0 font-normal aria-selected:opacity-100", day_range_start: "day-range-start", day_range_end: "day-range-end", day_selected: "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground", day_today: "bg-accent text-accent-foreground", day_outside: "day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground", day_disabled: "text-muted-foreground opacity-50", day_range_middle: "aria-selected:bg-accent aria-selected:text-accent-foreground", day_hidden: "invisible" }, classNames), components: {
|
|
69
72
|
IconLeft: function (_a) {
|
|
70
73
|
var className = _a.className, props = __rest(_a, ["className"]);
|
|
71
|
-
return (React.createElement(CaretLeft, __assign({ className: (0, twmerge_1.cn)("h-4 w-4", className) }, props)));
|
|
74
|
+
return (React.createElement(CaretLeft, __assign({ className: (0, twmerge_1.cn)("h-4 w-4", className !== null && className !== void 0 ? className : '') }, props)));
|
|
72
75
|
},
|
|
73
76
|
IconRight: function (_a) {
|
|
74
77
|
var className = _a.className, props = __rest(_a, ["className"]);
|
|
75
|
-
return (React.createElement(CaretRight, __assign({ className: (0, twmerge_1.cn)("h-4 w-4", className) }, props)));
|
|
78
|
+
return (React.createElement(CaretRight, __assign({ className: (0, twmerge_1.cn)("h-4 w-4", className !== null && className !== void 0 ? className : '') }, props)));
|
|
76
79
|
},
|
|
77
80
|
} }, props)));
|
|
78
81
|
}
|
|
@@ -54,21 +54,22 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
54
54
|
}
|
|
55
55
|
return t;
|
|
56
56
|
};
|
|
57
|
+
var _a;
|
|
57
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
59
|
exports.PopoverAnchor = exports.PopoverContent = exports.PopoverTrigger = exports.Popover = void 0;
|
|
59
60
|
var React = __importStar(require("react"));
|
|
60
61
|
var PopoverPrimitive = __importStar(require("@radix-ui/react-popover"));
|
|
61
62
|
var twmerge_1 = require("../../utils/twmerge");
|
|
62
|
-
var Popover = PopoverPrimitive.Root;
|
|
63
|
+
var Popover = (PopoverPrimitive === null || PopoverPrimitive === void 0 ? void 0 : PopoverPrimitive.Root) || null;
|
|
63
64
|
exports.Popover = Popover;
|
|
64
|
-
var PopoverTrigger = PopoverPrimitive.Trigger;
|
|
65
|
+
var PopoverTrigger = (PopoverPrimitive === null || PopoverPrimitive === void 0 ? void 0 : PopoverPrimitive.Trigger) || null;
|
|
65
66
|
exports.PopoverTrigger = PopoverTrigger;
|
|
66
|
-
var PopoverAnchor = PopoverPrimitive.Anchor;
|
|
67
|
+
var PopoverAnchor = (PopoverPrimitive === null || PopoverPrimitive === void 0 ? void 0 : PopoverPrimitive.Anchor) || null;
|
|
67
68
|
exports.PopoverAnchor = PopoverAnchor;
|
|
68
69
|
var PopoverContent = React.forwardRef(function (_a, ref) {
|
|
69
70
|
var className = _a.className, _b = _a.align, align = _b === void 0 ? "center" : _b, _c = _a.sideOffset, sideOffset = _c === void 0 ? 4 : _c, props = __rest(_a, ["className", "align", "sideOffset"]);
|
|
70
|
-
return (React.createElement(PopoverPrimitive.Portal, null,
|
|
71
|
-
React.createElement(PopoverPrimitive.Content, __assign({ ref: ref, align: align, sideOffset: sideOffset, className: (0, twmerge_1.cn)("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className) }, props))));
|
|
71
|
+
return ((PopoverPrimitive === null || PopoverPrimitive === void 0 ? void 0 : PopoverPrimitive.Portal) ? (React.createElement(PopoverPrimitive.Portal, null,
|
|
72
|
+
React.createElement(PopoverPrimitive.Content, __assign({ ref: ref, align: align, sideOffset: sideOffset, className: (0, twmerge_1.cn)("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className) }, props)))) : null);
|
|
72
73
|
});
|
|
73
74
|
exports.PopoverContent = PopoverContent;
|
|
74
|
-
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
|
75
|
+
PopoverContent.displayName = ((_a = PopoverPrimitive === null || PopoverPrimitive === void 0 ? void 0 : PopoverPrimitive.Content) === null || _a === void 0 ? void 0 : _a.displayName) || 'PopoverContent';
|
|
@@ -44,102 +44,146 @@ function DatePickerWithRangeV3(_a) {
|
|
|
44
44
|
var className = _a.className, _b = _a.value, value = _b === void 0 ? [null, null] : _b, onChange = _a.onChange, id = _a.id, _c = _a.readOnly, readOnly = _c === void 0 ? false : _c, _d = _a.futureDateOnly, futureDateOnly = _d === void 0 ? false : _d, _e = _a.previousDateOnly, previousDateOnly = _e === void 0 ? false : _e, _f = _a.allowPresentlyOngoing, allowPresentlyOngoing = _f === void 0 ? false : _f, _g = _a.invert, invert = _g === void 0 ? false : _g, _h = _a.disabled, disabled = _h === void 0 ? false : _h, _j = _a.debug, debug = _j === void 0 ? false : _j, _k = _a.startDateLabel, startDateLabel = _k === void 0 ? "Start Date" : _k, _l = _a.endDateLabel, endDateLabel = _l === void 0 ? "End Date" : _l, _m = _a.withPortal, withPortal = _m === void 0 ? false : _m;
|
|
45
45
|
var _o = (0, react_1.useState)(""), inputValue = _o[0], setInputValue = _o[1];
|
|
46
46
|
var _p = (0, react_1.useState)(false), isOpen = _p[0], setIsOpen = _p[1];
|
|
47
|
+
// Ensure we have valid dates or null
|
|
48
|
+
var safeValue = Array.isArray(value) ? value : [null, null];
|
|
49
|
+
var _q = safeValue.map(function (date) {
|
|
50
|
+
return date instanceof Date && (0, date_fns_1.isValid)(date) ? date : null;
|
|
51
|
+
}), startDate = _q[0], endDate = _q[1];
|
|
47
52
|
var currentDate = new Date();
|
|
48
53
|
currentDate.setHours(0, 0, 0, 0);
|
|
49
54
|
var yesterday = new Date(currentDate);
|
|
50
55
|
yesterday.setDate(currentDate.getDate() - 1);
|
|
51
56
|
// Update input value when controlled value changes
|
|
52
57
|
(0, react_1.useEffect)(function () {
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
try {
|
|
59
|
+
if (startDate) {
|
|
60
|
+
if (endDate === null) {
|
|
61
|
+
setInputValue("".concat((0, date_fns_1.format)(startDate, "PP"), " - Ongoing"));
|
|
62
|
+
}
|
|
63
|
+
else if (endDate) {
|
|
64
|
+
setInputValue("".concat((0, date_fns_1.format)(startDate, "PP"), " - ").concat((0, date_fns_1.format)(endDate, "PP")));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
setInputValue((0, date_fns_1.format)(startDate, "PP"));
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
else {
|
|
61
|
-
setInputValue(
|
|
71
|
+
setInputValue("");
|
|
62
72
|
}
|
|
63
73
|
}
|
|
64
|
-
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error('Error formatting dates:', error);
|
|
65
76
|
setInputValue("");
|
|
66
77
|
}
|
|
67
|
-
}, [
|
|
78
|
+
}, [startDate, endDate]);
|
|
68
79
|
var handleInputChange = function (inputVal) {
|
|
80
|
+
if (!inputVal || typeof inputVal !== 'string')
|
|
81
|
+
return;
|
|
69
82
|
setInputValue(inputVal);
|
|
70
83
|
if (readOnly)
|
|
71
84
|
return;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
85
|
+
try {
|
|
86
|
+
var dates = inputVal.split("-").map(function (d) { return d === null || d === void 0 ? void 0 : d.trim(); }).filter(Boolean);
|
|
87
|
+
if (dates.length === 2) {
|
|
88
|
+
var fromDate = (0, date_fns_1.parse)(dates[0], "PP", new Date());
|
|
89
|
+
var toDate = dates[1].toLowerCase() === "ongoing" ? null :
|
|
90
|
+
(0, date_fns_1.parse)(dates[1], "PP", new Date());
|
|
91
|
+
if ((0, date_fns_1.isValid)(fromDate) && (toDate === null || (0, date_fns_1.isValid)(toDate))) {
|
|
92
|
+
if (isDateValid(fromDate) && (toDate === null || isDateValid(toDate))) {
|
|
93
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(id, [fromDate, toDate]);
|
|
94
|
+
}
|
|
80
95
|
}
|
|
81
96
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
else if (dates.length === 1) {
|
|
98
|
+
var singleDate = (0, date_fns_1.parse)(dates[0], "PP", new Date());
|
|
99
|
+
if ((0, date_fns_1.isValid)(singleDate) && isDateValid(singleDate)) {
|
|
100
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(id, [singleDate, undefined]);
|
|
101
|
+
}
|
|
87
102
|
}
|
|
88
103
|
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
console.error('Error parsing input dates:', error);
|
|
106
|
+
}
|
|
89
107
|
};
|
|
90
108
|
var isDateValid = function (date) {
|
|
91
|
-
if (!date)
|
|
109
|
+
if (!date || !(date instanceof Date))
|
|
110
|
+
return true;
|
|
111
|
+
try {
|
|
112
|
+
if (futureDateOnly && !invert) {
|
|
113
|
+
return isFuture(date) || (allowPresentlyOngoing && isToday(date));
|
|
114
|
+
}
|
|
115
|
+
if (previousDateOnly && !invert) {
|
|
116
|
+
return isPast(date) || isToday(date);
|
|
117
|
+
}
|
|
92
118
|
return true;
|
|
93
|
-
if (futureDateOnly && !invert) {
|
|
94
|
-
return isFuture(date) || (allowPresentlyOngoing && isToday(date));
|
|
95
119
|
}
|
|
96
|
-
|
|
97
|
-
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.error('Error validating date:', error);
|
|
122
|
+
return false;
|
|
98
123
|
}
|
|
99
|
-
return true;
|
|
100
124
|
};
|
|
101
125
|
var getMinDate = function (isEndDate) {
|
|
102
|
-
|
|
103
|
-
|
|
126
|
+
try {
|
|
127
|
+
if (futureDateOnly && !invert) {
|
|
128
|
+
return currentDate;
|
|
129
|
+
}
|
|
130
|
+
if (isEndDate && startDate && (0, date_fns_1.isValid)(startDate)) {
|
|
131
|
+
return startDate;
|
|
132
|
+
}
|
|
104
133
|
}
|
|
105
|
-
|
|
106
|
-
|
|
134
|
+
catch (error) {
|
|
135
|
+
console.error('Error getting min date:', error);
|
|
107
136
|
}
|
|
108
137
|
return undefined;
|
|
109
138
|
};
|
|
110
139
|
var getMaxDate = function () {
|
|
111
|
-
|
|
112
|
-
|
|
140
|
+
try {
|
|
141
|
+
if (previousDateOnly && !invert) {
|
|
142
|
+
return yesterday;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error('Error getting max date:', error);
|
|
113
147
|
}
|
|
114
148
|
return undefined;
|
|
115
149
|
};
|
|
116
150
|
var handleCalendarSelect = function (dates) {
|
|
117
151
|
if (readOnly)
|
|
118
152
|
return;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var from = dates.from, to = dates.to;
|
|
124
|
-
if (from && isDateValid(from)) {
|
|
125
|
-
if (to && isDateValid(to)) {
|
|
126
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(id, [from, to]);
|
|
127
|
-
setIsOpen(false);
|
|
153
|
+
try {
|
|
154
|
+
if (!dates) {
|
|
155
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(id, [null, null]);
|
|
156
|
+
return;
|
|
128
157
|
}
|
|
129
|
-
|
|
130
|
-
|
|
158
|
+
var _a = dates || {}, from = _a.from, to = _a.to;
|
|
159
|
+
if (from && isDateValid(from)) {
|
|
160
|
+
if (to && isDateValid(to)) {
|
|
161
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(id, [from, to]);
|
|
162
|
+
setIsOpen(false);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(id, [from, undefined]);
|
|
166
|
+
}
|
|
131
167
|
}
|
|
132
168
|
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
console.error('Error handling calendar selection:', error);
|
|
171
|
+
}
|
|
133
172
|
};
|
|
134
173
|
var handleOngoingToggle = function (checked) {
|
|
135
|
-
|
|
136
|
-
|
|
174
|
+
try {
|
|
175
|
+
if (startDate) {
|
|
176
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(id, [startDate, checked ? null : undefined]);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error('Error handling ongoing toggle:', error);
|
|
137
181
|
}
|
|
138
182
|
};
|
|
139
183
|
if (debug) {
|
|
140
184
|
console.log({
|
|
141
185
|
id: id,
|
|
142
|
-
value:
|
|
186
|
+
value: safeValue,
|
|
143
187
|
inputValue: inputValue,
|
|
144
188
|
isOpen: isOpen,
|
|
145
189
|
readOnly: readOnly,
|
|
@@ -156,158 +200,25 @@ function DatePickerWithRangeV3(_a) {
|
|
|
156
200
|
react_1.default.createElement(popover_1.PopoverTrigger, { asChild: true },
|
|
157
201
|
react_1.default.createElement("div", { className: "relative" },
|
|
158
202
|
react_1.default.createElement(TextInputs_1.TextInput, { id: id, placeholder: "Pick a date range", value: inputValue, onChange: function (id, value) { return handleInputChange(value); }, className: "w-[225px]", icon: "CalendarBlank", disabled: disabled, readOnly: readOnly }))),
|
|
159
|
-
react_1.default.createElement(popover_1.PopoverContent, { className: "w-auto p-0", align: "start" },
|
|
160
|
-
react_1.default.createElement(calendar_1.Calendar, { initialFocus: true, mode: "range", defaultMonth:
|
|
161
|
-
{ from:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (readOnly)
|
|
165
|
-
return true;
|
|
166
|
-
var minDate = getMinDate(false);
|
|
167
|
-
var maxDate = getMaxDate();
|
|
168
|
-
if (minDate && date < minDate)
|
|
203
|
+
!disabled && !readOnly && (react_1.default.createElement(popover_1.PopoverContent, { className: "w-auto p-0", align: "start" },
|
|
204
|
+
react_1.default.createElement(calendar_1.Calendar, { initialFocus: true, mode: "range", defaultMonth: startDate || undefined, selected: endDate === null ?
|
|
205
|
+
{ from: startDate, to: undefined } :
|
|
206
|
+
{ from: startDate, to: endDate }, onSelect: function (range) { return handleCalendarSelect(range); }, numberOfMonths: 2, disabled: function (date) {
|
|
207
|
+
if (!date || disabled || readOnly)
|
|
169
208
|
return true;
|
|
170
|
-
|
|
209
|
+
try {
|
|
210
|
+
var minDate = getMinDate(false);
|
|
211
|
+
var maxDate = getMaxDate();
|
|
212
|
+
if (minDate && date < minDate)
|
|
213
|
+
return true;
|
|
214
|
+
if (maxDate && date > maxDate)
|
|
215
|
+
return true;
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
console.error('Error in date disabled check:', error);
|
|
171
220
|
return true;
|
|
172
|
-
|
|
173
|
-
} }))),
|
|
174
|
-
debug && (react_1.default.createElement("pre", { className: "mt-4 p-4 bg-gray-100 rounded" }, JSON.stringify({ value:
|
|
221
|
+
}
|
|
222
|
+
} })))),
|
|
223
|
+
debug && (react_1.default.createElement("pre", { className: "mt-4 p-4 bg-gray-100 rounded" }, JSON.stringify({ value: safeValue, inputValue: inputValue }, null, 2))))));
|
|
175
224
|
}
|
|
176
|
-
// DatePickerWithRangeV3
|
|
177
|
-
// function DatePickerDemo() {
|
|
178
|
-
// const [date, setDate] = React.useState();
|
|
179
|
-
// return (
|
|
180
|
-
// <Popover>
|
|
181
|
-
// <PopoverTrigger asChild>
|
|
182
|
-
// <Button
|
|
183
|
-
// variant={"outline"}
|
|
184
|
-
// className={cn(
|
|
185
|
-
// "w-[280px] justify-start text-left font-normal",
|
|
186
|
-
// !date && "text-muted-foreground"
|
|
187
|
-
// )}
|
|
188
|
-
// >
|
|
189
|
-
// <CalendarIcon />
|
|
190
|
-
// {date ? format(date, "PPP") : <span>Pick a date</span>}
|
|
191
|
-
// </Button>
|
|
192
|
-
// </PopoverTrigger>
|
|
193
|
-
// <PopoverContent className="w-auto p-0">
|
|
194
|
-
// <Calendar
|
|
195
|
-
// mode="single"
|
|
196
|
-
// selected={date}
|
|
197
|
-
// onSelect={setDate}
|
|
198
|
-
// initialFocus
|
|
199
|
-
// />
|
|
200
|
-
// </PopoverContent>
|
|
201
|
-
// </Popover>
|
|
202
|
-
// );
|
|
203
|
-
// }
|
|
204
|
-
// function DatePickerWithRange({ className }) {
|
|
205
|
-
// const [date, setDate] = React.useState({
|
|
206
|
-
// from: new Date(2022, 0, 20),
|
|
207
|
-
// to: addDays(new Date(2022, 0, 20), 20),
|
|
208
|
-
// });
|
|
209
|
-
// return (
|
|
210
|
-
// <div className={cn("grid gap-2", className)}>
|
|
211
|
-
// <Popover>
|
|
212
|
-
// <PopoverTrigger asChild>
|
|
213
|
-
// <Button
|
|
214
|
-
// id="date"
|
|
215
|
-
// variant={"outline"}
|
|
216
|
-
// className={cn(
|
|
217
|
-
// "w-[300px] justify-start text-left font-normal",
|
|
218
|
-
// !date && "text-muted-foreground"
|
|
219
|
-
// )}
|
|
220
|
-
// >
|
|
221
|
-
// <CalendarIcon />
|
|
222
|
-
// {date?.from ? (
|
|
223
|
-
// date.to ? (
|
|
224
|
-
// <>
|
|
225
|
-
// {format(date.from, "LLL dd, y")} -{" "}
|
|
226
|
-
// {format(date.to, "LLL dd, y")}
|
|
227
|
-
// </>
|
|
228
|
-
// ) : (
|
|
229
|
-
// format(date.from, "LLL dd, y")
|
|
230
|
-
// )
|
|
231
|
-
// ) : (
|
|
232
|
-
// <span>Pick a date</span>
|
|
233
|
-
// )}
|
|
234
|
-
// </Button>
|
|
235
|
-
// </PopoverTrigger>
|
|
236
|
-
// <PopoverContent className="w-auto p-0" align="start">
|
|
237
|
-
// <Calendar
|
|
238
|
-
// initialFocus
|
|
239
|
-
// mode="range"
|
|
240
|
-
// defaultMonth={date?.from}
|
|
241
|
-
// selected={date}
|
|
242
|
-
// onSelect={setDate}
|
|
243
|
-
// numberOfMonths={2}
|
|
244
|
-
// />
|
|
245
|
-
// </PopoverContent>
|
|
246
|
-
// </Popover>
|
|
247
|
-
// </div>
|
|
248
|
-
// );
|
|
249
|
-
// }
|
|
250
|
-
// function DatePickerWithRange2({ className }) {
|
|
251
|
-
// const [date, setDate] = React.useState();
|
|
252
|
-
// const [inputValue, setInputValue] = React.useState("");
|
|
253
|
-
// const [isOpen, setIsOpen] = React.useState(false);
|
|
254
|
-
// const handleInputChange = (value) => {
|
|
255
|
-
// // const value = event.target.value;
|
|
256
|
-
// setInputValue(value);
|
|
257
|
-
// const dates = value.split("-").map((d) => d.trim());
|
|
258
|
-
// if (dates.length === 2) {
|
|
259
|
-
// const fromDate = parse(dates[0], "PP", new Date());
|
|
260
|
-
// const toDate = parse(dates[1], "PP", new Date());
|
|
261
|
-
// if (isValid(fromDate) && isValid(toDate)) {
|
|
262
|
-
// setDate({ from: fromDate, to: toDate });
|
|
263
|
-
// }
|
|
264
|
-
// } else if (dates.length === 1) {
|
|
265
|
-
// const singleDate = parse(dates[0], "PP", new Date());
|
|
266
|
-
// if (isValid(singleDate)) {
|
|
267
|
-
// setDate({ from: singleDate, to: undefined });
|
|
268
|
-
// }
|
|
269
|
-
// }
|
|
270
|
-
// };
|
|
271
|
-
// React.useEffect(() => {
|
|
272
|
-
// if (date?.from) {
|
|
273
|
-
// if (date.to) {
|
|
274
|
-
// setInputValue(`${format(date.from, "PP")} - ${format(date.to, "PP")}`);
|
|
275
|
-
// } else {
|
|
276
|
-
// setInputValue(format(date.from, "PP"));
|
|
277
|
-
// }
|
|
278
|
-
// }
|
|
279
|
-
// }, [date]);
|
|
280
|
-
// return (
|
|
281
|
-
// <div className={cn("grid gap-2", className)}>
|
|
282
|
-
// <Popover open={isOpen} onOpenChange={setIsOpen}>
|
|
283
|
-
// <PopoverTrigger asChild>
|
|
284
|
-
// <div className="relative">
|
|
285
|
-
// <TextInput
|
|
286
|
-
// id="date"
|
|
287
|
-
// placeholder="Pick a date range"
|
|
288
|
-
// value={inputValue}
|
|
289
|
-
// onChange={(id, value) => handleInputChange(value)}
|
|
290
|
-
// className="w-max"
|
|
291
|
-
// icon={"CalendarBlank"}
|
|
292
|
-
// />
|
|
293
|
-
// </div>
|
|
294
|
-
// </PopoverTrigger>
|
|
295
|
-
// <PopoverContent className="w-auto p-0" align="start">
|
|
296
|
-
// <Calendar
|
|
297
|
-
// initialFocus
|
|
298
|
-
// mode="range"
|
|
299
|
-
// defaultMonth={date?.from}
|
|
300
|
-
// selected={date}
|
|
301
|
-
// onSelect={(newDate) => {
|
|
302
|
-
// setDate(newDate);
|
|
303
|
-
// if (newDate?.to) {
|
|
304
|
-
// setIsOpen(false);
|
|
305
|
-
// }
|
|
306
|
-
// }}
|
|
307
|
-
// numberOfMonths={2}
|
|
308
|
-
// />
|
|
309
|
-
// </PopoverContent>
|
|
310
|
-
// </Popover>
|
|
311
|
-
// </div>
|
|
312
|
-
// );
|
|
313
|
-
// }
|