feat(calendar): add useSelection hook for date selection#442
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
added 7 commits
March 12, 2026 13:30
Add Selection type definitions (Matcher, DateRange, CalendarBodyCell, SelectionCellProps, RangeSelectionCellProps) and matchDate utility for flexible date matching patterns. Unify DateCell and CalendarBodyCell by making CalendarBodyCell extend DateCell, establishing an explicit type contract between calendar core and selection layers.
Implement useSelection hook supporting three selection modes: - single: select one date with optional required constraint - range: select date range with min/max day constraints - multiple: toggle multiple dates with min/max count constraints Each mode enriches the calendar body cells with selection state (isSelected, isDisabled, isRangeStart, isRangeEnd, isInRange), enabling headless rendering of selection UI. Internally split into useSingleSelection, useRangeSelection, and useMultipleSelection to comply with Rules of Hooks while exposing a single useSelection entry point.
Add storybook stories demonstrating three selection modes: - Single: select one date, weekends disabled - Range: select date range with min/max constraints - Multiple: toggle up to 5 dates, past dates disabled
Add React example page showcasing useSelection hook with three tabbed demos (Single, Range, Multiple) using Chakra UI Table components, consistent with the existing calendar example style.
Move matchDate/matchDateArray tests from useSelection.test.ts into
a dedicated matchDate.test.ts, consistent with other utility tests.
Add edge case coverage:
- empty Date[] and { dayOfWeek: [] }
- { before }/{ after } boundary exclusivity
- { from, to } with same-day range
- time-insensitive Date comparison
- always true/false function matchers
- Date[] treated as single Matcher vs Matcher[]
- mixed Matcher array with multiple matcher types
d8b2c6b to
0058661
Compare
This was referenced Mar 24, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
useSelectionhook supporting three selection modes: single, range, and multipleMatchersystem for flexible date disabling (Date,Date[],{ before },{ after },{ from, to },{ dayOfWeek }, custom function)API
Selection Modes
selectedtypesingleDate | undefinedrequiredoptionrangeDateRange | undefinedmin/maxday constraintsmultipleDate[]min/maxcount constraintsDemo