chore: date picker year range#6781
Conversation
WalkthroughThe pull request refactors the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant C as Calendar Component
participant DP as DayPicker
U->>C: Open calendar
C->>C: Compute current year
C->>C: Calculate 'thirtyYearsAgoFirstDay' and 'thirtyYearsFromNowFirstDay'
C->>DP: Render DayPicker with startMonth and endMonth props
DP-->>C: Return rendered calendar view
C-->>U: Display calendar with defined month range
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/ui/src/calendar.tsx (1)
12-14: Consider optimizing with useMemo.These date calculations are performed on every render, which is unnecessary since they depend only on the current year. Consider memoizing these values with
useMemoto improve performance.export const Calendar = ({ className, classNames, showOutsideDays = true, ...props }: CalendarProps) => { - const currentYear = new Date().getFullYear(); - const thirtyYearsAgoFirstDay = new Date(currentYear - 30, 0, 1); - const thirtyYearsFromNowFirstDay = new Date(currentYear + 30, 11, 31); + const [thirtyYearsAgoFirstDay, thirtyYearsFromNowFirstDay] = React.useMemo(() => { + const currentYear = new Date().getFullYear(); + return [ + new Date(currentYear - 30, 0, 1), + new Date(currentYear + 30, 11, 31) + ]; + }, []);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/ui/src/calendar.tsx(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Analyze (javascript)
- GitHub Check: Analyze (python)
🔇 Additional comments (2)
packages/ui/src/calendar.tsx (2)
11-15: Function refactored correctly with date range calculation.The Calendar component has been effectively refactored from an implicit return to a block body function to accommodate the new date range logic. The calculation of 30 years before and after the current year is implemented correctly, with appropriate use of month indices (0 for January, 11 for December).
78-80: Date range correctly applied to DayPicker.The new date range props are properly passed to the DayPicker component, which will constrain the selectable dates to the specified 30-year window as required by the PR objectives.
Description
This PR updates the year range of all date pickers to show +- 30 years from the current year.
Type of Change
Summary by CodeRabbit