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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode, RefObject } from "react";
|
|
2
|
-
import { Configs, Period, DateValueType, DateType, DateRangeType, ClassNamesTypeProp, PopoverDirectionType, ColorKeys, WeekStringType, DateLookingType } from "../types";
|
|
2
|
+
import { Configs, Period, DateValueType, DateType, DateRangeType, ClassNamesTypeProp, PopoverDirectionType, ColorKeys, WeekStringType, DateLookingType, TimeType, TimeFormatType } from "../types";
|
|
3
3
|
interface DatepickerStore {
|
|
4
4
|
arrowContainer: RefObject<HTMLDivElement> | null;
|
|
5
5
|
asSingle?: boolean;
|
|
@@ -38,6 +38,14 @@ interface DatepickerStore {
|
|
|
38
38
|
toggleIcon?: (open: boolean) => ReactNode;
|
|
39
39
|
updateFirstDate: (date: Date) => void;
|
|
40
40
|
value: DateValueType;
|
|
41
|
+
useRange?: boolean;
|
|
42
|
+
showTimePicker?: boolean;
|
|
43
|
+
timeOnly?: boolean;
|
|
44
|
+
timeFormat?: TimeFormatType;
|
|
45
|
+
startTime: TimeType;
|
|
46
|
+
endTime: TimeType;
|
|
47
|
+
changeStartTime: (time: TimeType) => void;
|
|
48
|
+
changeEndTime: (time: TimeType) => void;
|
|
41
49
|
}
|
|
42
50
|
declare const DatepickerContext: import("react").Context<DatepickerStore>;
|
|
43
51
|
export default DatepickerContext;
|
package/dist/index.cjs.js
CHANGED
|
@@ -1662,7 +1662,15 @@ const DatepickerContext = require$$0.createContext({
|
|
|
1662
1662
|
toggleClassName: "",
|
|
1663
1663
|
toggleIcon: undefined,
|
|
1664
1664
|
updateFirstDate: () => { },
|
|
1665
|
-
value: null
|
|
1665
|
+
value: null,
|
|
1666
|
+
useRange: true,
|
|
1667
|
+
showTimePicker: false,
|
|
1668
|
+
timeOnly: false,
|
|
1669
|
+
timeFormat: "24",
|
|
1670
|
+
startTime: { hour: 0, minute: 0 },
|
|
1671
|
+
endTime: { hour: 0, minute: 0 },
|
|
1672
|
+
changeStartTime: () => { },
|
|
1673
|
+
changeEndTime: () => { }
|
|
1666
1674
|
});
|
|
1667
1675
|
|
|
1668
1676
|
var isBetween$1 = {exports: {}};
|
|
@@ -2794,7 +2802,7 @@ const SecondaryButton = (props) => {
|
|
|
2794
2802
|
|
|
2795
2803
|
const Footer = () => {
|
|
2796
2804
|
// Contexts
|
|
2797
|
-
const { hideDatepicker, period, changeDatepickerValue, configs, classNames } = require$$0.useContext(DatepickerContext);
|
|
2805
|
+
const { hideDatepicker, period, changeDatepickerValue, configs, classNames, showTimePicker, timeOnly, startTime, endTime } = require$$0.useContext(DatepickerContext);
|
|
2798
2806
|
// Functions
|
|
2799
2807
|
const getClassName = require$$0.useCallback(() => {
|
|
2800
2808
|
if (typeof classNames !== "undefined" && typeof classNames?.footer === "function") {
|
|
@@ -2805,14 +2813,32 @@ const Footer = () => {
|
|
|
2805
2813
|
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: () => {
|
|
2806
2814
|
hideDatepicker();
|
|
2807
2815
|
}, children: jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: configs?.footer?.cancel ? configs.footer.cancel : "Cancel" }) }), jsxRuntimeExports.jsx(PrimaryButton, { onClick: () => {
|
|
2808
|
-
if (
|
|
2816
|
+
if (timeOnly) {
|
|
2817
|
+
const now = new Date();
|
|
2818
|
+
const startDate = new Date(now);
|
|
2819
|
+
startDate.setHours(startTime.hour, startTime.minute, 0, 0);
|
|
2820
|
+
const endDate = new Date(now);
|
|
2821
|
+
endDate.setHours(endTime.hour, endTime.minute, 0, 0);
|
|
2809
2822
|
changeDatepickerValue({
|
|
2810
|
-
startDate
|
|
2811
|
-
endDate
|
|
2823
|
+
startDate,
|
|
2824
|
+
endDate
|
|
2812
2825
|
});
|
|
2813
2826
|
hideDatepicker();
|
|
2814
2827
|
}
|
|
2815
|
-
|
|
2828
|
+
else if (period.start && period.end) {
|
|
2829
|
+
const startDate = new Date(period.start);
|
|
2830
|
+
const endDate = new Date(period.end);
|
|
2831
|
+
if (showTimePicker) {
|
|
2832
|
+
startDate.setHours(startTime.hour, startTime.minute, 0, 0);
|
|
2833
|
+
endDate.setHours(endTime.hour, endTime.minute, 0, 0);
|
|
2834
|
+
}
|
|
2835
|
+
changeDatepickerValue({
|
|
2836
|
+
startDate,
|
|
2837
|
+
endDate
|
|
2838
|
+
});
|
|
2839
|
+
hideDatepicker();
|
|
2840
|
+
}
|
|
2841
|
+
}, disabled: !timeOnly && !(period.start && period.end), children: jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: configs?.footer?.apply ? configs.footer.apply : "Apply" }) })] }) }));
|
|
2816
2842
|
};
|
|
2817
2843
|
|
|
2818
2844
|
const CloseIcon = (props) => {
|
|
@@ -2831,7 +2857,7 @@ const ToggleButton = (e) => {
|
|
|
2831
2857
|
|
|
2832
2858
|
const Input = (e) => {
|
|
2833
2859
|
// Context
|
|
2834
|
-
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 } = require$$0.useContext(DatepickerContext);
|
|
2860
|
+
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 } = require$$0.useContext(DatepickerContext);
|
|
2835
2861
|
// UseRefs
|
|
2836
2862
|
const buttonRef = require$$0.useRef(null);
|
|
2837
2863
|
const inputRef = require$$0.useRef(null);
|
|
@@ -2987,9 +3013,9 @@ const Input = (e) => {
|
|
|
2987
3013
|
div.classList.add("mb-2.5");
|
|
2988
3014
|
div.classList.remove("mt-2.5");
|
|
2989
3015
|
arrow.classList.add("-bottom-2");
|
|
2990
|
-
arrow.classList.add("border-
|
|
3016
|
+
arrow.classList.add("border-r");
|
|
2991
3017
|
arrow.classList.add("border-b");
|
|
2992
|
-
arrow.classList.remove("border-
|
|
3018
|
+
arrow.classList.remove("border-l");
|
|
2993
3019
|
arrow.classList.remove("border-t");
|
|
2994
3020
|
}
|
|
2995
3021
|
setTimeout(() => {
|
|
@@ -3011,7 +3037,9 @@ const Input = (e) => {
|
|
|
3011
3037
|
}, [calendarContainer, arrowContainer, popoverDirection]);
|
|
3012
3038
|
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("input", { ref: inputRef, type: "text", className: getClassName(), disabled: disabled, readOnly: readOnly, required: required, placeholder: placeholder
|
|
3013
3039
|
? placeholder
|
|
3014
|
-
:
|
|
3040
|
+
: timeOnly
|
|
3041
|
+
? `${timeFormat === "12" ? "hh:mm AM" : "HH:mm"}${asSingle ? "" : ` ${separator} ${timeFormat === "12" ? "hh:mm AM" : "HH:mm"}`}`
|
|
3042
|
+
: `${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) })] }));
|
|
3015
3043
|
};
|
|
3016
3044
|
|
|
3017
3045
|
const CURRENT_DATE = new Date();
|
|
@@ -3159,6 +3187,77 @@ const Shortcuts = () => {
|
|
|
3159
3187
|
: printItemText(item) }) }, index))) }) })) : null;
|
|
3160
3188
|
};
|
|
3161
3189
|
|
|
3190
|
+
const TimeColumn = ({ value, max, onChange, label, pad = 2 }) => {
|
|
3191
|
+
const { primaryColor } = require$$0.useContext(DatepickerContext);
|
|
3192
|
+
const prev = (value - 1 + max) % max;
|
|
3193
|
+
const next = (value + 1) % max;
|
|
3194
|
+
const format = (n) => String(n).padStart(pad, "0");
|
|
3195
|
+
const bgActive = BG_COLOR["500"][primaryColor];
|
|
3196
|
+
const bgHover = BG_COLOR.hover[primaryColor];
|
|
3197
|
+
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" }) }) })] }));
|
|
3198
|
+
};
|
|
3199
|
+
const AmPmToggle = ({ isAm, onChange }) => {
|
|
3200
|
+
const { primaryColor } = require$$0.useContext(DatepickerContext);
|
|
3201
|
+
const bgActive = BG_COLOR["500"][primaryColor];
|
|
3202
|
+
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
|
|
3203
|
+
? bgActive + " text-white"
|
|
3204
|
+
: "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
|
|
3205
|
+
? bgActive + " text-white"
|
|
3206
|
+
: "text-gray-400 hover:bg-gray-100 dark:hover:bg-white/10 dark:text-white/50"), onClick: () => onChange(false), children: "PM" })] })] }));
|
|
3207
|
+
};
|
|
3208
|
+
const SingleTimePicker = ({ time, onChange, label }) => {
|
|
3209
|
+
const { timeFormat, primaryColor } = require$$0.useContext(DatepickerContext);
|
|
3210
|
+
const is12h = timeFormat === "12";
|
|
3211
|
+
const displayHour = require$$0.useMemo(() => {
|
|
3212
|
+
if (!is12h)
|
|
3213
|
+
return time.hour;
|
|
3214
|
+
if (time.hour === 0)
|
|
3215
|
+
return 12;
|
|
3216
|
+
if (time.hour > 12)
|
|
3217
|
+
return time.hour - 12;
|
|
3218
|
+
return time.hour;
|
|
3219
|
+
}, [is12h, time.hour]);
|
|
3220
|
+
const isAm = time.hour < 12;
|
|
3221
|
+
const handleHourChange = require$$0.useCallback((newDisplayHour) => {
|
|
3222
|
+
let hour24;
|
|
3223
|
+
if (is12h) {
|
|
3224
|
+
if (isAm) {
|
|
3225
|
+
hour24 = newDisplayHour === 12 ? 0 : newDisplayHour;
|
|
3226
|
+
}
|
|
3227
|
+
else {
|
|
3228
|
+
hour24 = newDisplayHour === 12 ? 12 : newDisplayHour + 12;
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
else {
|
|
3232
|
+
hour24 = newDisplayHour;
|
|
3233
|
+
}
|
|
3234
|
+
onChange({ ...time, hour: hour24 });
|
|
3235
|
+
}, [is12h, isAm, onChange, time]);
|
|
3236
|
+
const handleMinuteChange = require$$0.useCallback((minute) => {
|
|
3237
|
+
onChange({ ...time, minute });
|
|
3238
|
+
}, [onChange, time]);
|
|
3239
|
+
const handleAmPmChange = require$$0.useCallback((newIsAm) => {
|
|
3240
|
+
let newHour;
|
|
3241
|
+
if (newIsAm && !isAm) {
|
|
3242
|
+
newHour = time.hour - 12;
|
|
3243
|
+
}
|
|
3244
|
+
else if (!newIsAm && isAm) {
|
|
3245
|
+
newHour = time.hour + 12;
|
|
3246
|
+
}
|
|
3247
|
+
else {
|
|
3248
|
+
return;
|
|
3249
|
+
}
|
|
3250
|
+
onChange({ ...time, hour: newHour });
|
|
3251
|
+
}, [isAm, onChange, time]);
|
|
3252
|
+
const textColor = TEXT_COLOR["600"][primaryColor];
|
|
3253
|
+
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 })] })] }));
|
|
3254
|
+
};
|
|
3255
|
+
const TimePicker = () => {
|
|
3256
|
+
const { asSingle, startTime, endTime, changeStartTime, changeEndTime, useRange } = require$$0.useContext(DatepickerContext);
|
|
3257
|
+
const showSingle = asSingle || !useRange;
|
|
3258
|
+
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" })] }))] }));
|
|
3259
|
+
};
|
|
3260
|
+
|
|
3162
3261
|
function useOnClickOutside(ref, handler) {
|
|
3163
3262
|
require$$0.useEffect(() => {
|
|
3164
3263
|
const listener = (event) => {
|
|
@@ -3177,7 +3276,7 @@ function useOnClickOutside(ref, handler) {
|
|
|
3177
3276
|
}
|
|
3178
3277
|
|
|
3179
3278
|
const Arrow = require$$0.forwardRef((props, ref) => {
|
|
3180
|
-
return (jsxRuntimeExports.jsx("div", { ...props, ref: ref, className: "absolute z-20 h-4 w-4 rotate-45 mt-0.5
|
|
3279
|
+
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" }));
|
|
3181
3280
|
});
|
|
3182
3281
|
Arrow.displayName = "Arrow";
|
|
3183
3282
|
|
|
@@ -3190,7 +3289,7 @@ const VerticalDash = () => {
|
|
|
3190
3289
|
|
|
3191
3290
|
const Datepicker = (props) => {
|
|
3192
3291
|
// Props
|
|
3193
|
-
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;
|
|
3292
|
+
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;
|
|
3194
3293
|
// Refs
|
|
3195
3294
|
const containerRef = require$$0.useRef(null);
|
|
3196
3295
|
const calendarContainerRef = require$$0.useRef(null);
|
|
@@ -3205,6 +3304,8 @@ const Datepicker = (props) => {
|
|
|
3205
3304
|
const [dayHover, setDayHover] = require$$0.useState(null);
|
|
3206
3305
|
const [inputText, setInputText] = require$$0.useState("");
|
|
3207
3306
|
const [inputRef, setInputRef] = require$$0.useState(require$$0.createRef());
|
|
3307
|
+
const [startTime, setStartTime] = require$$0.useState(defaultTime?.start ?? { hour: 0, minute: 0 });
|
|
3308
|
+
const [endTime, setEndTime] = require$$0.useState(defaultTime?.end ?? { hour: 0, minute: 0 });
|
|
3208
3309
|
// Custom Hooks use
|
|
3209
3310
|
useOnClickOutside(containerRef, () => {
|
|
3210
3311
|
const container = containerRef.current;
|
|
@@ -3228,9 +3329,9 @@ const Datepicker = (props) => {
|
|
|
3228
3329
|
div.classList.add("mb-2.5");
|
|
3229
3330
|
div.classList.add("mt-2.5");
|
|
3230
3331
|
arrow.classList.remove("-bottom-2");
|
|
3231
|
-
arrow.classList.remove("border-
|
|
3332
|
+
arrow.classList.remove("border-r");
|
|
3232
3333
|
arrow.classList.remove("border-b");
|
|
3233
|
-
arrow.classList.add("border-
|
|
3334
|
+
arrow.classList.add("border-l");
|
|
3234
3335
|
arrow.classList.add("border-t");
|
|
3235
3336
|
}, 300);
|
|
3236
3337
|
}
|
|
@@ -3287,16 +3388,16 @@ const Datepicker = (props) => {
|
|
|
3287
3388
|
const containerCenter = (detail.right - detail.x) / 2 + detail.x;
|
|
3288
3389
|
const isRTL = i18n === "ar";
|
|
3289
3390
|
const alignRight = () => {
|
|
3290
|
-
arrow.classList.remove("
|
|
3291
|
-
arrow.classList.add("
|
|
3292
|
-
arrow.classList.add("
|
|
3293
|
-
calendarContainer.classList.add("
|
|
3391
|
+
arrow.classList.remove("ml-[1.2rem]");
|
|
3392
|
+
arrow.classList.add("right-0");
|
|
3393
|
+
arrow.classList.add("mr-3.5");
|
|
3394
|
+
calendarContainer.classList.add("right-0");
|
|
3294
3395
|
};
|
|
3295
3396
|
const alignLeft = () => {
|
|
3296
|
-
arrow.classList.add("
|
|
3297
|
-
arrow.classList.remove("
|
|
3298
|
-
arrow.classList.remove("
|
|
3299
|
-
calendarContainer.classList.remove("
|
|
3397
|
+
arrow.classList.add("ml-[1.2rem]");
|
|
3398
|
+
arrow.classList.remove("right-0");
|
|
3399
|
+
arrow.classList.remove("mr-3.5");
|
|
3400
|
+
calendarContainer.classList.remove("right-0");
|
|
3300
3401
|
};
|
|
3301
3402
|
if (popoverDirection === "down-left" || popoverDirection === "up-left") {
|
|
3302
3403
|
if (isRTL) {
|
|
@@ -3324,16 +3425,33 @@ const Datepicker = (props) => {
|
|
|
3324
3425
|
}
|
|
3325
3426
|
}
|
|
3326
3427
|
}, [popoverDirection, i18n]);
|
|
3428
|
+
const formatTimeValue = require$$0.useCallback((time) => {
|
|
3429
|
+
if (timeFormat === "12") {
|
|
3430
|
+
const h = time.hour % 12 || 12;
|
|
3431
|
+
const ampm = time.hour < 12 ? "AM" : "PM";
|
|
3432
|
+
return `${String(h).padStart(2, "0")}:${String(time.minute).padStart(2, "0")} ${ampm}`;
|
|
3433
|
+
}
|
|
3434
|
+
return `${String(time.hour).padStart(2, "0")}:${String(time.minute).padStart(2, "0")}`;
|
|
3435
|
+
}, [timeFormat]);
|
|
3327
3436
|
require$$0.useEffect(() => {
|
|
3437
|
+
if (timeOnly) {
|
|
3438
|
+
const timeStr = asSingle
|
|
3439
|
+
? formatTimeValue(startTime)
|
|
3440
|
+
: `${formatTimeValue(startTime)} ${separator} ${formatTimeValue(endTime)}`;
|
|
3441
|
+
setInputText(timeStr);
|
|
3442
|
+
return;
|
|
3443
|
+
}
|
|
3328
3444
|
if (value && value.startDate && value.endDate) {
|
|
3329
3445
|
if (dateIsSameOrBefore(value.startDate, value.endDate, "date")) {
|
|
3330
3446
|
setPeriod({
|
|
3331
3447
|
start: value.startDate,
|
|
3332
3448
|
end: value.endDate
|
|
3333
3449
|
});
|
|
3334
|
-
|
|
3450
|
+
const timeSuffix = showTimePicker ? ` ${formatTimeValue(startTime)}` : "";
|
|
3451
|
+
const endTimeSuffix = showTimePicker ? ` ${formatTimeValue(endTime)}` : "";
|
|
3452
|
+
setInputText(`${dateFormat(value.startDate, displayFormat, i18n)}${timeSuffix}${asSingle
|
|
3335
3453
|
? ""
|
|
3336
|
-
: ` ${separator} ${dateFormat(value.endDate, displayFormat, i18n)}`}`);
|
|
3454
|
+
: ` ${separator} ${dateFormat(value.endDate, displayFormat, i18n)}${endTimeSuffix}`}`);
|
|
3337
3455
|
}
|
|
3338
3456
|
}
|
|
3339
3457
|
if (value && value.startDate === null && value.endDate === null) {
|
|
@@ -3343,7 +3461,18 @@ const Datepicker = (props) => {
|
|
|
3343
3461
|
});
|
|
3344
3462
|
setInputText("");
|
|
3345
3463
|
}
|
|
3346
|
-
}, [
|
|
3464
|
+
}, [
|
|
3465
|
+
asSingle,
|
|
3466
|
+
value,
|
|
3467
|
+
displayFormat,
|
|
3468
|
+
separator,
|
|
3469
|
+
i18n,
|
|
3470
|
+
showTimePicker,
|
|
3471
|
+
timeOnly,
|
|
3472
|
+
startTime,
|
|
3473
|
+
endTime,
|
|
3474
|
+
formatTimeValue
|
|
3475
|
+
]);
|
|
3347
3476
|
require$$0.useEffect(() => {
|
|
3348
3477
|
if (startFrom && dateIsValid(startFrom)) {
|
|
3349
3478
|
const startDate = value?.startDate;
|
|
@@ -3428,7 +3557,15 @@ const Datepicker = (props) => {
|
|
|
3428
3557
|
toggleClassName,
|
|
3429
3558
|
toggleIcon,
|
|
3430
3559
|
updateFirstDate: (newDate) => firstGotoDate(newDate),
|
|
3431
|
-
value
|
|
3560
|
+
value,
|
|
3561
|
+
showTimePicker,
|
|
3562
|
+
timeOnly,
|
|
3563
|
+
timeFormat,
|
|
3564
|
+
startTime,
|
|
3565
|
+
endTime,
|
|
3566
|
+
changeStartTime: (time) => setStartTime(time),
|
|
3567
|
+
changeEndTime: (time) => setEndTime(time),
|
|
3568
|
+
useRange
|
|
3432
3569
|
};
|
|
3433
3570
|
}, [
|
|
3434
3571
|
asSingle,
|
|
@@ -3462,7 +3599,13 @@ const Datepicker = (props) => {
|
|
|
3462
3599
|
inputRef,
|
|
3463
3600
|
popoverDirection,
|
|
3464
3601
|
required,
|
|
3465
|
-
firstGotoDate
|
|
3602
|
+
firstGotoDate,
|
|
3603
|
+
showTimePicker,
|
|
3604
|
+
timeOnly,
|
|
3605
|
+
timeFormat,
|
|
3606
|
+
startTime,
|
|
3607
|
+
endTime,
|
|
3608
|
+
useRange
|
|
3466
3609
|
]);
|
|
3467
3610
|
const containerClassNameOverload = require$$0.useMemo(() => {
|
|
3468
3611
|
const defaultContainerClassName = "relative w-full text-gray-700";
|
|
@@ -3480,7 +3623,7 @@ const Datepicker = (props) => {
|
|
|
3480
3623
|
? popupClassName
|
|
3481
3624
|
: defaultPopupClassName;
|
|
3482
3625
|
}, [popupClassName]);
|
|
3483
|
-
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, {})] })] })] }) }));
|
|
3626
|
+
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, {})] })] })] }) }));
|
|
3484
3627
|
};
|
|
3485
3628
|
|
|
3486
3629
|
var af$1 = {exports: {}};
|