nearpay-datepicker-react 0.4.0 → 0.5.0
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.
- package/dist/components/TimePicker.d.ts +2 -0
- package/dist/contexts/DatepickerContext.d.ts +9 -1
- package/dist/index.cjs.js +171 -28
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +171 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/types/index.d.ts +12 -0
- package/package.json +1 -1
- package/LICENSE +0 -21
package/dist/index.esm.js
CHANGED
|
@@ -1660,7 +1660,15 @@ const DatepickerContext = createContext({
|
|
|
1660
1660
|
toggleClassName: "",
|
|
1661
1661
|
toggleIcon: undefined,
|
|
1662
1662
|
updateFirstDate: () => { },
|
|
1663
|
-
value: null
|
|
1663
|
+
value: null,
|
|
1664
|
+
useRange: true,
|
|
1665
|
+
showTimePicker: false,
|
|
1666
|
+
timeOnly: false,
|
|
1667
|
+
timeFormat: "24",
|
|
1668
|
+
startTime: { hour: 0, minute: 0 },
|
|
1669
|
+
endTime: { hour: 0, minute: 0 },
|
|
1670
|
+
changeStartTime: () => { },
|
|
1671
|
+
changeEndTime: () => { }
|
|
1664
1672
|
});
|
|
1665
1673
|
|
|
1666
1674
|
var isBetween$1 = {exports: {}};
|
|
@@ -2792,7 +2800,7 @@ const SecondaryButton = (props) => {
|
|
|
2792
2800
|
|
|
2793
2801
|
const Footer = () => {
|
|
2794
2802
|
// Contexts
|
|
2795
|
-
const { hideDatepicker, period, changeDatepickerValue, configs, classNames } = useContext(DatepickerContext);
|
|
2803
|
+
const { hideDatepicker, period, changeDatepickerValue, configs, classNames, showTimePicker, timeOnly, startTime, endTime } = useContext(DatepickerContext);
|
|
2796
2804
|
// Functions
|
|
2797
2805
|
const getClassName = useCallback(() => {
|
|
2798
2806
|
if (typeof classNames !== "undefined" && typeof classNames?.footer === "function") {
|
|
@@ -2803,14 +2811,32 @@ const Footer = () => {
|
|
|
2803
2811
|
return (jsxRuntimeExports.jsx("div", { className: getClassName(), children: jsxRuntimeExports.jsxs("div", { className: "w-full md:w-auto flex items-center justify-center gap-3", children: [jsxRuntimeExports.jsx(SecondaryButton, { onClick: () => {
|
|
2804
2812
|
hideDatepicker();
|
|
2805
2813
|
}, children: jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: configs?.footer?.cancel ? configs.footer.cancel : "Cancel" }) }), jsxRuntimeExports.jsx(PrimaryButton, { onClick: () => {
|
|
2806
|
-
if (
|
|
2814
|
+
if (timeOnly) {
|
|
2815
|
+
const now = new Date();
|
|
2816
|
+
const startDate = new Date(now);
|
|
2817
|
+
startDate.setHours(startTime.hour, startTime.minute, 0, 0);
|
|
2818
|
+
const endDate = new Date(now);
|
|
2819
|
+
endDate.setHours(endTime.hour, endTime.minute, 0, 0);
|
|
2807
2820
|
changeDatepickerValue({
|
|
2808
|
-
startDate
|
|
2809
|
-
endDate
|
|
2821
|
+
startDate,
|
|
2822
|
+
endDate
|
|
2810
2823
|
});
|
|
2811
2824
|
hideDatepicker();
|
|
2812
2825
|
}
|
|
2813
|
-
|
|
2826
|
+
else if (period.start && period.end) {
|
|
2827
|
+
const startDate = new Date(period.start);
|
|
2828
|
+
const endDate = new Date(period.end);
|
|
2829
|
+
if (showTimePicker) {
|
|
2830
|
+
startDate.setHours(startTime.hour, startTime.minute, 0, 0);
|
|
2831
|
+
endDate.setHours(endTime.hour, endTime.minute, 0, 0);
|
|
2832
|
+
}
|
|
2833
|
+
changeDatepickerValue({
|
|
2834
|
+
startDate,
|
|
2835
|
+
endDate
|
|
2836
|
+
});
|
|
2837
|
+
hideDatepicker();
|
|
2838
|
+
}
|
|
2839
|
+
}, disabled: !timeOnly && !(period.start && period.end), children: jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: configs?.footer?.apply ? configs.footer.apply : "Apply" }) })] }) }));
|
|
2814
2840
|
};
|
|
2815
2841
|
|
|
2816
2842
|
const CloseIcon = (props) => {
|
|
@@ -2829,7 +2855,7 @@ const ToggleButton = (e) => {
|
|
|
2829
2855
|
|
|
2830
2856
|
const Input = (e) => {
|
|
2831
2857
|
// Context
|
|
2832
|
-
const { primaryColor, period, dayHover, changeDayHover, calendarContainer, arrowContainer, inputText, changeInputText, hideDatepicker, changeDatepickerValue, asSingle, placeholder, separator, disabled, inputClassName, toggleClassName, toggleIcon, readOnly, displayFormat, inputId, inputName, classNames, popoverDirection, required } = useContext(DatepickerContext);
|
|
2858
|
+
const { primaryColor, period, dayHover, changeDayHover, calendarContainer, arrowContainer, inputText, changeInputText, hideDatepicker, changeDatepickerValue, asSingle, placeholder, separator, disabled, inputClassName, toggleClassName, toggleIcon, readOnly, displayFormat, inputId, inputName, classNames, popoverDirection, required, showTimePicker, timeOnly, timeFormat } = useContext(DatepickerContext);
|
|
2833
2859
|
// UseRefs
|
|
2834
2860
|
const buttonRef = useRef(null);
|
|
2835
2861
|
const inputRef = useRef(null);
|
|
@@ -2985,9 +3011,9 @@ const Input = (e) => {
|
|
|
2985
3011
|
div.classList.add("mb-2.5");
|
|
2986
3012
|
div.classList.remove("mt-2.5");
|
|
2987
3013
|
arrow.classList.add("-bottom-2");
|
|
2988
|
-
arrow.classList.add("border-
|
|
3014
|
+
arrow.classList.add("border-r");
|
|
2989
3015
|
arrow.classList.add("border-b");
|
|
2990
|
-
arrow.classList.remove("border-
|
|
3016
|
+
arrow.classList.remove("border-l");
|
|
2991
3017
|
arrow.classList.remove("border-t");
|
|
2992
3018
|
}
|
|
2993
3019
|
setTimeout(() => {
|
|
@@ -3009,7 +3035,9 @@ const Input = (e) => {
|
|
|
3009
3035
|
}, [calendarContainer, arrowContainer, popoverDirection]);
|
|
3010
3036
|
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("input", { ref: inputRef, type: "text", className: getClassName(), disabled: disabled, readOnly: readOnly, required: required, placeholder: placeholder
|
|
3011
3037
|
? placeholder
|
|
3012
|
-
:
|
|
3038
|
+
: timeOnly
|
|
3039
|
+
? `${timeFormat === "12" ? "hh:mm AM" : "HH:mm"}${asSingle ? "" : ` ${separator} ${timeFormat === "12" ? "hh:mm AM" : "HH:mm"}`}`
|
|
3040
|
+
: `${displayFormat}${showTimePicker ? ` ${timeFormat === "12" ? "hh:mm AM" : "HH:mm"}` : ""}${asSingle ? "" : ` ${separator} ${displayFormat}${showTimePicker ? ` ${timeFormat === "12" ? "hh:mm AM" : "HH:mm"}` : ""}`}`, value: inputText, id: inputId, name: inputName, autoComplete: "off", role: "presentation", onChange: handleInputChange, onKeyDown: handleInputKeyDown }), jsxRuntimeExports.jsx("button", { type: "button", ref: buttonRef, disabled: disabled, className: getToggleClassName(), children: renderToggleIcon(inputText == null || !inputText?.length) })] }));
|
|
3013
3041
|
};
|
|
3014
3042
|
|
|
3015
3043
|
const CURRENT_DATE = new Date();
|
|
@@ -3157,6 +3185,77 @@ const Shortcuts = () => {
|
|
|
3157
3185
|
: printItemText(item) }) }, index))) }) })) : null;
|
|
3158
3186
|
};
|
|
3159
3187
|
|
|
3188
|
+
const TimeColumn = ({ value, max, onChange, label, pad = 2 }) => {
|
|
3189
|
+
const { primaryColor } = useContext(DatepickerContext);
|
|
3190
|
+
const prev = (value - 1 + max) % max;
|
|
3191
|
+
const next = (value + 1) % max;
|
|
3192
|
+
const format = (n) => String(n).padStart(pad, "0");
|
|
3193
|
+
const bgActive = BG_COLOR["500"][primaryColor];
|
|
3194
|
+
const bgHover = BG_COLOR.hover[primaryColor];
|
|
3195
|
+
return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-0.5", children: [jsxRuntimeExports.jsx("span", { className: "text-[10px] text-gray-400 dark:text-white/40 uppercase tracking-wider", children: label }), jsxRuntimeExports.jsx("button", { type: "button", className: "p-1 rounded-full hover:bg-gray-100 dark:hover:bg-white/10 transition-colors duration-200 cursor-pointer", onClick: () => onChange(prev), children: jsxRuntimeExports.jsx("svg", { className: "w-4 h-4 text-gray-500 dark:text-white/60", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 2, stroke: "currentColor", children: jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4.5 15.75l7.5-7.5 7.5 7.5" }) }) }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [jsxRuntimeExports.jsx("span", { className: "text-xs text-gray-300 dark:text-white/20 h-6 flex items-center tabular-nums", children: format(prev) }), jsxRuntimeExports.jsx("span", { className: classNames("text-base font-semibold text-white h-8 w-10 flex items-center justify-center rounded-lg tabular-nums", bgActive, bgHover), children: format(value) }), jsxRuntimeExports.jsx("span", { className: "text-xs text-gray-300 dark:text-white/20 h-6 flex items-center tabular-nums", children: format(next) })] }), jsxRuntimeExports.jsx("button", { type: "button", className: "p-1 rounded-full hover:bg-gray-100 dark:hover:bg-white/10 transition-colors duration-200 cursor-pointer", onClick: () => onChange(next), children: jsxRuntimeExports.jsx("svg", { className: "w-4 h-4 text-gray-500 dark:text-white/60", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 2, stroke: "currentColor", children: jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19.5 8.25l-7.5 7.5-7.5-7.5" }) }) })] }));
|
|
3196
|
+
};
|
|
3197
|
+
const AmPmToggle = ({ isAm, onChange }) => {
|
|
3198
|
+
const { primaryColor } = useContext(DatepickerContext);
|
|
3199
|
+
const bgActive = BG_COLOR["500"][primaryColor];
|
|
3200
|
+
return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-0.5 ms-1", children: [jsxRuntimeExports.jsx("span", { className: "text-[10px] text-gray-400 dark:text-white/40 uppercase tracking-wider", children: "\u00A0" }), jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-1 mt-[26px]", children: [jsxRuntimeExports.jsx("button", { type: "button", className: classNames("text-xs font-medium px-2 py-1 rounded-md transition-all duration-200 cursor-pointer", isAm
|
|
3201
|
+
? bgActive + " text-white"
|
|
3202
|
+
: "text-gray-400 hover:bg-gray-100 dark:hover:bg-white/10 dark:text-white/50"), onClick: () => onChange(true), children: "AM" }), jsxRuntimeExports.jsx("button", { type: "button", className: classNames("text-xs font-medium px-2 py-1 rounded-md transition-all duration-200 cursor-pointer", !isAm
|
|
3203
|
+
? bgActive + " text-white"
|
|
3204
|
+
: "text-gray-400 hover:bg-gray-100 dark:hover:bg-white/10 dark:text-white/50"), onClick: () => onChange(false), children: "PM" })] })] }));
|
|
3205
|
+
};
|
|
3206
|
+
const SingleTimePicker = ({ time, onChange, label }) => {
|
|
3207
|
+
const { timeFormat, primaryColor } = useContext(DatepickerContext);
|
|
3208
|
+
const is12h = timeFormat === "12";
|
|
3209
|
+
const displayHour = useMemo(() => {
|
|
3210
|
+
if (!is12h)
|
|
3211
|
+
return time.hour;
|
|
3212
|
+
if (time.hour === 0)
|
|
3213
|
+
return 12;
|
|
3214
|
+
if (time.hour > 12)
|
|
3215
|
+
return time.hour - 12;
|
|
3216
|
+
return time.hour;
|
|
3217
|
+
}, [is12h, time.hour]);
|
|
3218
|
+
const isAm = time.hour < 12;
|
|
3219
|
+
const handleHourChange = useCallback((newDisplayHour) => {
|
|
3220
|
+
let hour24;
|
|
3221
|
+
if (is12h) {
|
|
3222
|
+
if (isAm) {
|
|
3223
|
+
hour24 = newDisplayHour === 12 ? 0 : newDisplayHour;
|
|
3224
|
+
}
|
|
3225
|
+
else {
|
|
3226
|
+
hour24 = newDisplayHour === 12 ? 12 : newDisplayHour + 12;
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
else {
|
|
3230
|
+
hour24 = newDisplayHour;
|
|
3231
|
+
}
|
|
3232
|
+
onChange({ ...time, hour: hour24 });
|
|
3233
|
+
}, [is12h, isAm, onChange, time]);
|
|
3234
|
+
const handleMinuteChange = useCallback((minute) => {
|
|
3235
|
+
onChange({ ...time, minute });
|
|
3236
|
+
}, [onChange, time]);
|
|
3237
|
+
const handleAmPmChange = useCallback((newIsAm) => {
|
|
3238
|
+
let newHour;
|
|
3239
|
+
if (newIsAm && !isAm) {
|
|
3240
|
+
newHour = time.hour - 12;
|
|
3241
|
+
}
|
|
3242
|
+
else if (!newIsAm && isAm) {
|
|
3243
|
+
newHour = time.hour + 12;
|
|
3244
|
+
}
|
|
3245
|
+
else {
|
|
3246
|
+
return;
|
|
3247
|
+
}
|
|
3248
|
+
onChange({ ...time, hour: newHour });
|
|
3249
|
+
}, [isAm, onChange, time]);
|
|
3250
|
+
const textColor = TEXT_COLOR["600"][primaryColor];
|
|
3251
|
+
return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [jsxRuntimeExports.jsx("span", { className: classNames("text-xs font-medium mb-1", textColor), children: label }), jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1", children: [jsxRuntimeExports.jsx(TimeColumn, { value: is12h ? displayHour : time.hour, max: is12h ? 13 : 24, onChange: handleHourChange, label: "Hr", pad: 2 }), jsxRuntimeExports.jsx("span", { className: "text-lg font-bold text-gray-400 dark:text-white/40 mt-5", children: ":" }), jsxRuntimeExports.jsx(TimeColumn, { value: time.minute, max: 60, onChange: handleMinuteChange, label: "Min", pad: 2 }), is12h && jsxRuntimeExports.jsx(AmPmToggle, { isAm: isAm, onChange: handleAmPmChange })] })] }));
|
|
3252
|
+
};
|
|
3253
|
+
const TimePicker = () => {
|
|
3254
|
+
const { asSingle, startTime, endTime, changeStartTime, changeEndTime, useRange } = useContext(DatepickerContext);
|
|
3255
|
+
const showSingle = asSingle || !useRange;
|
|
3256
|
+
return (jsxRuntimeExports.jsxs("div", { className: classNames("flex py-3 px-2 border-t border-gray-200 dark:border-zinc-700", showSingle ? "justify-center" : "justify-around"), children: [jsxRuntimeExports.jsx(SingleTimePicker, { time: startTime, onChange: changeStartTime, label: showSingle ? "Time" : "Start Time" }), !showSingle && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("div", { className: "w-px bg-gray-200 dark:bg-zinc-700 mx-2" }), jsxRuntimeExports.jsx(SingleTimePicker, { time: endTime, onChange: changeEndTime, label: "End Time" })] }))] }));
|
|
3257
|
+
};
|
|
3258
|
+
|
|
3160
3259
|
function useOnClickOutside(ref, handler) {
|
|
3161
3260
|
useEffect(() => {
|
|
3162
3261
|
const listener = (event) => {
|
|
@@ -3175,7 +3274,7 @@ function useOnClickOutside(ref, handler) {
|
|
|
3175
3274
|
}
|
|
3176
3275
|
|
|
3177
3276
|
const Arrow = forwardRef((props, ref) => {
|
|
3178
|
-
return (jsxRuntimeExports.jsx("div", { ...props, ref: ref, className: "absolute z-20 h-4 w-4 rotate-45 mt-0.5
|
|
3277
|
+
return (jsxRuntimeExports.jsx("div", { ...props, ref: ref, className: "absolute z-20 h-4 w-4 rotate-45 mt-0.5 ml-[1.2rem] border-l rtl:ml-0 rtl:mr-[1.2rem] border-t border-gray-300 bg-white dark:bg-zinc-800 dark:border-zinc-700" }));
|
|
3179
3278
|
});
|
|
3180
3279
|
Arrow.displayName = "Arrow";
|
|
3181
3280
|
|
|
@@ -3188,7 +3287,7 @@ const VerticalDash = () => {
|
|
|
3188
3287
|
|
|
3189
3288
|
const Datepicker = (props) => {
|
|
3190
3289
|
// Props
|
|
3191
|
-
const { asSingle = false, classNames = undefined, configs = undefined, containerClassName = null, dateLooking = DEFAULT_DATE_LOOKING, disabledDates = null, disabled = false, displayFormat = DATE_FORMAT, i18n = LANGUAGE, inputClassName = null, inputId, inputName, minDate = undefined, maxDate = undefined, onChange, placeholder = null, popupClassName = null, popoverDirection = undefined, primaryColor = DEFAULT_COLOR, separator = DEFAULT_SEPARATOR, showFooter = false, showShortcuts = false, startFrom = null, startWeekOn = START_WEEK, readOnly = false, required = false, toggleClassName = null, toggleIcon = undefined, useRange = true, value = null } = props;
|
|
3290
|
+
const { asSingle = false, classNames = undefined, configs = undefined, containerClassName = null, dateLooking = DEFAULT_DATE_LOOKING, disabledDates = null, disabled = false, displayFormat = DATE_FORMAT, i18n = LANGUAGE, inputClassName = null, inputId, inputName, minDate = undefined, maxDate = undefined, onChange, placeholder = null, popupClassName = null, popoverDirection = undefined, primaryColor = DEFAULT_COLOR, separator = DEFAULT_SEPARATOR, showFooter = false, showShortcuts = false, startFrom = null, startWeekOn = START_WEEK, readOnly = false, required = false, showTimePicker = false, timeOnly = false, timeFormat = "24", defaultTime = undefined, toggleClassName = null, toggleIcon = undefined, useRange = true, value = null } = props;
|
|
3192
3291
|
// Refs
|
|
3193
3292
|
const containerRef = useRef(null);
|
|
3194
3293
|
const calendarContainerRef = useRef(null);
|
|
@@ -3203,6 +3302,8 @@ const Datepicker = (props) => {
|
|
|
3203
3302
|
const [dayHover, setDayHover] = useState(null);
|
|
3204
3303
|
const [inputText, setInputText] = useState("");
|
|
3205
3304
|
const [inputRef, setInputRef] = useState(createRef());
|
|
3305
|
+
const [startTime, setStartTime] = useState(defaultTime?.start ?? { hour: 0, minute: 0 });
|
|
3306
|
+
const [endTime, setEndTime] = useState(defaultTime?.end ?? { hour: 0, minute: 0 });
|
|
3206
3307
|
// Custom Hooks use
|
|
3207
3308
|
useOnClickOutside(containerRef, () => {
|
|
3208
3309
|
const container = containerRef.current;
|
|
@@ -3226,9 +3327,9 @@ const Datepicker = (props) => {
|
|
|
3226
3327
|
div.classList.add("mb-2.5");
|
|
3227
3328
|
div.classList.add("mt-2.5");
|
|
3228
3329
|
arrow.classList.remove("-bottom-2");
|
|
3229
|
-
arrow.classList.remove("border-
|
|
3330
|
+
arrow.classList.remove("border-r");
|
|
3230
3331
|
arrow.classList.remove("border-b");
|
|
3231
|
-
arrow.classList.add("border-
|
|
3332
|
+
arrow.classList.add("border-l");
|
|
3232
3333
|
arrow.classList.add("border-t");
|
|
3233
3334
|
}, 300);
|
|
3234
3335
|
}
|
|
@@ -3285,16 +3386,16 @@ const Datepicker = (props) => {
|
|
|
3285
3386
|
const containerCenter = (detail.right - detail.x) / 2 + detail.x;
|
|
3286
3387
|
const isRTL = i18n === "ar";
|
|
3287
3388
|
const alignRight = () => {
|
|
3288
|
-
arrow.classList.remove("
|
|
3289
|
-
arrow.classList.add("
|
|
3290
|
-
arrow.classList.add("
|
|
3291
|
-
calendarContainer.classList.add("
|
|
3389
|
+
arrow.classList.remove("ml-[1.2rem]");
|
|
3390
|
+
arrow.classList.add("right-0");
|
|
3391
|
+
arrow.classList.add("mr-3.5");
|
|
3392
|
+
calendarContainer.classList.add("right-0");
|
|
3292
3393
|
};
|
|
3293
3394
|
const alignLeft = () => {
|
|
3294
|
-
arrow.classList.add("
|
|
3295
|
-
arrow.classList.remove("
|
|
3296
|
-
arrow.classList.remove("
|
|
3297
|
-
calendarContainer.classList.remove("
|
|
3395
|
+
arrow.classList.add("ml-[1.2rem]");
|
|
3396
|
+
arrow.classList.remove("right-0");
|
|
3397
|
+
arrow.classList.remove("mr-3.5");
|
|
3398
|
+
calendarContainer.classList.remove("right-0");
|
|
3298
3399
|
};
|
|
3299
3400
|
if (popoverDirection === "down-left" || popoverDirection === "up-left") {
|
|
3300
3401
|
if (isRTL) {
|
|
@@ -3322,16 +3423,33 @@ const Datepicker = (props) => {
|
|
|
3322
3423
|
}
|
|
3323
3424
|
}
|
|
3324
3425
|
}, [popoverDirection, i18n]);
|
|
3426
|
+
const formatTimeValue = useCallback((time) => {
|
|
3427
|
+
if (timeFormat === "12") {
|
|
3428
|
+
const h = time.hour % 12 || 12;
|
|
3429
|
+
const ampm = time.hour < 12 ? "AM" : "PM";
|
|
3430
|
+
return `${String(h).padStart(2, "0")}:${String(time.minute).padStart(2, "0")} ${ampm}`;
|
|
3431
|
+
}
|
|
3432
|
+
return `${String(time.hour).padStart(2, "0")}:${String(time.minute).padStart(2, "0")}`;
|
|
3433
|
+
}, [timeFormat]);
|
|
3325
3434
|
useEffect(() => {
|
|
3435
|
+
if (timeOnly) {
|
|
3436
|
+
const timeStr = asSingle
|
|
3437
|
+
? formatTimeValue(startTime)
|
|
3438
|
+
: `${formatTimeValue(startTime)} ${separator} ${formatTimeValue(endTime)}`;
|
|
3439
|
+
setInputText(timeStr);
|
|
3440
|
+
return;
|
|
3441
|
+
}
|
|
3326
3442
|
if (value && value.startDate && value.endDate) {
|
|
3327
3443
|
if (dateIsSameOrBefore(value.startDate, value.endDate, "date")) {
|
|
3328
3444
|
setPeriod({
|
|
3329
3445
|
start: value.startDate,
|
|
3330
3446
|
end: value.endDate
|
|
3331
3447
|
});
|
|
3332
|
-
|
|
3448
|
+
const timeSuffix = showTimePicker ? ` ${formatTimeValue(startTime)}` : "";
|
|
3449
|
+
const endTimeSuffix = showTimePicker ? ` ${formatTimeValue(endTime)}` : "";
|
|
3450
|
+
setInputText(`${dateFormat(value.startDate, displayFormat, i18n)}${timeSuffix}${asSingle
|
|
3333
3451
|
? ""
|
|
3334
|
-
: ` ${separator} ${dateFormat(value.endDate, displayFormat, i18n)}`}`);
|
|
3452
|
+
: ` ${separator} ${dateFormat(value.endDate, displayFormat, i18n)}${endTimeSuffix}`}`);
|
|
3335
3453
|
}
|
|
3336
3454
|
}
|
|
3337
3455
|
if (value && value.startDate === null && value.endDate === null) {
|
|
@@ -3341,7 +3459,18 @@ const Datepicker = (props) => {
|
|
|
3341
3459
|
});
|
|
3342
3460
|
setInputText("");
|
|
3343
3461
|
}
|
|
3344
|
-
}, [
|
|
3462
|
+
}, [
|
|
3463
|
+
asSingle,
|
|
3464
|
+
value,
|
|
3465
|
+
displayFormat,
|
|
3466
|
+
separator,
|
|
3467
|
+
i18n,
|
|
3468
|
+
showTimePicker,
|
|
3469
|
+
timeOnly,
|
|
3470
|
+
startTime,
|
|
3471
|
+
endTime,
|
|
3472
|
+
formatTimeValue
|
|
3473
|
+
]);
|
|
3345
3474
|
useEffect(() => {
|
|
3346
3475
|
if (startFrom && dateIsValid(startFrom)) {
|
|
3347
3476
|
const startDate = value?.startDate;
|
|
@@ -3426,7 +3555,15 @@ const Datepicker = (props) => {
|
|
|
3426
3555
|
toggleClassName,
|
|
3427
3556
|
toggleIcon,
|
|
3428
3557
|
updateFirstDate: (newDate) => firstGotoDate(newDate),
|
|
3429
|
-
value
|
|
3558
|
+
value,
|
|
3559
|
+
showTimePicker,
|
|
3560
|
+
timeOnly,
|
|
3561
|
+
timeFormat,
|
|
3562
|
+
startTime,
|
|
3563
|
+
endTime,
|
|
3564
|
+
changeStartTime: (time) => setStartTime(time),
|
|
3565
|
+
changeEndTime: (time) => setEndTime(time),
|
|
3566
|
+
useRange
|
|
3430
3567
|
};
|
|
3431
3568
|
}, [
|
|
3432
3569
|
asSingle,
|
|
@@ -3460,7 +3597,13 @@ const Datepicker = (props) => {
|
|
|
3460
3597
|
inputRef,
|
|
3461
3598
|
popoverDirection,
|
|
3462
3599
|
required,
|
|
3463
|
-
firstGotoDate
|
|
3600
|
+
firstGotoDate,
|
|
3601
|
+
showTimePicker,
|
|
3602
|
+
timeOnly,
|
|
3603
|
+
timeFormat,
|
|
3604
|
+
startTime,
|
|
3605
|
+
endTime,
|
|
3606
|
+
useRange
|
|
3464
3607
|
]);
|
|
3465
3608
|
const containerClassNameOverload = useMemo(() => {
|
|
3466
3609
|
const defaultContainerClassName = "relative w-full text-gray-700";
|
|
@@ -3478,7 +3621,7 @@ const Datepicker = (props) => {
|
|
|
3478
3621
|
? popupClassName
|
|
3479
3622
|
: defaultPopupClassName;
|
|
3480
3623
|
}, [popupClassName]);
|
|
3481
|
-
return (jsxRuntimeExports.jsx(DatepickerContext.Provider, { value: contextValues, children: jsxRuntimeExports.jsxs("div", { className: containerClassNameOverload, ref: containerRef, children: [jsxRuntimeExports.jsx(Input, { setContextRef: setInputRef }), jsxRuntimeExports.jsxs("div", { className: popupClassNameOverload, ref: calendarContainerRef, children: [jsxRuntimeExports.jsx(Arrow, { ref: arrowRef }), jsxRuntimeExports.jsxs("div", { className: "mt-2.5 shadow-xs border border-gray-300 px-1 py-0.5 bg-white dark:bg-zinc-800 dark:text-white dark:border-zinc-700 rounded-lg", children: [jsxRuntimeExports.jsxs("div", { className: "flex flex-col lg:flex-row py-2", children: [showShortcuts && jsxRuntimeExports.jsx(Shortcuts, {}), jsxRuntimeExports.jsxs("div", { className: `flex items-stretch flex-col md:flex-row space-y-4 md:space-y-0 md:gap-x-1.5 ${showShortcuts ? "md:ps-2" : "md:ps-1"} pe-2 lg:pe-1`, children: [jsxRuntimeExports.jsx(Calendar, { date: firstDate, onClickPrevious: previousMonthFirst, onClickNext: nextMonthFirst, changeMonth: changeFirstMonth, changeYear: changeFirstYear, minDate: minDate, maxDate: maxDate }), useRange && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("div", { className: "flex items-center", children: jsxRuntimeExports.jsx(VerticalDash, {}) }), jsxRuntimeExports.jsx(Calendar, { date: secondDate, onClickPrevious: previousMonthSecond, onClickNext: nextMonthSecond, changeMonth: changeSecondMonth, changeYear: changeSecondYear, minDate: minDate, maxDate: maxDate })] }))] })] }), showFooter && jsxRuntimeExports.jsx(Footer, {})] })] })] }) }));
|
|
3624
|
+
return (jsxRuntimeExports.jsx(DatepickerContext.Provider, { value: contextValues, children: jsxRuntimeExports.jsxs("div", { className: containerClassNameOverload, ref: containerRef, children: [jsxRuntimeExports.jsx(Input, { setContextRef: setInputRef }), jsxRuntimeExports.jsxs("div", { className: popupClassNameOverload, ref: calendarContainerRef, children: [jsxRuntimeExports.jsx(Arrow, { ref: arrowRef }), jsxRuntimeExports.jsxs("div", { className: "mt-2.5 shadow-xs border border-gray-300 px-1 py-0.5 bg-white dark:bg-zinc-800 dark:text-white dark:border-zinc-700 rounded-lg", children: [!timeOnly && (jsxRuntimeExports.jsxs("div", { className: "flex flex-col lg:flex-row py-2", children: [showShortcuts && jsxRuntimeExports.jsx(Shortcuts, {}), jsxRuntimeExports.jsxs("div", { className: `flex items-stretch flex-col md:flex-row space-y-4 md:space-y-0 md:gap-x-1.5 ${showShortcuts ? "md:ps-2" : "md:ps-1"} pe-2 lg:pe-1`, children: [jsxRuntimeExports.jsx(Calendar, { date: firstDate, onClickPrevious: previousMonthFirst, onClickNext: nextMonthFirst, changeMonth: changeFirstMonth, changeYear: changeFirstYear, minDate: minDate, maxDate: maxDate }), useRange && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("div", { className: "flex items-center", children: jsxRuntimeExports.jsx(VerticalDash, {}) }), jsxRuntimeExports.jsx(Calendar, { date: secondDate, onClickPrevious: previousMonthSecond, onClickNext: nextMonthSecond, changeMonth: changeSecondMonth, changeYear: changeSecondYear, minDate: minDate, maxDate: maxDate })] }))] })] })), (showTimePicker || timeOnly) && jsxRuntimeExports.jsx(TimePicker, {}), showFooter && jsxRuntimeExports.jsx(Footer, {})] })] })] }) }));
|
|
3482
3625
|
};
|
|
3483
3626
|
|
|
3484
3627
|
var af$1 = {exports: {}};
|