feat: add customizable calendar icon#4295
Conversation
Introduce the ability to customize the calendar icon used in the DatePicker. This is achieved by allowing a new prop which can accept a string (class name) or a React component. This aims to enhance the component's flexibility and user customization options.
There was a problem hiding this comment.
✅ This pull request was sent to the PullRequest network.
@frankops11 you can click here to see the review status or cancel the code review job.
There was a problem hiding this comment.
It might be worth adding an example for the second use case, but outside of that this looks like a solid feature to add and I see no issues with the implementation to prevent this from moving forward
Reviewed with ❤️ by PullRequest
| showIcon | ||
| selected={startDate} | ||
| onChange={(date) => setStartDate(date)} | ||
| icon="fa fa-calendar" |
There was a problem hiding this comment.
James, good call on the SVG component example. I'll add that in and push it soon. Thanks!
There was a problem hiding this comment.
Hi James,
I've added the examples! 🚀 The SVG one isn’t as clean since I embedded the SVG directly, but I hope it makes sense. :D
Cheers!
There was a problem hiding this comment.
This looks really useful, and thanks for writing so much in the PR description.
The only comment I really have for improvement is it could be nice to have some tests for this.
Reviewed with ❤️ by PullRequest
Hi Dallas, Absolutely! I've attached a few, looking forward to your feedback! 😄
Cheers! |
There was a problem hiding this comment.
This looks really useful, and thanks for writing so much in the PR description.
The only comment I really have for improvement is it could be nice to have some tests for this.
Reviewed with ❤️ by PullRequest
Hi Dallas,
Absolutely! I've attached a few, looking forward to your feedback! 😄
![]()
Cheers!
Codecov Report
@@ Coverage Diff @@
## main #4295 +/- ##
==========================================
+ Coverage 96.52% 96.54% +0.01%
==========================================
Files 25 27 +2
Lines 2358 2370 +12
Branches 962 965 +3
==========================================
+ Hits 2276 2288 +12
Misses 82 82
|
|
Hey @martijnrusschen! I'm Francisco, and I've been poking around and contributing a bit to react-datepicker lately. Just shot a PR your way with a feature that allows for more versatile calendar icon customization. Have you had a chance to take a look? I’d love to hear your thoughts and find out if there’s a chance we could merge it into main. Along the way, I've also been thinking about a couple of things that could be cool for the project. For instance, I'm considering playing around with VitePress to propose a redesign of the documentation website. It’s not bad as it stands, but I’ve got some ideas that might make it a bit more polished and user-friendly. Would you be open to discussing this? I'm keen on continuing to contribute to the project, both in improvements and solving issues. Looking forward to your feedback on the PR and chatting about these ideas. Cheers! |
martijnrusschen
left a comment
There was a problem hiding this comment.
Thank you for the extensive examples and write-up. This is looking good!
|
@frankops11 Thanks for your contribution. I'd love to hear your thoughts on improving the documentation site. The component has significantly grown over the years and could use some rework to make it future proof. |
Hey, thanks a lot for merging the PR and for being open to dialogue about improving the documentation site! I'm particularly excited about infusing the documentation site with a modern, sleek aesthetic, and VitePress strikes me as an ideal tool for this. Despite its Vue.js foundation, we can utilize Whyframe to render React previews and examples. This would not only allow users to explore live demos but also interact with and understand the code in an approachable manner. Diving into react-datepicker component enhancements: TypeScript Compatibility: Generating or exposing TypeScript definitions should enhance the experience for TypeScript projects. A full TypeScript migration is in my thoughts too but let's indeed tread step by step. Eager to dive into your thoughts and, upon approval, immerse myself in implementing these enhancements! Warm regards, |
|
Let's move this discussion to an issue or discussion so we can chat about the initiatives. |



🚀 Proposal:
Enhance the customization capabilities of the calendar icon in the
DatePickercomponent, allowing the use of custom icons and not solely the default provided icon.🏗 Changes Made:
New
iconProperty:iconprop that accepts either a string (icon class name) or a React component (e.g., a custom SVG).iconis a string, an<i>element is rendered with that string as its class name.iconis a React component, it is rendered as-is.New
calendarIconClassNameProperty:calendarIconClassNameprop for further icon styling customization.calendarIconClassNamewill be added as an additional CSS class to the calendar icon, allowing enhanced style customization.Code Refactor:
CalendarIcon) for improved code readability and maintainability.renderInputContainermethod to utilize the newCalendarIconcomponent.🎯 Motivation:
The inspiration behind these changes is to bestow developers with greater control over the
DatePicker's display. By enabling calendar icon customization, we enhance the developers' UI control over theDatePickerwithout sacrificing functionality or user experience.👀 How to Use the New Feature:
You can now utilize various renowned icon libraries, such as Font Awesome, Material Icons, or your custom SVGs, with the new
iconprop. Here are examples of how to implement this:🔄 Backward Compatibility:
It is pivotal to note that these changes have been implemented to ensure backward compatibility. Existing implementations of the
DatePickerusing theshowIconprop will continue to function as before, displaying the default calendar icon if noiconprop is provided.📝 Final Notes:
These proposed changes aim to deliver a flexible solution to accommodate various needs without introducing significant overhead to the codebase or altering the API properties in a way that disrupts existing implementations. I am open to feedback and suggestions to refine this proposal and hope that this change brings valuable additions to the
react-datepickeruser community.