Add isRangeSelected and isRangeHovered to Calendar render props#81
Add isRangeSelected and isRangeHovered to Calendar render props#81
isRangeSelected and isRangeHovered to Calendar render props#81Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: Zertz <2636763+Zertz@users.noreply.github.com>
Co-authored-by: Zertz <2636763+Zertz@users.noreply.github.com>
isRangeSelected and isRangeHovered to render propsisRangeSelected and isRangeHovered to Calendar render props
…feedback Co-authored-by: Zertz <2636763+Zertz@users.noreply.github.com>
Zertz
left a comment
There was a problem hiding this comment.
Update documentation in packages/www
Co-authored-by: Zertz <2636763+Zertz@users.noreply.github.com>
Done in c354d57. Updated |
There was a problem hiding this comment.
Pull request overview
Adds first-class range-selection/hover state to Tempocal’s React Calendar render props, and centralizes hover state management in useTempocal so examples/consumers no longer need to compute these booleans manually.
Changes:
- Add
isRangeSelected/isRangeHoveredtoCalendar’sdayPropsandrenderDayrender-prop arguments (computed insideDay). - Move
hoverValuestate intouseTempocal, and passhoverValue+rangeValuethroughcalendarProps(auto-spread ontoCalendar). - Update docs and the
DateRangePickerexample; adjustuseTempocaltest expectations.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/useTempocal.ts | Adds internal hoverValue state; returns hoverValue/rangeValue in calendarProps and exposes onChangeHoverValue. |
| packages/react/src/Calendar.tsx | Threads hoverValue/rangeValue into Month/Day and computes isRangeSelected/isRangeHovered for render props. |
| packages/react/test/useTempocal.test.ts | Updates assertions for new useTempocal return shape. |
| packages/www/examples/DateRangePicker.tsx | Uses new isRangeSelected/isRangeHovered props and onChangeHoverValue instead of local hover state. |
| packages/www/pages/react/useTempocal.tsx | Documents onChangeHoverValue and updated calendarProps shape. |
| packages/www/pages/react/Calendar.tsx | Documents updated dayProps/renderDay signatures including range booleans. |
Comments suppressed due to low confidence (1)
packages/react/src/Calendar.tsx:64
dayPropsis typed as returningButtonHTMLAttributes<HTMLLIElement>but those props are spread onto a<li>inDay. This is both a typing mismatch (wrong attribute set for an<li>) and can encourage consumers to pass invalid DOM props likedisabled. The return type should be based on<li>attributes (e.g.,React.LiHTMLAttributes<HTMLLIElement>/React.HTMLAttributes<HTMLLIElement>) to match how it’s applied.
}) => Omit<
React.DetailedHTMLProps<
React.ButtonHTMLAttributes<HTMLLIElement>,
HTMLLIElement
>,
"style"
>;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <CodeBlock>{`calendarProps: { | ||
| locale: Locale; | ||
| maxValue: Temporal.PlainDate; | ||
| minValue: Temporal.PlainDate; | ||
| value: Temporal.PlainDate; | ||
| hoverValue: Temporal.PlainDate | undefined; | ||
| rangeValue: DateRange | DateTimeRange | undefined; | ||
| }`}</CodeBlock> |
There was a problem hiding this comment.
In the documented calendarProps shape, maxValue and minValue are shown as required Temporal.PlainDate, but useTempocal actually returns them as optional/possibly undefined. Updating this snippet to reflect the optionality would keep the docs aligned with the real API.
Co-authored-by: Zertz <2636763+Zertz@users.noreply.github.com>
Zertz
left a comment
There was a problem hiding this comment.
Add isDateWithinRange to the docs
…ar entry Co-authored-by: Zertz <2636763+Zertz@users.noreply.github.com>
Done in 5ad18fa. Added |
Co-authored-by: Zertz <2636763+Zertz@users.noreply.github.com>
Computing range selection and hover state required boilerplate Temporal comparisons in every consumer. These are now computed internally and exposed via
renderDay/dayProps.API changes (
Calendar.tsx)renderDayanddayPropscallbacks now receiveisRangeSelected: booleanandisRangeHovered: booleanisRangeHoveredcovers both directions (hover before or after the anchor date)API changes (
useTempocal.ts)hoverValue(Temporal.PlainDate | undefined) is now managed as state insideuseTempocal— no manualuseStateneeded in consumer codeonChangeHoverValuecallback returned from the hook, to be attached to dayonMouseOverhandlerscalendarPropsnow includeshoverValueandrangeValue(the selected range, when in range mode), so spreading{...calendarProps}ontoCalendarpasses them automatically — no explicit props neededNew core utility (
packages/core)isDateWithinRange(date, rangeValue)added topackages/core/src/isDateWithinRange.tsand exported from the core packageboolean—trueifdatefalls within the closed interval defined byrangeValue(both start and end must be defined)PlainDateandPlainDateTimerange tuples; date-time values are automatically converted to plain dates for comparisonCalendar.tsxcallsisDateWithinRangetwice for the bidirectional hover case:isDateWithinRange(date, [rangeStart, hoverValue]) || isDateWithinRange(date, [hoverValue, rangeStart])packages/core/test/isDateWithinRange.test.tscovering: no range, partial range, dates inside/on/outside a closed range, and bidirectional hover intervals/core/isDateWithinRangeinpackages/wwwExample (
DateRangePicker.tsx)Before:
After:
The
DateRangePickerexample also demonstrates usingisDateWithinRangeandcalendarProps.hoverValuedirectly to render a live hover preview in the footer: when only the start date is selected, the footer shows the previewed range in correct chronological order (handling both forward and backward hover) usingisDateWithinRange(start, [start, previewEnd])to determine the display direction.Original prompt
isRangeSelectedandisRangeHoveredto render props indaterangeanddatetimerangemodes #75✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.