@lumx/react 4.24.0-next.0 → 4.24.0-next.2

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
@@ -4762,6 +4762,13 @@ interface SideNavigationItemProps extends GenericProps$1, HasCloseMode$1 {
4762
4762
  isOpen?: boolean;
4763
4763
  /** Whether the component is selected or not. */
4764
4764
  isSelected?: boolean;
4765
+ /**
4766
+ * Whether the link points to the current page or not.
4767
+ * Sets `aria-current="page"` on the link, which produces the selected style.
4768
+ * This does not set the `--is-selected` modifier class: a link component set in `linkAs` can set the
4769
+ * attribute by itself, and React never sees it, so the attribute is the only reliable signal.
4770
+ */
4771
+ isCurrentPage?: boolean;
4765
4772
  /** Custom react component for the link (can be used to inject react router Link). */
4766
4773
  linkAs?: 'a' | any;
4767
4774
  /** Props to pass to the link (minus those already set by the SideNavigationItem props). */
package/index.js CHANGED
@@ -19292,6 +19292,7 @@ const SideNavigationItem = forwardRef((props, ref) => {
19292
19292
  icon,
19293
19293
  isOpen,
19294
19294
  isSelected,
19295
+ isCurrentPage,
19295
19296
  label,
19296
19297
  linkAs,
19297
19298
  linkProps,
@@ -19305,6 +19306,9 @@ const SideNavigationItem = forwardRef((props, ref) => {
19305
19306
  const hasContent = !isEmpty(content);
19306
19307
  const shouldSplitActions = Boolean(onActionClick);
19307
19308
  const showChildren = hasContent && isOpen;
19309
+
19310
+ // Mark the link as the current page. A link component set in `linkAs` can also set it by itself.
19311
+ const ariaCurrent = isCurrentPage ? 'page' : undefined;
19308
19312
  const contentId = useId();
19309
19313
  const ariaProps = {};
19310
19314
  if (hasContent) {
@@ -19324,6 +19328,7 @@ const SideNavigationItem = forwardRef((props, ref) => {
19324
19328
  className: element$a('wrapper'),
19325
19329
  children: [RawClickable({
19326
19330
  as: linkAs || (linkProps?.href ? 'a' : 'button'),
19331
+ 'aria-current': ariaCurrent,
19327
19332
  ...linkProps,
19328
19333
  className: element$a('link'),
19329
19334
  handleClick: onClick,
@@ -19348,6 +19353,7 @@ const SideNavigationItem = forwardRef((props, ref) => {
19348
19353
  })]
19349
19354
  }) : RawClickable({
19350
19355
  as: linkAs || (linkProps?.href ? 'a' : 'button'),
19356
+ 'aria-current': ariaCurrent,
19351
19357
  ...linkProps,
19352
19358
  className: element$a('link'),
19353
19359
  handleClick: onClick,
@@ -22577,7 +22583,7 @@ function timeOfDayMinutes(date) {
22577
22583
  /** Options for `buildTimeList`. */
22578
22584
 
22579
22585
  const MINUTES_IN_HOUR = 60;
22580
- const MINUTES_IN_DAY = 24 * MINUTES_IN_HOUR;
22586
+ const MINUTES_IN_DAY$1 = 24 * MINUTES_IN_HOUR;
22581
22587
 
22582
22588
  /**
22583
22589
  * Build a full-day list of `TimeOfDay` entries spaced `step` minutes apart.
@@ -22597,7 +22603,7 @@ function buildTimeList(options = {}) {
22597
22603
  const minMinutes = minTime ? timeOfDayMinutes(minTime) : undefined;
22598
22604
  const maxMinutes = maxTime ? timeOfDayMinutes(maxTime) : undefined;
22599
22605
  const list = [];
22600
- for (let minutes = 0; minutes < MINUTES_IN_DAY; minutes += step) {
22606
+ for (let minutes = 0; minutes < MINUTES_IN_DAY$1; minutes += step) {
22601
22607
  const hour = Math.floor(minutes / MINUTES_IN_HOUR);
22602
22608
  const minute = minutes % MINUTES_IN_HOUR;
22603
22609
  const outOfRange = minMinutes !== undefined && minutes < minMinutes || maxMinutes !== undefined && minutes > maxMinutes || undefined;
@@ -22663,24 +22669,42 @@ function parseTimeInput(raw) {
22663
22669
  };
22664
22670
  }
22665
22671
 
22672
+ const MINUTES_IN_DAY = 24 * 60;
22673
+ function ceilToStep(minutes, step) {
22674
+ return Math.ceil(minutes / step) * step;
22675
+ }
22676
+ function floorToStep(minutes, step) {
22677
+ return Math.floor(minutes / step) * step;
22678
+ }
22679
+ function minutesToTimeOfDay(minutes) {
22680
+ return {
22681
+ hour: Math.floor(minutes / 60),
22682
+ minute: minutes % 60
22683
+ };
22684
+ }
22685
+
22666
22686
  /**
22667
- * Clamp `time` to `[minTime, maxTime]`. Inputs strictly before `minTime` snap
22668
- * up; inputs strictly after `maxTime` snap down; otherwise returned unchanged.
22669
- * Only the time-of-day of `minTime`/`maxTime` is used.
22687
+ * Clamp `time` to `[minTime, maxTime]`, snapping to the nearest `step`-aligned
22688
+ * option (as generated by `buildTimeList`) rather than to the raw bound.
22689
+ * Inputs below the effective `minTime` snap up to it. Inputs above the
22690
+ * effective `maxTime` snap down to it. Others are returned unchanged. When no
22691
+ * `step`-aligned option exists inside `[minTime, maxTime]`, `time` is returned
22692
+ * unchanged since there is nothing to snap to. Only the time-of-day of
22693
+ * `minTime`/`maxTime` is used.
22670
22694
  */
22671
- function snapTimeToBounds(time, minTime, maxTime) {
22695
+ function snapTimeToBounds(time, minTime, maxTime, step = 30) {
22672
22696
  const totalMinutes = time.hour * 60 + time.minute;
22673
- if (minTime && totalMinutes < timeOfDayMinutes(minTime)) {
22674
- return {
22675
- hour: minTime.getHours(),
22676
- minute: minTime.getMinutes()
22677
- };
22697
+ const effectiveMin = minTime ? ceilToStep(timeOfDayMinutes(minTime), step) : undefined;
22698
+ const effectiveMax = maxTime ? floorToStep(timeOfDayMinutes(maxTime), step) : undefined;
22699
+ const noOptionInBounds = effectiveMin !== undefined && (effectiveMin >= MINUTES_IN_DAY || effectiveMax !== undefined && effectiveMin > effectiveMax);
22700
+ if (noOptionInBounds) {
22701
+ return time;
22678
22702
  }
22679
- if (maxTime && totalMinutes > timeOfDayMinutes(maxTime)) {
22680
- return {
22681
- hour: maxTime.getHours(),
22682
- minute: maxTime.getMinutes()
22683
- };
22703
+ if (effectiveMin !== undefined && totalMinutes < effectiveMin) {
22704
+ return minutesToTimeOfDay(effectiveMin);
22705
+ }
22706
+ if (effectiveMax !== undefined && totalMinutes > effectiveMax) {
22707
+ return minutesToTimeOfDay(effectiveMax);
22684
22708
  }
22685
22709
  return time;
22686
22710
  }
@@ -22759,11 +22783,11 @@ const TimePickerField = props => {
22759
22783
  hour: value.getHours(),
22760
22784
  minute: value.getMinutes()
22761
22785
  };
22762
- const clamped = snapTimeToBounds(timeOfDay, minTime, maxTime);
22786
+ const clamped = snapTimeToBounds(timeOfDay, minTime, maxTime, step);
22763
22787
  if (clamped.hour !== value.getHours() || clamped.minute !== value.getMinutes()) {
22764
22788
  onChange(getDateAtTime(clamped, value), name);
22765
22789
  }
22766
- }, [boundsMode, value, minTime, maxTime, onChange, name]);
22790
+ }, [boundsMode, value, step, minTime, maxTime, onChange, name]);
22767
22791
  const handleChange = useCallback(next => {
22768
22792
  const date = next ? getDateAtTime(next, value) : undefined;
22769
22793
  onChange(date, name);
@@ -22776,10 +22800,10 @@ const TimePickerField = props => {
22776
22800
  if (!parsed) return;
22777
22801
 
22778
22802
  // Snap to bounds if needed, then dedup against the current value.
22779
- const time = snapTimeToBounds(parsed, minTime, maxTime);
22803
+ const time = snapTimeToBounds(parsed, minTime, maxTime, step);
22780
22804
  if (value && isDateOnTime(value, time)) return;
22781
22805
  onChange(getDateAtTime(time, value), name);
22782
- }, [maxTime, minTime, name, onChange, searchValue, value]);
22806
+ }, [maxTime, minTime, name, onChange, searchValue, step, value]);
22783
22807
  const searchInputValue = value ? formatTime(value, locale) : undefined;
22784
22808
  return TimePickerField$1({
22785
22809
  ...forwardedProps,