@lumx/react 4.24.0-next.0 → 4.24.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.
Files changed (3) hide show
  1. package/index.js +38 -20
  2. package/index.js.map +1 -1
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -22577,7 +22577,7 @@ function timeOfDayMinutes(date) {
22577
22577
  /** Options for `buildTimeList`. */
22578
22578
 
22579
22579
  const MINUTES_IN_HOUR = 60;
22580
- const MINUTES_IN_DAY = 24 * MINUTES_IN_HOUR;
22580
+ const MINUTES_IN_DAY$1 = 24 * MINUTES_IN_HOUR;
22581
22581
 
22582
22582
  /**
22583
22583
  * Build a full-day list of `TimeOfDay` entries spaced `step` minutes apart.
@@ -22597,7 +22597,7 @@ function buildTimeList(options = {}) {
22597
22597
  const minMinutes = minTime ? timeOfDayMinutes(minTime) : undefined;
22598
22598
  const maxMinutes = maxTime ? timeOfDayMinutes(maxTime) : undefined;
22599
22599
  const list = [];
22600
- for (let minutes = 0; minutes < MINUTES_IN_DAY; minutes += step) {
22600
+ for (let minutes = 0; minutes < MINUTES_IN_DAY$1; minutes += step) {
22601
22601
  const hour = Math.floor(minutes / MINUTES_IN_HOUR);
22602
22602
  const minute = minutes % MINUTES_IN_HOUR;
22603
22603
  const outOfRange = minMinutes !== undefined && minutes < minMinutes || maxMinutes !== undefined && minutes > maxMinutes || undefined;
@@ -22663,24 +22663,42 @@ function parseTimeInput(raw) {
22663
22663
  };
22664
22664
  }
22665
22665
 
22666
+ const MINUTES_IN_DAY = 24 * 60;
22667
+ function ceilToStep(minutes, step) {
22668
+ return Math.ceil(minutes / step) * step;
22669
+ }
22670
+ function floorToStep(minutes, step) {
22671
+ return Math.floor(minutes / step) * step;
22672
+ }
22673
+ function minutesToTimeOfDay(minutes) {
22674
+ return {
22675
+ hour: Math.floor(minutes / 60),
22676
+ minute: minutes % 60
22677
+ };
22678
+ }
22679
+
22666
22680
  /**
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.
22681
+ * Clamp `time` to `[minTime, maxTime]`, snapping to the nearest `step`-aligned
22682
+ * option (as generated by `buildTimeList`) rather than to the raw bound.
22683
+ * Inputs below the effective `minTime` snap up to it. Inputs above the
22684
+ * effective `maxTime` snap down to it. Others are returned unchanged. When no
22685
+ * `step`-aligned option exists inside `[minTime, maxTime]`, `time` is returned
22686
+ * unchanged since there is nothing to snap to. Only the time-of-day of
22687
+ * `minTime`/`maxTime` is used.
22670
22688
  */
22671
- function snapTimeToBounds(time, minTime, maxTime) {
22689
+ function snapTimeToBounds(time, minTime, maxTime, step = 30) {
22672
22690
  const totalMinutes = time.hour * 60 + time.minute;
22673
- if (minTime && totalMinutes < timeOfDayMinutes(minTime)) {
22674
- return {
22675
- hour: minTime.getHours(),
22676
- minute: minTime.getMinutes()
22677
- };
22691
+ const effectiveMin = minTime ? ceilToStep(timeOfDayMinutes(minTime), step) : undefined;
22692
+ const effectiveMax = maxTime ? floorToStep(timeOfDayMinutes(maxTime), step) : undefined;
22693
+ const noOptionInBounds = effectiveMin !== undefined && (effectiveMin >= MINUTES_IN_DAY || effectiveMax !== undefined && effectiveMin > effectiveMax);
22694
+ if (noOptionInBounds) {
22695
+ return time;
22678
22696
  }
22679
- if (maxTime && totalMinutes > timeOfDayMinutes(maxTime)) {
22680
- return {
22681
- hour: maxTime.getHours(),
22682
- minute: maxTime.getMinutes()
22683
- };
22697
+ if (effectiveMin !== undefined && totalMinutes < effectiveMin) {
22698
+ return minutesToTimeOfDay(effectiveMin);
22699
+ }
22700
+ if (effectiveMax !== undefined && totalMinutes > effectiveMax) {
22701
+ return minutesToTimeOfDay(effectiveMax);
22684
22702
  }
22685
22703
  return time;
22686
22704
  }
@@ -22759,11 +22777,11 @@ const TimePickerField = props => {
22759
22777
  hour: value.getHours(),
22760
22778
  minute: value.getMinutes()
22761
22779
  };
22762
- const clamped = snapTimeToBounds(timeOfDay, minTime, maxTime);
22780
+ const clamped = snapTimeToBounds(timeOfDay, minTime, maxTime, step);
22763
22781
  if (clamped.hour !== value.getHours() || clamped.minute !== value.getMinutes()) {
22764
22782
  onChange(getDateAtTime(clamped, value), name);
22765
22783
  }
22766
- }, [boundsMode, value, minTime, maxTime, onChange, name]);
22784
+ }, [boundsMode, value, step, minTime, maxTime, onChange, name]);
22767
22785
  const handleChange = useCallback(next => {
22768
22786
  const date = next ? getDateAtTime(next, value) : undefined;
22769
22787
  onChange(date, name);
@@ -22776,10 +22794,10 @@ const TimePickerField = props => {
22776
22794
  if (!parsed) return;
22777
22795
 
22778
22796
  // Snap to bounds if needed, then dedup against the current value.
22779
- const time = snapTimeToBounds(parsed, minTime, maxTime);
22797
+ const time = snapTimeToBounds(parsed, minTime, maxTime, step);
22780
22798
  if (value && isDateOnTime(value, time)) return;
22781
22799
  onChange(getDateAtTime(time, value), name);
22782
- }, [maxTime, minTime, name, onChange, searchValue, value]);
22800
+ }, [maxTime, minTime, name, onChange, searchValue, step, value]);
22783
22801
  const searchInputValue = value ? formatTime(value, locale) : undefined;
22784
22802
  return TimePickerField$1({
22785
22803
  ...forwardedProps,