Skip to content

Separate AM/PM picker column (#69)#86

Open
troberts-28 wants to merge 4 commits into
developfrom
feature/separate-am-pm-picker
Open

Separate AM/PM picker column (#69)#86
troberts-28 wants to merge 4 commits into
developfrom
feature/separate-am-pm-picker

Conversation

@troberts-28
Copy link
Copy Markdown
Owner

@troberts-28 troberts-28 commented May 10, 2026

Closes #69.

Summary

  • New separateAmPmPicker prop on TimerPicker / TimerPickerModal. When combined with use12HourPicker, AM/PM renders as a dedicated scrollable column after seconds and the hour column shows 12, 1, 2, …, 11. Public onDurationChange / latestDuration / setValue keep using 0–23 hours.
  • hourLimit is honoured in separate mode: hour-column rows grey + snap based on the currently-selected AM/PM. The AM/PM column is freely toggleable so users can always switch halves to reach a valid hour. Wraparound limits (max < min) work the same as in the existing 12-hour mode. hourInterval > 1 is respected end-to-end (rendering, snap, greying).
  • Two new style keys for the column: separateAmPmItem and selectedSeparateAmPmItem. pickerColumnWidth.amPm now also works (modal width math routed through the existing resolveColumnWidth helper).
  • Single-mechanism greying + snap. DurationScroll accepts optional getValidValue and isItemDisabled callbacks; TimerPicker injects cross-column context (current AM/PM + hourLimit + hourInterval) through these instead of passing extra prop channels through to PickerItem. No reentrant setValue from the orchestrator.
  • LatestDurationRef = { readonly current: number } replaces the synthetic RefObject<number> cast on latestDuration.hours / latestDuration.*.
  • Internal helper renamed cycleIdxhourSlot (and findNearestValidHourSlot) for readability.
  • README updated with the new prop, the two style keys, and the pickerColumnWidth.amPm option. Example app gains a separateAmPmPicker modal page and a cross-midnight hourLimit test page.

When use12HourPicker is enabled, separateAmPmPicker renders AM/PM as a
dedicated scrollable column after seconds instead of appending it to each
hour. The hours column shows 12, 1, 2, …, 11 in clock order. Public API
(onDurationChange, latestDuration, setValue) keeps using 0–23 hours.

hourLimit is honoured in this mode: the hour column's rows grey based on
the currently selected AM/PM, and momentum-scroll snaps to the nearest
valid hour in that half. The AM/PM column is intentionally limit-free so
users can always toggle halves to reach any valid hour. Wraparound limits
(max < min) are handled the same as in the existing 12-hour mode.

The TimerPickerModal width calculation now counts the AM/PM column when
present, so default styles work without manual pickerColumnWidth tweaks.
maximumHours remains ignored in separate mode (warns at runtime).
…y refs

- DurationScroll gains `getValidValue` + `isItemDisabled` callback props.
  TimerPicker injects cross-column context (current AM/PM, hourLimit,
  hourInterval) through these instead of plumbing combinedHourLimit /
  currentAmPm through DurationScroll → PickerItem.
- One snap path: DurationScroll's onMomentumScrollEnd calls the validate
  callback, no more reentrant setValue from TimerPicker.
- findNearestValidCycleIdx now takes interval and iterates 0..11 step
  interval, so hourInterval > 1 no longer snaps to a non-rendered cycleIdx.
  Adds parameterised interval coverage to the test suite.
- Drop dead selectedAmPmRef + sync useEffect.
- Replace the synthetic `RefObject<number>` cast on latestDuration.hours
  with a proper `LatestDurationRef = { readonly current: number }` type
  used by both TimerPickerRef and TimerPickerModalRef.
- Add "amPm" to PickerColumn so pickerColumnWidth.amPm works and the modal
  width math routes through the existing resolveColumnWidth helper.
cycleIdx was internal jargon. hourSlot reads naturally as 'a slot in the
12-hour clock-face column' where slot 0 is the 12 (noon/midnight) position.
splitHour24 returns { amPm, hourSlot }; findNearestValidHourSlot replaces
findNearestValidCycleIdx; getValidHourSlot/isHourSlotDisabled in TimerPicker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant