@lumx/react 4.29.0-next.0 → 4.29.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/index.js +91 -60
- package/index.js.map +1 -1
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -12029,8 +12029,52 @@ CommentBlock.displayName = COMPONENT_NAME$17;
|
|
|
12029
12029
|
CommentBlock.className = CLASSNAME$14;
|
|
12030
12030
|
CommentBlock.defaultProps = DEFAULT_PROPS$W;
|
|
12031
12031
|
|
|
12032
|
+
/** Calendar days: the day of a `Date` is its local date, the time of day is ignored. */
|
|
12033
|
+
|
|
12034
|
+
/** Check that `date` is a valid date. */
|
|
12035
|
+
const isDateValid = date => date instanceof Date && !Number.isNaN(date.getTime());
|
|
12036
|
+
|
|
12037
|
+
/**
|
|
12038
|
+
* Get the calendar date of a day: the `00:00 UTC` instant whose local date is the day, else the local start of the
|
|
12039
|
+
* day (ex: clock change at midnight in `Atlantic/Azores`). Every date that a date picker sets is a calendar date.
|
|
12040
|
+
* The day overflows like the `Date` constructor. Two-digit years are not mapped to 19xx.
|
|
12041
|
+
*/
|
|
12042
|
+
function getCalendarDate(year, monthIndex, day) {
|
|
12043
|
+
// Normalize the local day (overflow, two-digit years).
|
|
12044
|
+
const local = new Date(0);
|
|
12045
|
+
local.setFullYear(year, monthIndex, day);
|
|
12046
|
+
const [y, m, d] = [local.getFullYear(), local.getMonth(), local.getDate()];
|
|
12047
|
+
const utc = new Date(0);
|
|
12048
|
+
utc.setUTCFullYear(y, m, d);
|
|
12049
|
+
// Negative UTC offset: 00:00 UTC is still the previous local day, use 00:00 UTC of the next day.
|
|
12050
|
+
if (utc.getDate() !== d) utc.setUTCFullYear(y, m, d + 1);
|
|
12051
|
+
if (utc.getDate() === d) return utc;
|
|
12052
|
+
local.setHours(0, 0, 0, 0);
|
|
12053
|
+
return local;
|
|
12054
|
+
}
|
|
12055
|
+
|
|
12056
|
+
/** Number of the day of `date`, ordered like the days (`NaN` for an invalid date). */
|
|
12057
|
+
const getDayNumber = date => date.getFullYear() * 10000 + date.getMonth() * 100 + date.getDate();
|
|
12058
|
+
|
|
12059
|
+
/** Check that `date1` and `date2` are on the same day. `false` if one of them is not a valid date. */
|
|
12060
|
+
const isSameDay = (date1, date2) => isDateValid(date1) && isDateValid(date2) && getDayNumber(date1) === getDayNumber(date2);
|
|
12061
|
+
|
|
12032
12062
|
/**
|
|
12033
|
-
*
|
|
12063
|
+
* Check that the day of `date` is in the range (`minDate` and `maxDate` days included).
|
|
12064
|
+
* An invalid `minDate` or `maxDate` is ignored.
|
|
12065
|
+
*/
|
|
12066
|
+
const isDateInRange = (date, minDate, maxDate) => (!isDateValid(minDate) || getDayNumber(date) >= getDayNumber(minDate)) && (!isDateValid(maxDate) || getDayNumber(date) <= getDayNumber(maxDate));
|
|
12067
|
+
|
|
12068
|
+
/** Number of days in a month (`monthIndex`: 0 = January). */
|
|
12069
|
+
function getDaysInMonth(year, monthIndex) {
|
|
12070
|
+
const date = new Date(0);
|
|
12071
|
+
date.setFullYear(year, monthIndex + 1, 0);
|
|
12072
|
+
return date.getDate();
|
|
12073
|
+
}
|
|
12074
|
+
|
|
12075
|
+
/**
|
|
12076
|
+
* Add a number of months to a date, on the first day of the month (no month length mismatch).
|
|
12077
|
+
* Keeps the time of day.
|
|
12034
12078
|
*/
|
|
12035
12079
|
function addMonthResetDay(date, monthOffset) {
|
|
12036
12080
|
const newDate = new Date(date.getTime());
|
|
@@ -12039,11 +12083,6 @@ function addMonthResetDay(date, monthOffset) {
|
|
|
12039
12083
|
return newDate;
|
|
12040
12084
|
}
|
|
12041
12085
|
|
|
12042
|
-
/**
|
|
12043
|
-
* Check if given date is valid.
|
|
12044
|
-
*/
|
|
12045
|
-
const isDateValid = date => date instanceof Date && !Number.isNaN(date.getTime());
|
|
12046
|
-
|
|
12047
12086
|
/**
|
|
12048
12087
|
* Component display name.
|
|
12049
12088
|
*/
|
|
@@ -12054,6 +12093,8 @@ const COMPONENT_NAME$16 = 'DatePicker';
|
|
|
12054
12093
|
*/
|
|
12055
12094
|
const CLASSNAME$13 = 'lumx-date-picker';
|
|
12056
12095
|
|
|
12096
|
+
/** Week info of `Intl.Locale` (not in the TS lib of the repo). */
|
|
12097
|
+
|
|
12057
12098
|
/** Get first day of week for locale from the browser API */
|
|
12058
12099
|
const getFromBrowser = locale => {
|
|
12059
12100
|
try {
|
|
@@ -12149,61 +12190,42 @@ const getWeekDays = locale => {
|
|
|
12149
12190
|
return weekDays;
|
|
12150
12191
|
};
|
|
12151
12192
|
|
|
12152
|
-
/** Up to 6 rows can appear in a month calendar => 4 weeks + 1 start of month partial week + 1
|
|
12193
|
+
/** Up to 6 rows can appear in a month calendar => 4 weeks + 1 start of month partial week + 1 end of month partial week */
|
|
12153
12194
|
const MONTH_ROW_COUNT = 6;
|
|
12154
12195
|
|
|
12155
12196
|
/**
|
|
12156
12197
|
* Get month calendar.
|
|
12157
|
-
* A list of weeks with days indexed by week day number
|
|
12198
|
+
* A list of weeks with days indexed by week day number.
|
|
12158
12199
|
*/
|
|
12159
12200
|
const getMonthCalendar = (locale, referenceDate = new Date(), rangeMinDate, rangeMaxDate) => {
|
|
12201
|
+
const year = referenceDate.getFullYear();
|
|
12160
12202
|
const month = referenceDate.getMonth();
|
|
12161
|
-
const
|
|
12162
|
-
iterDate.setDate(1);
|
|
12163
|
-
const minDate = rangeMinDate && new Date(rangeMinDate);
|
|
12164
|
-
const maxDate = rangeMaxDate && new Date(rangeMaxDate);
|
|
12165
|
-
// Reset time to compare dates only.
|
|
12166
|
-
iterDate.setUTCHours(0, 0, 0, 0);
|
|
12167
|
-
minDate?.setUTCHours(0, 0, 0, 0);
|
|
12168
|
-
maxDate?.setUTCHours(0, 0, 0, 0);
|
|
12203
|
+
const dayCount = getDaysInMonth(year, month);
|
|
12169
12204
|
const weekDays = getWeekDays(locale);
|
|
12170
|
-
const lastDayOfWeek =
|
|
12205
|
+
const lastDayOfWeek = weekDays[weekDays.length - 1];
|
|
12171
12206
|
const weeks = [];
|
|
12172
12207
|
let week = {};
|
|
12173
|
-
let
|
|
12174
|
-
|
|
12175
|
-
const weekDayNumber =
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
if (minDate && iterDate < minDate || maxDate && iterDate > maxDate) {
|
|
12183
|
-
day.isOutOfRange = true;
|
|
12184
|
-
}
|
|
12185
|
-
if (iterDate.getMonth() === month) {
|
|
12186
|
-
week[weekDayNumber] = day;
|
|
12208
|
+
for (let day = 1; weeks.length < MONTH_ROW_COUNT; day += 1) {
|
|
12209
|
+
const date = getCalendarDate(year, month, day);
|
|
12210
|
+
const weekDayNumber = date.getDay();
|
|
12211
|
+
if (day <= dayCount) {
|
|
12212
|
+
const annotatedDay = {
|
|
12213
|
+
date
|
|
12214
|
+
};
|
|
12215
|
+
if (!isDateInRange(date, rangeMinDate, rangeMaxDate)) annotatedDay.isOutOfRange = true;
|
|
12216
|
+
week[weekDayNumber] = annotatedDay;
|
|
12187
12217
|
}
|
|
12188
12218
|
if (weekDayNumber === lastDayOfWeek.number) {
|
|
12189
12219
|
weeks.push(week);
|
|
12190
|
-
rowCount += 1;
|
|
12191
12220
|
week = {};
|
|
12192
12221
|
}
|
|
12193
|
-
iterDate.setDate(iterDate.getDate() + 1);
|
|
12194
12222
|
}
|
|
12195
|
-
if (Object.keys(week).length) weeks.push(week);
|
|
12196
12223
|
return {
|
|
12197
12224
|
weeks,
|
|
12198
12225
|
weekDays
|
|
12199
12226
|
};
|
|
12200
12227
|
};
|
|
12201
12228
|
|
|
12202
|
-
/**
|
|
12203
|
-
* Check `date1` is on the same day as `date2`.
|
|
12204
|
-
*/
|
|
12205
|
-
const isSameDay = (date1, date2) => isDateValid(date1) && isDateValid(date2) && date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate();
|
|
12206
|
-
|
|
12207
12229
|
/**
|
|
12208
12230
|
* Get current browser locale (BCP-47 string).
|
|
12209
12231
|
*
|
|
@@ -12253,8 +12275,6 @@ function usePreviousValue(value) {
|
|
|
12253
12275
|
const getYearDisplayName = locale => {
|
|
12254
12276
|
let label;
|
|
12255
12277
|
try {
|
|
12256
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
12257
|
-
// @ts-ignore
|
|
12258
12278
|
const displayNames = new Intl.DisplayNames(locale, {
|
|
12259
12279
|
type: 'dateTimeField'
|
|
12260
12280
|
});
|
|
@@ -12265,9 +12285,28 @@ const getYearDisplayName = locale => {
|
|
|
12265
12285
|
return label;
|
|
12266
12286
|
};
|
|
12267
12287
|
|
|
12268
|
-
|
|
12288
|
+
/**
|
|
12289
|
+
* Options of the long date format (the text of a date picker field).
|
|
12290
|
+
* Gregorian calendar: `parseDate` reads the typed fields as Gregorian (ex: no Buddhist year in `th`).
|
|
12291
|
+
*/
|
|
12292
|
+
const LONG_DATE_FORMAT = {
|
|
12293
|
+
year: 'numeric',
|
|
12294
|
+
month: 'long',
|
|
12295
|
+
day: 'numeric',
|
|
12296
|
+
calendar: 'gregory'
|
|
12297
|
+
};
|
|
12298
|
+
|
|
12299
|
+
/**
|
|
12300
|
+
* Format a date in the long format of the locale (ex: `November 12, 2026`, `12 novembre 2026`).
|
|
12301
|
+
* Empty string when there is no valid date.
|
|
12302
|
+
*/
|
|
12303
|
+
const formatDate = (date, locale) => isDateValid(date) ? date.toLocaleDateString(locale, LONG_DATE_FORMAT) : '';
|
|
12304
|
+
|
|
12305
|
+
/** Format the day number of a date in the locale (only the digits when the locale format has digits). */
|
|
12306
|
+
function formatDayNumber(date, locale) {
|
|
12269
12307
|
const formattedDate = date.toLocaleDateString(locale, {
|
|
12270
|
-
day: 'numeric'
|
|
12308
|
+
day: 'numeric',
|
|
12309
|
+
calendar: 'gregory'
|
|
12271
12310
|
});
|
|
12272
12311
|
if (formattedDate.match(/\d/)) return formattedDate.replace(/\D*(\d+)\D*/g, '$1');
|
|
12273
12312
|
return formattedDate;
|
|
@@ -12318,7 +12357,8 @@ const DatePickerControlled = forwardRef((props, ref) => {
|
|
|
12318
12357
|
}, [locale, minDate, maxDate, selectedMonth]);
|
|
12319
12358
|
const selectedYear = selectedMonth.getFullYear();
|
|
12320
12359
|
const formattedYear = selectedMonth.toLocaleDateString(locale, {
|
|
12321
|
-
year: 'numeric'
|
|
12360
|
+
year: 'numeric',
|
|
12361
|
+
calendar: 'gregory'
|
|
12322
12362
|
}).slice(0, 4);
|
|
12323
12363
|
const [currentYear, setCurrentYear] = React__default.useState(String(selectedYear));
|
|
12324
12364
|
|
|
@@ -12351,7 +12391,8 @@ const DatePickerControlled = forwardRef((props, ref) => {
|
|
|
12351
12391
|
const updateYearOnEnterPressed = React__default.useMemo(() => onEnterPressed$1(updateYear), [updateYear]);
|
|
12352
12392
|
const monthYear = selectedMonth.toLocaleDateString(locale, {
|
|
12353
12393
|
year: 'numeric',
|
|
12354
|
-
month: 'long'
|
|
12394
|
+
month: 'long',
|
|
12395
|
+
calendar: 'gregory'
|
|
12355
12396
|
});
|
|
12356
12397
|
|
|
12357
12398
|
// Update current year when selected year changes
|
|
@@ -12442,8 +12483,8 @@ const DatePickerControlled = forwardRef((props, ref) => {
|
|
|
12442
12483
|
isOutOfRange
|
|
12443
12484
|
} = week[weekDay.number] || {};
|
|
12444
12485
|
const key = `${weekIndex}-${dayIndex}`;
|
|
12445
|
-
const isToday = !isOutOfRange &&
|
|
12446
|
-
const isSelected =
|
|
12486
|
+
const isToday = !isOutOfRange && isSameDay(date, new Date());
|
|
12487
|
+
const isSelected = isSameDay(value, date);
|
|
12447
12488
|
return /*#__PURE__*/jsx("div", {
|
|
12448
12489
|
className: element$F('day-wrapper'),
|
|
12449
12490
|
children: date && /*#__PURE__*/jsxs(Button, {
|
|
@@ -12457,14 +12498,10 @@ const DatePickerControlled = forwardRef((props, ref) => {
|
|
|
12457
12498
|
onClick: () => onChange(date),
|
|
12458
12499
|
children: [/*#__PURE__*/jsx("span", {
|
|
12459
12500
|
"aria-hidden": true,
|
|
12460
|
-
children: formatDayNumber(
|
|
12501
|
+
children: formatDayNumber(date, locale)
|
|
12461
12502
|
}), /*#__PURE__*/jsx("span", {
|
|
12462
12503
|
className: classNames.visuallyHidden(),
|
|
12463
|
-
children: date
|
|
12464
|
-
day: 'numeric',
|
|
12465
|
-
month: 'long',
|
|
12466
|
-
year: 'numeric'
|
|
12467
|
-
})
|
|
12504
|
+
children: formatDate(date, locale)
|
|
12468
12505
|
})]
|
|
12469
12506
|
})
|
|
12470
12507
|
}, key);
|
|
@@ -12573,13 +12610,7 @@ const DatePickerField = forwardRef((props, ref) => {
|
|
|
12573
12610
|
onChange(newDate, name);
|
|
12574
12611
|
close();
|
|
12575
12612
|
}, [name, onChange, close]);
|
|
12576
|
-
|
|
12577
|
-
// Format date for text field
|
|
12578
|
-
const textFieldValue = value?.toLocaleDateString(locale, {
|
|
12579
|
-
year: 'numeric',
|
|
12580
|
-
month: 'long',
|
|
12581
|
-
day: 'numeric'
|
|
12582
|
-
}) || '';
|
|
12613
|
+
const textFieldValue = formatDate(value, locale);
|
|
12583
12614
|
const todayOrSelectedDateRef = React__default.useRef(null);
|
|
12584
12615
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
12585
12616
|
children: [/*#__PURE__*/jsx(TextField, {
|