art-bd-ui 1.0.6 → 1.0.7
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/cjs/_virtual/range.js +11 -0
- package/dist/cjs/components/forms/input/input.js +1 -0
- package/dist/cjs/components/ui/alert/alert.js +1 -0
- package/dist/cjs/components/ui/badge/badge.js +0 -1
- package/dist/cjs/components/ui/calendar/calendar.js +43 -10
- package/dist/cjs/components/ui/card/card.js +1 -0
- package/dist/cjs/components/ui/date-pickers/date-time-picker/date-time-picker.js +88 -0
- package/dist/cjs/components/ui/date-pickers/month-select/month-select.js +25 -0
- package/dist/cjs/components/ui/date-pickers/time-picker/components/time-period-select.js +33 -0
- package/dist/cjs/components/ui/date-pickers/time-picker/components/time-picker-input.js +78 -0
- package/dist/cjs/components/ui/date-pickers/time-picker/time-picker.js +35 -0
- package/dist/cjs/components/ui/date-pickers/utils.js +177 -0
- package/dist/cjs/components/ui/date-pickers/year-select/year-select.js +17 -0
- package/dist/cjs/index.js +50 -42
- package/dist/cjs/node_modules/@radix-ui/react-select/dist/index.js +66 -66
- package/dist/cjs/node_modules/date-fns/_lib/normalizeDates.js +1 -1
- package/dist/cjs/node_modules/date-fns/add.js +73 -0
- package/dist/cjs/node_modules/date-fns/isSameWeek.js +56 -0
- package/dist/cjs/node_modules/date-fns/locale/uk/_lib/formatDistance.js +254 -0
- package/dist/cjs/node_modules/date-fns/locale/uk/_lib/formatLong.js +43 -0
- package/dist/cjs/node_modules/date-fns/locale/uk/_lib/formatRelative.js +94 -0
- package/dist/cjs/node_modules/date-fns/locale/uk/_lib/localize.js +219 -0
- package/dist/cjs/node_modules/date-fns/locale/uk/_lib/match.js +143 -0
- package/dist/cjs/node_modules/date-fns/locale/uk.js +33 -0
- package/dist/cjs/node_modules/lodash/_baseRange.js +41 -0
- package/dist/cjs/node_modules/lodash/_createRange.js +46 -0
- package/dist/cjs/node_modules/lodash/_isIterateeCall.js +47 -0
- package/dist/cjs/node_modules/lodash/range.js +60 -0
- package/dist/cjs/node_modules/lodash/toFinite.js +56 -0
- package/dist/cjs/styles/responsive.js +1 -1
- package/dist/esm/_virtual/range.js +7 -0
- package/dist/esm/components/forms/input/input.js +1 -1
- package/dist/esm/components/forms/select/select.js +6 -6
- package/dist/esm/components/ui/alert/alert.js +1 -1
- package/dist/esm/components/ui/badge/badge.js +1 -1
- package/dist/esm/components/ui/calendar/calendar.js +44 -11
- package/dist/esm/components/ui/card/card.js +1 -1
- package/dist/esm/components/ui/date-pickers/date-time-picker/date-time-picker.js +86 -0
- package/dist/esm/components/ui/date-pickers/month-select/month-select.js +23 -0
- package/dist/esm/components/ui/date-pickers/time-picker/components/time-period-select.js +31 -0
- package/dist/esm/components/ui/date-pickers/time-picker/components/time-picker-input.js +76 -0
- package/dist/esm/components/ui/date-pickers/time-picker/time-picker.js +33 -0
- package/dist/esm/components/ui/date-pickers/utils.js +172 -0
- package/dist/esm/components/ui/date-pickers/year-select/year-select.js +15 -0
- package/dist/esm/index.js +17 -14
- package/dist/esm/node_modules/date-fns/_lib/normalizeDates.js +1 -1
- package/dist/esm/node_modules/date-fns/add.js +68 -0
- package/dist/esm/node_modules/date-fns/isSameWeek.js +51 -0
- package/dist/esm/node_modules/date-fns/locale/uk/_lib/formatDistance.js +252 -0
- package/dist/esm/node_modules/date-fns/locale/uk/_lib/formatLong.js +41 -0
- package/dist/esm/node_modules/date-fns/locale/uk/_lib/formatRelative.js +92 -0
- package/dist/esm/node_modules/date-fns/locale/uk/_lib/localize.js +217 -0
- package/dist/esm/node_modules/date-fns/locale/uk/_lib/match.js +141 -0
- package/dist/esm/node_modules/date-fns/locale/uk.js +28 -0
- package/dist/esm/node_modules/lodash/_baseRange.js +39 -0
- package/dist/esm/node_modules/lodash/_createRange.js +44 -0
- package/dist/esm/node_modules/lodash/_isIterateeCall.js +45 -0
- package/dist/esm/node_modules/lodash/range.js +58 -0
- package/dist/esm/node_modules/lodash/toFinite.js +54 -0
- package/dist/esm/styles/responsive.js +1 -1
- package/dist/styles.css +46 -30
- package/dist/types/index.d.ts +175 -115
- package/package.json +1 -1
- package/dist/cjs/components/ui/date-picker/date-picker.js +0 -15
- package/dist/esm/components/ui/date-picker/date-picker.js +0 -13
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _commonjsHelpers = require('./_commonjsHelpers.js');
|
|
6
|
+
var range$1 = require('../node_modules/lodash/range.js');
|
|
7
|
+
|
|
8
|
+
var rangeExports = range$1.__require();
|
|
9
|
+
var range = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(rangeExports);
|
|
10
|
+
|
|
11
|
+
exports.default = range;
|
|
@@ -3,22 +3,55 @@
|
|
|
3
3
|
|
|
4
4
|
var tslib_es6 = require('../../../node_modules/tslib/tslib.es6.js');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var React = require('react');
|
|
6
7
|
var utils = require('../../../lib/utils.js');
|
|
7
8
|
var icon = require('../../media/icon/icon.js');
|
|
8
9
|
var button = require('../../buttons/button/button.js');
|
|
10
|
+
var select = require('../../forms/select/select.js');
|
|
9
11
|
var DayPicker = require('../../../node_modules/react-day-picker/dist/esm/DayPicker.js');
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
const Chevron = (_a) => {
|
|
14
|
+
var { className, orientation } = _a, props = tslib_es6.__rest(_a, ["className", "orientation"]);
|
|
15
|
+
return (jsxRuntime.jsx(icon.Icon, Object.assign({ name: `chevron-${orientation}`, className: utils.cn("h-4 w-4", className) }, props)));
|
|
16
|
+
};
|
|
17
|
+
const Dropdown = (props) => {
|
|
18
|
+
const { options, value, onChange } = props;
|
|
19
|
+
const handleValueChange = (newValue) => {
|
|
20
|
+
if (onChange) {
|
|
21
|
+
const syntheticEvent = {
|
|
22
|
+
target: {
|
|
23
|
+
value: newValue,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
onChange(syntheticEvent);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return (jsxRuntime.jsxs(select.Select, { value: value === null || value === void 0 ? void 0 : value.toString(), onValueChange: handleValueChange, children: [jsxRuntime.jsx(select.SelectTrigger, { children: jsxRuntime.jsx(select.SelectValue, {}) }), jsxRuntime.jsx(select.SelectContent, { children: jsxRuntime.jsx(select.SelectGroup, { children: options === null || options === void 0 ? void 0 : options.map((option) => (jsxRuntime.jsx(select.SelectItem, { value: option.value.toString(), disabled: option.disabled, children: option.label }, option.value))) }) })] }));
|
|
30
|
+
};
|
|
31
|
+
const components = {
|
|
32
|
+
Chevron,
|
|
33
|
+
Dropdown,
|
|
34
|
+
};
|
|
35
|
+
const Calendar = React.memo((_a) => {
|
|
36
|
+
var _b, _c;
|
|
12
37
|
var { className, classNames, showOutsideDays = true } = _a, props = tslib_es6.__rest(_a, ["className", "classNames", "showOutsideDays"]);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
38
|
+
const selectedMonth = (_b = props.month) === null || _b === void 0 ? void 0 : _b.getMonth();
|
|
39
|
+
const selectedYear = (_c = props.month) === null || _c === void 0 ? void 0 : _c.getFullYear();
|
|
40
|
+
const disabledLeftNavigation = React.useMemo(() => {
|
|
41
|
+
if (selectedMonth && props.startMonth) {
|
|
42
|
+
return selectedMonth === props.startMonth.getMonth() && selectedYear === props.startMonth.getFullYear();
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}, [selectedMonth, selectedYear, props.startMonth]);
|
|
46
|
+
const disabledRightNavigation = React.useMemo(() => {
|
|
47
|
+
if (selectedMonth && props.endMonth) {
|
|
48
|
+
return selectedMonth === props.endMonth.getMonth() && selectedYear === props.endMonth.getFullYear();
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}, [selectedMonth, selectedYear, props.endMonth]);
|
|
52
|
+
const _classNames = React.useMemo(() => (Object.assign({ months: "flex flex-col sm:flex-row space-y-4 sm:space-y-0 justify-center", month: "flex flex-col items-center space-y-4", month_caption: "flex justify-center pt-1 relative items-center", caption_label: "text-sm font-medium", nav: "space-x-1 flex items-center", dropdowns: "inline-flex gap-2 items-center", button_previous: utils.cn(button.buttonVariants({ variant: "outline" }), "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute left-5 top-5", disabledLeftNavigation && "pointer-events-none"), button_next: utils.cn(button.buttonVariants({ variant: "outline" }), "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100 absolute right-5 top-5", disabledRightNavigation && "pointer-events-none"), month_grid: "w-full border-collapse space-y-1", weekdays: utils.cn("flex", props.showWeekNumber && "justify-end"), weekday: "text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]", week: "flex w-full mt-2", day: "h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20 rounded-1", day_button: utils.cn(button.buttonVariants({ variant: "ghost" }), "h-9 w-9 p-0 font-normal aria-selected:opacity-100 rounded-l-md rounded-r-md"), range_end: "day-range-end", selected: "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground rounded-l-md rounded-r-md", today: "bg-accent text-accent-foreground", outside: "day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30", disabled: "text-muted-foreground opacity-50", range_middle: "aria-selected:bg-accent aria-selected:text-accent-foreground", hidden: "invisible" }, classNames)), [props.showWeekNumber, disabledLeftNavigation, disabledRightNavigation, classNames]);
|
|
53
|
+
return (jsxRuntime.jsx(DayPicker.DayPicker, Object.assign({ captionLayout: "dropdown", showOutsideDays: showOutsideDays, className: utils.cn("p-3", className), classNames: _classNames, components: components }, props)));
|
|
54
|
+
});
|
|
22
55
|
Calendar.displayName = "Calendar";
|
|
23
56
|
|
|
24
57
|
exports.Calendar = Calendar;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var tslib_es6 = require('../../../../node_modules/tslib/tslib.es6.js');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var timePicker = require('../time-picker/time-picker.js');
|
|
8
|
+
var calendar = require('../../calendar/calendar.js');
|
|
9
|
+
var utils = require('../../../../lib/utils.js');
|
|
10
|
+
var popover = require('../../../popovers/popover/popover.js');
|
|
11
|
+
var button = require('../../../buttons/button/button.js');
|
|
12
|
+
var uk = require('../../../../node_modules/date-fns/locale/uk.js');
|
|
13
|
+
var enUS = require('../../../../node_modules/date-fns/locale/en-US.js');
|
|
14
|
+
var add = require('../../../../node_modules/date-fns/add.js');
|
|
15
|
+
var format = require('../../../../node_modules/date-fns/format.js');
|
|
16
|
+
|
|
17
|
+
const getDateFnsLocale = (locale) => (locale === "ua" ? uk.uk : enUS.enUS);
|
|
18
|
+
const DateTimePicker = React.forwardRef((_a, ref) => {
|
|
19
|
+
var _b, _c;
|
|
20
|
+
var { locale = "en", defaultPopupValue = new Date(new Date().setHours(0, 0, 0, 0)), value, onChange, onMonthChange, hourCycle = 24, disabled = false, displayFormat, granularity = "second", placeholder = "Pick a date", className } = _a, props = tslib_es6.__rest(_a, ["locale", "defaultPopupValue", "value", "onChange", "onMonthChange", "hourCycle", "disabled", "displayFormat", "granularity", "placeholder", "className"]);
|
|
21
|
+
const buttonRef = React.useRef(null);
|
|
22
|
+
const [month, setMonth] = React.useState(value !== null && value !== void 0 ? value : defaultPopupValue);
|
|
23
|
+
const [displayDate, setDisplayDate] = React.useState(value !== null && value !== void 0 ? value : undefined);
|
|
24
|
+
onMonthChange || (onMonthChange = onChange);
|
|
25
|
+
/**
|
|
26
|
+
* Makes sure display date updates when value change on
|
|
27
|
+
* parent component
|
|
28
|
+
*/
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
setDisplayDate(value);
|
|
31
|
+
}, [value]);
|
|
32
|
+
/**
|
|
33
|
+
* carry over the current time when a user clicks a new day
|
|
34
|
+
* instead of resetting to 00:00
|
|
35
|
+
*/
|
|
36
|
+
const handleMonthChange = (newDay) => {
|
|
37
|
+
var _a, _b, _c, _d, _e, _f;
|
|
38
|
+
if (!newDay) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (!defaultPopupValue) {
|
|
42
|
+
newDay.setHours((_a = month === null || month === void 0 ? void 0 : month.getHours()) !== null && _a !== void 0 ? _a : 0, (_b = month === null || month === void 0 ? void 0 : month.getMinutes()) !== null && _b !== void 0 ? _b : 0, (_c = month === null || month === void 0 ? void 0 : month.getSeconds()) !== null && _c !== void 0 ? _c : 0);
|
|
43
|
+
onMonthChange === null || onMonthChange === void 0 ? void 0 : onMonthChange(newDay);
|
|
44
|
+
setMonth(newDay);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const diff = newDay.getTime() - defaultPopupValue.getTime();
|
|
48
|
+
const diffInDays = diff / (1000 * 60 * 60 * 24);
|
|
49
|
+
const newDateFull = add.add(defaultPopupValue, { days: Math.ceil(diffInDays) });
|
|
50
|
+
newDateFull.setHours((_d = month === null || month === void 0 ? void 0 : month.getHours()) !== null && _d !== void 0 ? _d : 0, (_e = month === null || month === void 0 ? void 0 : month.getMinutes()) !== null && _e !== void 0 ? _e : 0, (_f = month === null || month === void 0 ? void 0 : month.getSeconds()) !== null && _f !== void 0 ? _f : 0);
|
|
51
|
+
onMonthChange === null || onMonthChange === void 0 ? void 0 : onMonthChange(newDateFull);
|
|
52
|
+
setMonth(newDateFull);
|
|
53
|
+
};
|
|
54
|
+
const onSelect = (newDay) => {
|
|
55
|
+
if (!newDay) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newDay);
|
|
59
|
+
setMonth(newDay);
|
|
60
|
+
setDisplayDate(newDay);
|
|
61
|
+
};
|
|
62
|
+
React.useImperativeHandle(ref, () => (Object.assign(Object.assign({}, buttonRef.current), { value: displayDate })), [displayDate]);
|
|
63
|
+
const initHourFormat = {
|
|
64
|
+
hour24: (_b = displayFormat === null || displayFormat === void 0 ? void 0 : displayFormat.hour24) !== null && _b !== void 0 ? _b : `PPP HH:mm${!granularity || granularity === "second" ? ":ss" : ""}`,
|
|
65
|
+
hour12: (_c = displayFormat === null || displayFormat === void 0 ? void 0 : displayFormat.hour12) !== null && _c !== void 0 ? _c : `PP hh:mm${!granularity || granularity === "second" ? ":ss" : ""} b`,
|
|
66
|
+
};
|
|
67
|
+
const loc = getDateFnsLocale(locale);
|
|
68
|
+
return (jsxRuntime.jsxs(popover.Popover, { children: [jsxRuntime.jsx(popover.PopoverTrigger, { asChild: true, disabled: disabled, children: jsxRuntime.jsx(button.Button, { ref: buttonRef, variant: "outline", leftIcon: "calendar", className: utils.cn("w-full justify-start text-left font-normal", !displayDate && "text-muted-foreground", className), children: displayDate
|
|
69
|
+
? format.formatDate(displayDate, hourCycle === 24 ? initHourFormat.hour24 : initHourFormat.hour12, {
|
|
70
|
+
locale: loc,
|
|
71
|
+
})
|
|
72
|
+
: placeholder }) }), jsxRuntime.jsxs(popover.PopoverContent, { className: "w-auto p-0", children: [jsxRuntime.jsx(calendar.Calendar, Object.assign({ mode: "single", selected: displayDate, month: month, onSelect: (newDate) => {
|
|
73
|
+
var _a, _b, _c;
|
|
74
|
+
if (newDate) {
|
|
75
|
+
newDate.setHours((_a = month === null || month === void 0 ? void 0 : month.getHours()) !== null && _a !== void 0 ? _a : 0, (_b = month === null || month === void 0 ? void 0 : month.getMinutes()) !== null && _b !== void 0 ? _b : 0, (_c = month === null || month === void 0 ? void 0 : month.getSeconds()) !== null && _c !== void 0 ? _c : 0);
|
|
76
|
+
onSelect(newDate);
|
|
77
|
+
}
|
|
78
|
+
}, onMonthChange: handleMonthChange, locale: loc }, props)), granularity !== "day" && (jsxRuntime.jsx("div", { className: "border-border border-t p-3", children: jsxRuntime.jsx(timePicker.TimePicker, { value: month, onChange: (value) => {
|
|
79
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value);
|
|
80
|
+
setDisplayDate(value);
|
|
81
|
+
if (value) {
|
|
82
|
+
setMonth(value);
|
|
83
|
+
}
|
|
84
|
+
}, hourCycle: hourCycle, granularity: granularity }) }))] })] }));
|
|
85
|
+
});
|
|
86
|
+
DateTimePicker.displayName = "DateTimePicker";
|
|
87
|
+
|
|
88
|
+
exports.DateTimePicker = DateTimePicker;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var select = require('../../../forms/select/select.js');
|
|
7
|
+
var enUS = require('../../../../node_modules/date-fns/locale/en-US.js');
|
|
8
|
+
var format = require('../../../../node_modules/date-fns/format.js');
|
|
9
|
+
|
|
10
|
+
function genMonths(locale) {
|
|
11
|
+
return Array.from({ length: 12 }, (_, i) => ({
|
|
12
|
+
value: i,
|
|
13
|
+
label: format.formatDate(new Date(2021, i), "MMMM", { locale }),
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
const defaultLocale = enUS.enUS;
|
|
17
|
+
const MonthSelect = React.forwardRef(({ value: month, onChange, locale = defaultLocale }, ref) => {
|
|
18
|
+
const MONTHS = React.useMemo(() => genMonths(locale), []);
|
|
19
|
+
return (jsxRuntime.jsxs(select.Select, { defaultValue: month === null || month === void 0 ? void 0 : month.toString(), onValueChange: (value) => {
|
|
20
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(Number.parseInt(value, 10));
|
|
21
|
+
}, children: [jsxRuntime.jsx(select.SelectTrigger, { ref: ref, className: "focus:bg-accent focus:text-accent-foreground w-fit gap-1 border-none p-0", children: jsxRuntime.jsx(select.SelectValue, {}) }), jsxRuntime.jsx(select.SelectContent, { children: MONTHS.map((month) => (jsxRuntime.jsx(select.SelectItem, { value: month.value.toString(), children: month.label }, month.value))) })] }));
|
|
22
|
+
});
|
|
23
|
+
MonthSelect.displayName = "MonthSelect";
|
|
24
|
+
|
|
25
|
+
exports.MonthSelect = MonthSelect;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var utils = require('../../utils.js');
|
|
7
|
+
var select = require('../../../../forms/select/select.js');
|
|
8
|
+
var flex = require('../../../../layout/flex/flex.js');
|
|
9
|
+
|
|
10
|
+
const TimePeriodSelect = React.forwardRef(({ period, setPeriod, date, onDateChange, onLeftFocus, onRightFocus }, ref) => {
|
|
11
|
+
const handleKeyDown = (e) => {
|
|
12
|
+
if (e.key === "ArrowRight")
|
|
13
|
+
onRightFocus === null || onRightFocus === void 0 ? void 0 : onRightFocus();
|
|
14
|
+
if (e.key === "ArrowLeft")
|
|
15
|
+
onLeftFocus === null || onLeftFocus === void 0 ? void 0 : onLeftFocus();
|
|
16
|
+
};
|
|
17
|
+
const handleValueChange = (value) => {
|
|
18
|
+
setPeriod === null || setPeriod === void 0 ? void 0 : setPeriod(value);
|
|
19
|
+
/**
|
|
20
|
+
* trigger an update whenever the user switches between AM and PM;
|
|
21
|
+
* otherwise user must manually change the hour each time
|
|
22
|
+
*/
|
|
23
|
+
if (date) {
|
|
24
|
+
const tempDate = new Date(date);
|
|
25
|
+
const hours = utils.display12HourValue(date.getHours());
|
|
26
|
+
onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(utils.setDateByType(tempDate, hours.toString(), "12hours", period === "AM" ? "PM" : "AM"));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return (jsxRuntime.jsx(flex.Flex, { align: "center", className: "h-10", children: jsxRuntime.jsxs(select.Select, { defaultValue: period, onValueChange: (value) => handleValueChange(value), children: [jsxRuntime.jsx(select.SelectTrigger, { ref: ref, className: "focus:bg-accent focus:text-accent-foreground w-[65px]", onKeyDown: handleKeyDown, children: jsxRuntime.jsx(select.SelectValue, {}) }), jsxRuntime.jsxs(select.SelectContent, { children: [jsxRuntime.jsx(select.SelectItem, { value: "AM", children: "AM" }), jsxRuntime.jsx(select.SelectItem, { value: "PM", children: "PM" })] })] }) }));
|
|
30
|
+
});
|
|
31
|
+
TimePeriodSelect.displayName = "TimePeriodSelect";
|
|
32
|
+
|
|
33
|
+
exports.TimePeriodSelect = TimePeriodSelect;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var tslib_es6 = require('../../../../../node_modules/tslib/tslib.es6.js');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var utils = require('../../utils.js');
|
|
8
|
+
var utils$1 = require('../../../../../lib/utils.js');
|
|
9
|
+
var input = require('../../../../forms/input/input.js');
|
|
10
|
+
|
|
11
|
+
const TimePickerInput = React.forwardRef((_a, ref) => {
|
|
12
|
+
var { className, type = "tel", value, id, name, date = new Date(new Date().setHours(0, 0, 0, 0)), onDateChange, onChange, onKeyDown, picker, period, onLeftFocus, onRightFocus } = _a, props = tslib_es6.__rest(_a, ["className", "type", "value", "id", "name", "date", "onDateChange", "onChange", "onKeyDown", "picker", "period", "onLeftFocus", "onRightFocus"]);
|
|
13
|
+
const [flag, setFlag] = React.useState(false);
|
|
14
|
+
const [prevIntKey, setPrevIntKey] = React.useState("0");
|
|
15
|
+
/**
|
|
16
|
+
* allow the user to enter the second digit within 2 seconds
|
|
17
|
+
* otherwise start again with entering first digit
|
|
18
|
+
*/
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
if (flag) {
|
|
21
|
+
const timer = setTimeout(() => {
|
|
22
|
+
setFlag(false);
|
|
23
|
+
}, 2000);
|
|
24
|
+
return () => clearTimeout(timer);
|
|
25
|
+
}
|
|
26
|
+
}, [flag]);
|
|
27
|
+
const calculatedValue = React.useMemo(() => {
|
|
28
|
+
return utils.getDateByType(date, picker);
|
|
29
|
+
}, [date, picker]);
|
|
30
|
+
const calculateNewValue = (key) => {
|
|
31
|
+
/*
|
|
32
|
+
* If picker is '12hours' and the first digit is 0, then the second digit is automatically set to 1.
|
|
33
|
+
* The second entered digit will break the condition and the value will be set to 10-12.
|
|
34
|
+
*/
|
|
35
|
+
if (picker === "12hours") {
|
|
36
|
+
if (flag && calculatedValue.slice(1, 2) === "1" && prevIntKey === "0")
|
|
37
|
+
return `0${key}`;
|
|
38
|
+
}
|
|
39
|
+
return !flag ? `0${key}` : calculatedValue.slice(1, 2) + key;
|
|
40
|
+
};
|
|
41
|
+
const handleKeyDown = (e) => {
|
|
42
|
+
if (e.key === "Tab")
|
|
43
|
+
return;
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
if (e.key === "ArrowRight")
|
|
46
|
+
onRightFocus === null || onRightFocus === void 0 ? void 0 : onRightFocus();
|
|
47
|
+
if (e.key === "ArrowLeft")
|
|
48
|
+
onLeftFocus === null || onLeftFocus === void 0 ? void 0 : onLeftFocus();
|
|
49
|
+
if (["ArrowUp", "ArrowDown"].includes(e.key)) {
|
|
50
|
+
const step = e.key === "ArrowUp" ? 1 : -1;
|
|
51
|
+
const newValue = utils.getArrowByType(calculatedValue, step, picker);
|
|
52
|
+
if (flag)
|
|
53
|
+
setFlag(false);
|
|
54
|
+
const tempDate = date ? new Date(date) : new Date();
|
|
55
|
+
onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(utils.setDateByType(tempDate, newValue, picker, period));
|
|
56
|
+
}
|
|
57
|
+
if (e.key >= "0" && e.key <= "9") {
|
|
58
|
+
if (picker === "12hours")
|
|
59
|
+
setPrevIntKey(e.key);
|
|
60
|
+
const newValue = calculateNewValue(e.key);
|
|
61
|
+
if (flag)
|
|
62
|
+
onRightFocus === null || onRightFocus === void 0 ? void 0 : onRightFocus();
|
|
63
|
+
setFlag((prev) => !prev);
|
|
64
|
+
const tempDate = date ? new Date(date) : new Date();
|
|
65
|
+
onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(utils.setDateByType(tempDate, newValue, picker, period));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return (jsxRuntime.jsx(input.Input, Object.assign({ ref: ref, id: id || picker, name: name || picker, className: utils$1.cn("focus:bg-accent focus:text-accent-foreground w-[48px] text-center font-mono text-base tabular-nums caret-transparent [&::-webkit-inner-spin-button]:appearance-none", className), value: value || calculatedValue, onChange: (e) => {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
71
|
+
}, type: type, inputMode: "decimal", onKeyDown: (e) => {
|
|
72
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
73
|
+
handleKeyDown(e);
|
|
74
|
+
} }, props)));
|
|
75
|
+
});
|
|
76
|
+
TimePickerInput.displayName = "TimePickerInput";
|
|
77
|
+
|
|
78
|
+
exports.TimePickerInput = TimePickerInput;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var timePickerInput = require('./components/time-picker-input.js');
|
|
7
|
+
var timePeriodSelect = require('./components/time-period-select.js');
|
|
8
|
+
var icon = require('../../../media/icon/icon.js');
|
|
9
|
+
var flex = require('../../../layout/flex/flex.js');
|
|
10
|
+
|
|
11
|
+
const TimePicker = React.forwardRef(({ value: date, onChange, hourCycle = 24, granularity = "second" }, ref) => {
|
|
12
|
+
const minuteRef = React.useRef(null);
|
|
13
|
+
const hourRef = React.useRef(null);
|
|
14
|
+
const secondRef = React.useRef(null);
|
|
15
|
+
const periodRef = React.useRef(null);
|
|
16
|
+
const [period, setPeriod] = React.useState(date && date.getHours() >= 12 ? "PM" : "AM");
|
|
17
|
+
React.useImperativeHandle(ref, () => ({
|
|
18
|
+
minuteRef: minuteRef.current,
|
|
19
|
+
hourRef: hourRef.current,
|
|
20
|
+
secondRef: secondRef.current,
|
|
21
|
+
periodRef: periodRef.current,
|
|
22
|
+
}), [minuteRef, hourRef, secondRef]);
|
|
23
|
+
return (jsxRuntime.jsxs(flex.Flex, { align: "center", justify: "center", gap: 2, children: [jsxRuntime.jsx("label", { htmlFor: "datetime-picker-hour-input", className: "inline-flex items-center cursor-pointer", children: jsxRuntime.jsx(icon.Icon, { name: "clock", className: "mr-2 h-4 w-4" }) }), jsxRuntime.jsx(timePickerInput.TimePickerInput, { picker: hourCycle === 24 ? "hours" : "12hours", date: date, id: "datetime-picker-hour-input", onDateChange: onChange, ref: hourRef, period: period, onRightFocus: () => { var _a; return (_a = minuteRef === null || minuteRef === void 0 ? void 0 : minuteRef.current) === null || _a === void 0 ? void 0 : _a.focus(); } }), (granularity === "minute" || granularity === "second") && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [":", jsxRuntime.jsx(timePickerInput.TimePickerInput, { picker: "minutes", date: date, onDateChange: onChange, ref: minuteRef, onLeftFocus: () => { var _a; return (_a = hourRef === null || hourRef === void 0 ? void 0 : hourRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, onRightFocus: () => { var _a; return (_a = secondRef === null || secondRef === void 0 ? void 0 : secondRef.current) === null || _a === void 0 ? void 0 : _a.focus(); } })] })), granularity === "second" && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [":", jsxRuntime.jsx(timePickerInput.TimePickerInput, { ref: secondRef, picker: "seconds", date: date, onDateChange: onChange, onLeftFocus: () => { var _a; return (_a = minuteRef === null || minuteRef === void 0 ? void 0 : minuteRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, onRightFocus: () => { var _a; return (_a = periodRef === null || periodRef === void 0 ? void 0 : periodRef.current) === null || _a === void 0 ? void 0 : _a.focus(); } })] })), hourCycle === 12 && (jsxRuntime.jsx("div", { className: "grid gap-1 text-center", children: jsxRuntime.jsx(timePeriodSelect.TimePeriodSelect, { ref: periodRef, period: period, setPeriod: setPeriod, date: date, onDateChange: (date) => {
|
|
24
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(date);
|
|
25
|
+
if (date && (date === null || date === void 0 ? void 0 : date.getHours()) >= 12) {
|
|
26
|
+
setPeriod("PM");
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
setPeriod("AM");
|
|
30
|
+
}
|
|
31
|
+
}, onLeftFocus: () => { var _a; return (_a = secondRef === null || secondRef === void 0 ? void 0 : secondRef.current) === null || _a === void 0 ? void 0 : _a.focus(); } }) }))] }));
|
|
32
|
+
});
|
|
33
|
+
TimePicker.displayName = "TimePicker";
|
|
34
|
+
|
|
35
|
+
exports.TimePicker = TimePicker;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* regular expression to check for valid hour format (01-23)
|
|
5
|
+
*/
|
|
6
|
+
function isValidHour(value) {
|
|
7
|
+
return /^(0[0-9]|1[0-9]|2[0-3])$/.test(value);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* regular expression to check for valid 12 hour format (01-12)
|
|
11
|
+
*/
|
|
12
|
+
function isValid12Hour(value) {
|
|
13
|
+
return /^(0[1-9]|1[0-2])$/.test(value);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* regular expression to check for valid minute format (00-59)
|
|
17
|
+
*/
|
|
18
|
+
function isValidMinuteOrSecond(value) {
|
|
19
|
+
return /^[0-5][0-9]$/.test(value);
|
|
20
|
+
}
|
|
21
|
+
function getValidNumber(value, { max, min = 0, loop = false }) {
|
|
22
|
+
let numericValue = parseInt(value, 10);
|
|
23
|
+
if (!Number.isNaN(numericValue)) {
|
|
24
|
+
if (!loop) {
|
|
25
|
+
if (numericValue > max)
|
|
26
|
+
numericValue = max;
|
|
27
|
+
if (numericValue < min)
|
|
28
|
+
numericValue = min;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (numericValue > max)
|
|
32
|
+
numericValue = min;
|
|
33
|
+
if (numericValue < min)
|
|
34
|
+
numericValue = max;
|
|
35
|
+
}
|
|
36
|
+
return numericValue.toString().padStart(2, "0");
|
|
37
|
+
}
|
|
38
|
+
return "00";
|
|
39
|
+
}
|
|
40
|
+
function getValidHour(value) {
|
|
41
|
+
if (isValidHour(value))
|
|
42
|
+
return value;
|
|
43
|
+
return getValidNumber(value, { max: 23 });
|
|
44
|
+
}
|
|
45
|
+
function getValid12Hour(value) {
|
|
46
|
+
if (isValid12Hour(value))
|
|
47
|
+
return value;
|
|
48
|
+
return getValidNumber(value, { min: 1, max: 12 });
|
|
49
|
+
}
|
|
50
|
+
function getValidMinuteOrSecond(value) {
|
|
51
|
+
if (isValidMinuteOrSecond(value))
|
|
52
|
+
return value;
|
|
53
|
+
return getValidNumber(value, { max: 59 });
|
|
54
|
+
}
|
|
55
|
+
function getValidArrowNumber(value, { min, max, step }) {
|
|
56
|
+
let numericValue = parseInt(value, 10);
|
|
57
|
+
if (!Number.isNaN(numericValue)) {
|
|
58
|
+
numericValue += step;
|
|
59
|
+
return getValidNumber(String(numericValue), { min, max, loop: true });
|
|
60
|
+
}
|
|
61
|
+
return "00";
|
|
62
|
+
}
|
|
63
|
+
function getValidArrowHour(value, step) {
|
|
64
|
+
return getValidArrowNumber(value, { min: 0, max: 23, step });
|
|
65
|
+
}
|
|
66
|
+
function getValidArrow12Hour(value, step) {
|
|
67
|
+
return getValidArrowNumber(value, { min: 1, max: 12, step });
|
|
68
|
+
}
|
|
69
|
+
function getValidArrowMinuteOrSecond(value, step) {
|
|
70
|
+
return getValidArrowNumber(value, { min: 0, max: 59, step });
|
|
71
|
+
}
|
|
72
|
+
function setMinutes(date, value) {
|
|
73
|
+
const minutes = getValidMinuteOrSecond(value);
|
|
74
|
+
date.setMinutes(parseInt(minutes, 10));
|
|
75
|
+
return date;
|
|
76
|
+
}
|
|
77
|
+
function setSeconds(date, value) {
|
|
78
|
+
const seconds = getValidMinuteOrSecond(value);
|
|
79
|
+
date.setSeconds(parseInt(seconds, 10));
|
|
80
|
+
return date;
|
|
81
|
+
}
|
|
82
|
+
function setHours(date, value) {
|
|
83
|
+
const hours = getValidHour(value);
|
|
84
|
+
date.setHours(parseInt(hours, 10));
|
|
85
|
+
return date;
|
|
86
|
+
}
|
|
87
|
+
function set12Hours(date, value, period) {
|
|
88
|
+
const hours = parseInt(getValid12Hour(value), 10);
|
|
89
|
+
const convertedHours = convert12HourTo24Hour(hours, period);
|
|
90
|
+
date.setHours(convertedHours);
|
|
91
|
+
return date;
|
|
92
|
+
}
|
|
93
|
+
function setDateByType(date, value, type, period) {
|
|
94
|
+
switch (type) {
|
|
95
|
+
case "minutes":
|
|
96
|
+
return setMinutes(date, value);
|
|
97
|
+
case "seconds":
|
|
98
|
+
return setSeconds(date, value);
|
|
99
|
+
case "hours":
|
|
100
|
+
return setHours(date, value);
|
|
101
|
+
case "12hours": {
|
|
102
|
+
if (!period)
|
|
103
|
+
return date;
|
|
104
|
+
return set12Hours(date, value, period);
|
|
105
|
+
}
|
|
106
|
+
default:
|
|
107
|
+
return date;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function getDateByType(date, type) {
|
|
111
|
+
if (!date)
|
|
112
|
+
return "00";
|
|
113
|
+
switch (type) {
|
|
114
|
+
case "minutes":
|
|
115
|
+
return getValidMinuteOrSecond(String(date.getMinutes()));
|
|
116
|
+
case "seconds":
|
|
117
|
+
return getValidMinuteOrSecond(String(date.getSeconds()));
|
|
118
|
+
case "hours":
|
|
119
|
+
return getValidHour(String(date.getHours()));
|
|
120
|
+
case "12hours":
|
|
121
|
+
return getValid12Hour(String(display12HourValue(date.getHours())));
|
|
122
|
+
default:
|
|
123
|
+
return "00";
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function getArrowByType(value, step, type) {
|
|
127
|
+
switch (type) {
|
|
128
|
+
case "minutes":
|
|
129
|
+
return getValidArrowMinuteOrSecond(value, step);
|
|
130
|
+
case "seconds":
|
|
131
|
+
return getValidArrowMinuteOrSecond(value, step);
|
|
132
|
+
case "hours":
|
|
133
|
+
return getValidArrowHour(value, step);
|
|
134
|
+
case "12hours":
|
|
135
|
+
return getValidArrow12Hour(value, step);
|
|
136
|
+
default:
|
|
137
|
+
return "00";
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* handles value change of 12-hour input
|
|
142
|
+
* 12:00 PM is 12:00
|
|
143
|
+
* 12:00 AM is 00:00
|
|
144
|
+
*/
|
|
145
|
+
function convert12HourTo24Hour(hour, period) {
|
|
146
|
+
if (period === "PM") {
|
|
147
|
+
if (hour <= 11) {
|
|
148
|
+
return hour + 12;
|
|
149
|
+
}
|
|
150
|
+
return hour;
|
|
151
|
+
}
|
|
152
|
+
if (period === "AM") {
|
|
153
|
+
if (hour === 12)
|
|
154
|
+
return 0;
|
|
155
|
+
return hour;
|
|
156
|
+
}
|
|
157
|
+
return hour;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* time is stored in the 24-hour form,
|
|
161
|
+
* but needs to be displayed to the user
|
|
162
|
+
* in its 12-hour representation
|
|
163
|
+
*/
|
|
164
|
+
function display12HourValue(hours) {
|
|
165
|
+
if (hours === 0 || hours === 12)
|
|
166
|
+
return "12";
|
|
167
|
+
if (hours >= 22)
|
|
168
|
+
return `${hours - 12}`;
|
|
169
|
+
if (hours % 12 > 9)
|
|
170
|
+
return `${hours}`;
|
|
171
|
+
return `0${hours % 12}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
exports.display12HourValue = display12HourValue;
|
|
175
|
+
exports.getArrowByType = getArrowByType;
|
|
176
|
+
exports.getDateByType = getDateByType;
|
|
177
|
+
exports.setDateByType = setDateByType;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var range = require('../../../../_virtual/range.js');
|
|
7
|
+
var select = require('../../../forms/select/select.js');
|
|
8
|
+
|
|
9
|
+
const YearSelect = React.forwardRef(({ value: year, onChange, minYear = 1940, maxYear = new Date().getFullYear() + 50 }, ref) => {
|
|
10
|
+
const YEARS = React.useMemo(() => range.default(minYear, maxYear, 1).map((y) => ({ value: y, label: y.toString() })), [minYear, maxYear]);
|
|
11
|
+
return (jsxRuntime.jsxs(select.Select, { defaultValue: year === null || year === void 0 ? void 0 : year.toString(), onValueChange: (value) => {
|
|
12
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(Number.parseInt(value, 10));
|
|
13
|
+
}, children: [jsxRuntime.jsx(select.SelectTrigger, { ref: ref, className: "focus:bg-accent focus:text-accent-foreground w-fit gap-1 border-none p-0", children: jsxRuntime.jsx(select.SelectValue, {}) }), jsxRuntime.jsx(select.SelectContent, { position: "item-aligned", className: "max-h-[320px]", children: YEARS.map((year) => (jsxRuntime.jsx(select.SelectItem, { value: year.value.toString(), children: year.label }, year.value))) })] }));
|
|
14
|
+
});
|
|
15
|
+
YearSelect.displayName = "YearSelect";
|
|
16
|
+
|
|
17
|
+
exports.YearSelect = YearSelect;
|