@lumx/react 4.28.1-alpha.0 → 4.29.0-next.1

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.d.ts CHANGED
@@ -3996,12 +3996,13 @@ declare const Navigation: Comp<NavigationProps, HTMLElement> & SubComponents;
3996
3996
  /**
3997
3997
  * Props of the notification action.
3998
3998
  * Without `as`: props of a `Button`, with a `label` used as its content.
3999
- * With `as`: props of that component, forwarded as they are.
3999
+ * With `as`: props of that component.
4000
+ * Both get the medium `emphasis` and the `theme` of the notification as defaults.
4000
4001
  */
4001
4002
  type NotificationActionProps<E extends ElementType$1 = typeof Button> = (Omit<ButtonProps, 'children'> & {
4002
4003
  as?: undefined;
4003
4004
  label?: string;
4004
- }) | (ComponentProps<E> & {
4005
+ }) | (HasPolymorphicAs$1<E> & {
4005
4006
  as: E;
4006
4007
  });
4007
4008
  /**
@@ -4042,13 +4043,9 @@ declare const COMPONENT_NAME$1 = "Notification";
4042
4043
  */
4043
4044
  declare const CLASSNAME$1: LumxClassName$1<typeof COMPONENT_NAME$1>;
4044
4045
  /**
4045
- * Notification component.
4046
- *
4047
- * @param props Component props.
4048
- * @param ref Component ref.
4049
- * @return React element.
4046
+ * Notification component type, generic on the `as` component of `actionProps`.
4050
4047
  */
4051
- declare const Notification: {
4048
+ type NotificationComponent = {
4052
4049
  <E extends ElementType$1 = typeof Button>(props: NotificationProps<E> & {
4053
4050
  ref?: Ref<HTMLDivElement>;
4054
4051
  }): ReactElement | null;
@@ -4057,6 +4054,14 @@ declare const Notification: {
4057
4054
  className: typeof CLASSNAME$1;
4058
4055
  defaultProps: Partial<NotificationProps>;
4059
4056
  };
4057
+ /**
4058
+ * Notification component.
4059
+ *
4060
+ * @param props Component props.
4061
+ * @param ref Component ref.
4062
+ * @return React element.
4063
+ */
4064
+ declare const Notification: NotificationComponent;
4060
4065
 
4061
4066
  /**
4062
4067
  * PopoverDialog props.
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
+
12032
12037
  /**
12033
- * Add a number of months from a date while resetting the day to prevent month length mismatches.
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
+
12062
+ /**
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 send of month partial week */
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 iterDate = new Date(referenceDate);
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 = last(weekDays);
12205
+ const lastDayOfWeek = weekDays[weekDays.length - 1];
12171
12206
  const weeks = [];
12172
12207
  let week = {};
12173
- let rowCount = 0;
12174
- while (rowCount < MONTH_ROW_COUNT) {
12175
- const weekDayNumber = iterDate.getDay();
12176
- const day = {
12177
- date: new Date(iterDate.getTime())
12178
- };
12179
-
12180
- // If a range is specified, check if the day is out of range.
12181
- // min and max date are included within the valid range.
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
- function formatDayNumber(locale, date) {
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 && date && isSameDay(date, new Date());
12446
- const isSelected = date && value && isSameDay(value, date);
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(locale, date)
12501
+ children: formatDayNumber(date, locale)
12461
12502
  }), /*#__PURE__*/jsx("span", {
12462
12503
  className: classNames.visuallyHidden(),
12463
- children: date.toLocaleDateString(locale, {
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, {
@@ -17647,6 +17678,10 @@ const DEFAULT_PROPS$D = {
17647
17678
  usePortal: true
17648
17679
  };
17649
17680
 
17681
+ /**
17682
+ * Notification component type, generic on the `as` component of `actionProps`.
17683
+ */
17684
+
17650
17685
  /* eslint-disable react-hooks/rules-of-hooks, jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
17651
17686
  /**
17652
17687
  * Notification component.
@@ -17682,15 +17717,18 @@ const Notification = forwardRef((props, ref) => {
17682
17717
  } = NOTIFICATION_CONFIGURATION[type] || {};
17683
17718
  const rootRef = useRef(null);
17684
17719
  const isVisible = useTransitionVisibility(rootRef, !!isOpen, NOTIFICATION_TRANSITION_DURATION);
17685
- const hasAction = Boolean(actionProps) || Boolean(onActionClick) && Boolean(actionLabel);
17686
17720
  const {
17687
17721
  as: Action,
17688
17722
  label: actionPropsLabel = actionLabel,
17689
- onClick: onActionPropsClick = onActionClick,
17723
+ onClick: onActionPropsClick,
17690
17724
  ...forwardedActionProps
17691
17725
  } = actionProps || {};
17726
+ // A `Button` without a label has no accessible name.
17727
+ const hasAction = Boolean(Action) || Boolean(actionPropsLabel) && Boolean(actionProps || onActionClick);
17692
17728
  const handleActionClick = evt => {
17693
- onActionPropsClick?.(evt);
17729
+ if (onActionPropsClick) onActionPropsClick(evt);
17730
+ // The deprecated callback is typed with no argument.
17731
+ else onActionClick?.();
17694
17732
  evt.stopPropagation();
17695
17733
  };
17696
17734
  const commonActionProps = {