-
Notifications
You must be signed in to change notification settings - Fork 1
Add isRangeSelected and isRangeHovered to Calendar render props
#81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/add-israngeselected-hovered-props
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
985b106
Initial plan
Copilot a657697
Add isRangeSelected and isRangeHovered to Calendar render props
Copilot df24d62
Remove accidentally committed package-lock.json
Copilot e2fbaed
Move hoverValue/rangeValue into useTempocal calendarProps per review …
Copilot c354d57
Remove useCallback wrapper for onChangeHoverValue; update www docs
Copilot dd113dd
Extract getRangeDayState to packages/core; add tests
Copilot 5ad18fa
Rename getRangeDayState to isDateWithinRange; add docs page and sideb…
Copilot 3120da4
Delete packages/core/src/getRangeDayState.ts
Zertz 1f65766
Delete packages/core/test/getRangeDayState.test.ts
Zertz ace63d1
Update DateRangePicker example to use isDateWithinRange and hoverValue
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { Temporal } from "@js-temporal/polyfill"; | ||
|
|
||
| export function isDateWithinRange( | ||
| date: Temporal.PlainDate, | ||
| rangeValue: | ||
| | [undefined, undefined] | ||
| | [Temporal.PlainDate, undefined] | ||
| | [Temporal.PlainDate, Temporal.PlainDate] | ||
| | [Temporal.PlainDateTime, undefined] | ||
| | [Temporal.PlainDateTime, Temporal.PlainDateTime] | ||
| | undefined | ||
| ): boolean { | ||
| const rangeStart = | ||
| rangeValue?.[0] instanceof Temporal.PlainDateTime | ||
| ? rangeValue[0].toPlainDate() | ||
| : rangeValue?.[0]; | ||
|
|
||
| const rangeEnd = | ||
| rangeValue?.[1] instanceof Temporal.PlainDateTime | ||
| ? rangeValue[1].toPlainDate() | ||
| : rangeValue?.[1]; | ||
|
|
||
| return ( | ||
| !!rangeStart && | ||
| !!rangeEnd && | ||
| Temporal.PlainDate.compare(date, rangeStart) >= 0 && | ||
| Temporal.PlainDate.compare(date, rangeEnd) <= 0 | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { Temporal } from "@js-temporal/polyfill"; | ||
| import { expect, test } from "vitest"; | ||
| import { isDateWithinRange } from "../src/isDateWithinRange"; | ||
|
|
||
| // helpers | ||
| const date = (year: number, month: number, day: number) => | ||
| Temporal.PlainDate.from({ year, month, day }); | ||
|
|
||
| const dt = (year: number, month: number, day: number) => | ||
| Temporal.PlainDateTime.from({ year, month, day, hour: 0 }); | ||
|
|
||
| // ── closed range (isRangeSelected use case) ────────────────────────────────── | ||
|
|
||
| test("isDateWithinRange: false when rangeValue is undefined", () => { | ||
| expect(isDateWithinRange(date(2022, 3, 5), undefined)).toBe(false); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: false when only start is set", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 5), [date(2022, 3, 1), undefined]) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: true for date inside range", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 5), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: true for date on range start", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 1), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: true for date on range end", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 10), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: false for date before range start", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 2, 28), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: false for date after range end", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 11), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: works with PlainDateTime range", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 5), [dt(2022, 3, 1), dt(2022, 3, 10)]) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| // ── bidirectional hover interval (isRangeHovered use case) ─────────────────── | ||
| // In Calendar.tsx: isRangeHovered uses | ||
| // isDateWithinRange(date, [rangeStart, hoverValue]) || | ||
| // isDateWithinRange(date, [hoverValue, rangeStart]) | ||
|
|
||
| test("isDateWithinRange: forward hover — date inside [start, hover]", () => { | ||
| // start=Mar 1, hover=Mar 10, date=Mar 5 → in [1, 10] | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 5), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: backward hover — date inside [hover, start]", () => { | ||
| // start=Mar 10, hover=Mar 1 → check [hover=1, start=10] | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 5), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: forward hover — date on start boundary", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 1), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: forward hover — date on hover boundary", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 10), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: false for date outside forward hover interval", () => { | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 11), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: false for date outside backward hover interval", () => { | ||
| // start=Mar 10, hover=Mar 1 → check [hover=1, start=10], date=Mar 11 outside | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 11), [date(2022, 3, 1), date(2022, 3, 10)]) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("isDateWithinRange: works with PlainDateTime start in hover range", () => { | ||
| // PlainDateTime start converts to PlainDate for comparison | ||
| expect( | ||
| isDateWithinRange(date(2022, 3, 5), [dt(2022, 3, 1), dt(2022, 3, 10)]) | ||
| ).toBe(true); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.