-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Components: Add DateCalendar
and DateRangeCalendar
components
#70578
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
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @chihsuan! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
- Introduced `DateCalendar` and `DateRangeCalendar` components for single date and date range selection, respectively. - Implemented localization support and accessibility features in both components. - Added styles and utility functions for calendar rendering and interaction. - Created tests for both components to ensure functionality and user experience. - Updated package dependencies to include `react-day-picker` and related libraries.
68ad983
to
4f507e3
Compare
- Exported `DateCalendar`, `DateRangeCalendar`, and `TZDate` from the index file. - Updated styles in `calendar/style.scss` to remove unnecessary namespace prefixes. - Imported calendar styles in the main `style.scss`. - Changed story titles for `DateCalendar` and `DateRangeCalendar` to reflect the correct component hierarchy.
bdaeaf1
to
275b4a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @chihsuan!
Before exporting the component from the package (thus making it a public API), I wonder if we should test the component in real-case scenario first — unless you're already using this component in WooCommerce?
(One small note — for ease of review, it would have been better to have an initial commit only containing the raw pasted code. It would have made it easier to distinguish the actual code changes added in Gutenberg compared to the original component.)
* @param root0.onChange | ||
* @param root0.value | ||
*/ | ||
export function useControlledValue< T >( { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a follow-up, we should try to re-use the existing useControlledValue
hook in the package https://github.com/WordPress/gutenberg/blob/2dd93a3b957906412f6b4d8c547d8326f2ba8b78/packages/components/src/calendar/utils/use-controlled-value.ts
packages/components/src/calendar/stories/date-calendar.story.tsx
Outdated
Show resolved
Hide resolved
packages/components/src/calendar/stories/date-range-calendar.story.tsx
Outdated
Show resolved
Hide resolved
The styles also seem to be off compared to the original copy of the component:
Likely, something broke either when refactoring classnames and selectors, or when refactoring colro variables. |
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
- Updated parameter documentation for clarity by renaming `root0` to `props` and adjusting the parameter descriptions accordingly.
…tory.tsx Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
- Replaced CSS custom properties with SCSS variables for better maintainability in `style.scss`. - Updated button and navigation dimensions, focus outlines, and background colors to utilize the new variable definitions.
Good catch! @ciampo Yes, color variables were not set correctly. I've fixed it in cf6c3d5. Screen.Recording.2025-07-04.at.11.58.19.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in Slack, we're using this component in WooCommerce Analytics and don’t have any issues with it.
Cool, I guess we can leave the package exports, then!
I apologize for not clarifying this in the PR description. The initial commit does contain only the raw code without any modifications.
My bad, too — I checked, saw the scss
file (instead of a CSS) and for some reason I assumed that wasn't the original component code. I must have gotten confused with the CSS modules setup we have in place in other repos 😅
Yes, color variables were not set correctly. I've fixed it
I confirm that styles look good now :)
packages/components/src/calendar/utils/use-localization-props.ts
Outdated
Show resolved
Hide resolved
packages/components/src/calendar/stories/date-calendar.story.tsx
Outdated
Show resolved
Hide resolved
packages/components/src/calendar/stories/date-range-calendar.story.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
…r and date-range-calendar test files.
…tly instead of awaiting it - Adjusted all test cases in both `date-calendar.tsx` and `date-range-calendar.tsx` to reflect this change, improving test performance and readability.
- Updated the DateCalendar test to include a comment explaining the use of "Etc/GMT+2" for time zone, highlighting compatibility with Node v22.
- Updated the `today`, `tomorrow`, and `yesterday` variables in `date-calendar.tsx` and `date-range-calendar.tsx` tests to ensure they are consistently set to the start of the day. - Added a configuration to run tests in UTC timezone to avoid discrepancies based on system timezone.
- Changed the focus outline property in `style.scss` to utilize the CSS variable `--wp-admin-border-width-focus`, enhancing consistency and maintainability.
Thanks, @ciampo, I've made the suggested changes. 🙇♂️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @chihsuan , for the patience in addressing all of my feedback — code changes LGTM and both components test well in Storybook 🚀
Would you be able to explore/iterate on #70578 (comment) in a follow-up PR?
I added the "Needs Dev Note" Label because I think this is a great new component we should defiantly highlight when it ships in WordPress Core 👍 :) |
Yes, I can help with that. 🙂 |
@fabiankaegy I'm removing the "needs dev note" label for now, as I think we want to be a bit more cautious with the way we introduce the component — in #70681 I'm changing it to be a private API. Happy to add the label back in case the component is made public, though! |
What?
Related to Automattic/wp-calypso#102989
This PR introduces new
DateCalendar
andDateRangeCalendar
components built on the react-day-picker library, originally implemented by @ciampo, with the following changes to make it follow the Gutenberg guidelines/patterns:styles.module.scss
tostyle.scss
.calendar__*
to.components-calendar__*
stories/
andtests/
directory respectivelycc @oandregal @youknowriad
Why?
Current limitations:
DatePicker
(@wordpress/components) lacks date range support, whileDateRange
(Calypso) only handles ranges and requires moment.js.Create a unified Calendar component that supports both single dates and date ranges, with flexible layout options.
How?
Testing Instructions
DateCalendar
andDateRangeCalendar
storiesTesting Instructions for Keyboard
Screenshots or screencast
Screen.Recording.2025-07-01.at.17.20.17.mov