flowbite-react
flowbite-react copied to clipboard
Feat/date value datepicker
- [x] I have followed the Your First Code Contribution section of the Contributing guide
It was added a new property called dateValue, which directly modifies the date inside of the datepicker whenever it's necessary, also the view is set to this selected date, automatically, independently from the type of view.
It closes #1187 #1055 #1039 #1167
The prop added is merely optional and will not cause any breaking change, test coverage is basically set and documentation is covered as well.
Summary by CodeRabbit
-
New Features
- Added
value
,defaultValue
, andlabel
controls for Datepicker customization. - Introduced new story variants for different date scenarios.
- Added
-
Improvements
- Enhanced Datepicker to handle
value
anddefaultValue
based on range constraints. - Improved state management for selected and view dates.
- Simplified logic for clearing selected dates.
- Enhanced Datepicker to handle
-
Bug Fixes
- Ensured robust date comparisons by checking for
selectedDate
before performing operations.
- Ensured robust date comparisons by checking for
-
Documentation
- Added a new section on creating a controlled Datepicker using the
value
prop. - Updated documentation to explain how to clear the input by passing
null
.
- Added a new section on creating a controlled Datepicker using the
-
Tests
- Introduced new test cases for various Datepicker functionalities including date selection, clearing dates, and default date display.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
flowbite-react | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | May 16, 2024 8:49pm |
flowbite-react-storybook | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | May 16, 2024 8:49pm |
Codecov Report
Attention: Patch coverage is 80.55556%
with 7 lines
in your changes are missing coverage. Please review.
Project coverage is 97.36%. Comparing base (
7461173
) to head (baed714
). Report is 245 commits behind head on main.
:exclamation: Current head baed714 differs from pull request most recent head 2070c8b
Please upload reports for the commit 2070c8b to get more accurate results.
Additional details and impacted files
@@ Coverage Diff @@
## main #1190 +/- ##
==========================================
- Coverage 99.54% 97.36% -2.19%
==========================================
Files 163 214 +51
Lines 6621 9091 +2470
Branches 401 542 +141
==========================================
+ Hits 6591 8851 +2260
- Misses 30 240 +210
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hey @rluders , I guess now it is ready for review, could please czech it out ?
@ddiasfront I see some formatting issues
@SutuSebastian Can you describe it, please? I didn't see any formatting issues regarding the date itself, is it on the date or another stuff?
@SutuSebastian Can you describe it, please? I didn't see any formatting issues regarding the date itself, is it on the date or another stuff?
Apparently u fixed it with the last commits :D
The build failed, and inside the build fail output there was the formatting issue AFAIR.
@rluders , @SutuSebastian Okay guys, now I've fixed the issues bellow as well, including the clear functionality:
#1187 #1055 #1039 #1167
In the clear functionality scenario, I had to add a label property to be rendered whenever there's no date selected, and i set it to default "No date selected", please check it out.
Thanks for looking at the issue I opened and hats off to you for the fix @ddiasfront 🚀
@ddiasfront could you rebase it with main branch?
@ddiasfront could you rebase it with main branch?
Dun
@ddiasfront Can you let us know when you're ready for a re-review? Just want to make sure before I dive in
@ddiasfront Can you let us know when you're ready for a re-review? Just want to make sure before I dive in
It is all set @tulup-conner, @rluders , @SutuSebastian
@tulup-conner Changes dun, check the last commit, please.
Please check it out when you have some time @rluders? Would be glad to receive any feedback, or even pair if you want to :)
It's been more than two weeks....Please help us
@SutuSebastian @rluders @tulup-conner any comments ?
i know that this issue is already been created here : https://github.com/themesberg/flowbite-react/issues/1187#issue-2041570898 Here is how i am using it and it is working great along with formik validation
<Datepicker
id={'start_date'}
name={'start_date'}
minDate={new Date()}
onSelectedDateChanged={(date) => {
if(date) {
setFormDefaultValues({
...formDefaultValues,
start_date: date ? moment(date).format('YYYY-MM-DD') : ''
});
formik.setFieldValue('start_date', moment(date).format('YYYY-MM-DD'));
formik.setFieldTouched('start_date');
}
}}
defaultDate={formDefaultValues.start_date ? new Date(moment(formDefaultValues.start_date).format('YYYY-MM-DD')) : new Date()}
className={`rounded-lg ${formik.touched.start_date && formik.errors.start_date ? 'bg-red-50 border border-red-500 text-red-900' : ''}`}
value={formDefaultValues.start_date ? new Date(moment(formDefaultValues.start_date).format('YYYY-MM-DD')).toDateString() : new Date().toDateString()}
/>
Now here is the problem :
- datepicker popup doesn't select defaultValue as selected
- How do i setup date in a particular format like his YYYY-MM-DD
So is it possible for us to improve this interface
export interface DatepickerProps extends Omit<TextInputProps, 'theme'> {
open?: boolean;
inline?: boolean;
autoHide?: boolean;
showClearButton?: boolean;
labelClearButton?: string;
showTodayButton?: boolean;
labelTodayButton?: string;
defaultDate?: Date;
minDate?: Date;
maxDate?: Date;
language?: string;
weekStart?: WeekStart;
theme?: DeepPartial<FlowbiteDatepickerTheme>;
onSelectedDateChanged?: (date: Date) => void;
}
and add few more attribute like format which is the most conmanly used and it is DATE picker so there is has nothing to do with the time as well, here is the little tip to anyone who is using prisma ORM along with mysql and want to store only date then update this
start_date DateTime @default(now()) @db.Date
end_date DateTime @default(now()) @db.Date
This feature is super crucial.. seems we cannot set a VALUE otherwise (e.g. for update scenarios)?
PLEASE.. can you folks review /re-merge it? :-)
Hey, @knom this PR still needs some extra work before getting merged. Hopefully, @ddiasfront didn't drop it. :)
Thanks @rluders.
Anything I can do to help? Like do some of the merges, fixes?
what's remaining here that's blocking a merge? the only unresolved comments don't appear to be blockers
I'm catchin up with @vipertecpro and @SutuSebastian to close this one asap
⚠️ No Changeset found
Latest commit: 2070c8b4a46350a75a611911de9da4381676dbb8
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
[!WARNING]
Rate Limit Exceeded
@ddiasfront has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 30 seconds before requesting another review.
How to resolve this issue?
After the wait time has elapsed, a review can be triggered using the
@coderabbitai review
command as a PR comment. Alternatively, push new commits to this PR.We recommend that you space out your commits to avoid hitting the rate limit.
How do rate limits work?
CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information.
Commits
Files that changed from the base of the PR and between 8050049162a55cba02f5b91ba7d680d61c47bc6b and 2070c8b4a46350a75a611911de9da4381676dbb8.
Walkthrough
The Datepicker component has been significantly improved to support controlled inputs using the value
and defaultValue
props. These updates include better state management, enhanced customization options, and improved handling of date selection scenarios, allowing for programmatic updates to the selected date without manual interaction.
Changes
Files/Paths | Change Summary |
---|---|
apps/web/content/docs/components/datepicker.mdx |
Added controlled <Datepicker /> section using value prop and handling of null values. |
packages/ui/src/components/Datepicker/Datepicker.stories.tsx |
Enhanced Datepicker stories with value , defaultValue , and label controls; updated logic and added new story variants. |
packages/ui/src/components/Datepicker/Datepicker.tsx |
Replaced defaultDate with defaultValue ; added value , label , and customValue props; revamped state management and date handling. |
packages/ui/src/components/Datepicker/DatepickerContext.tsx |
Updated selectedDate type to `Date |
packages/ui/src/components/Datepicker/Views/Days.tsx |
Added check for selectedDate before comparing with currentDate in isSelected calculation. |
packages/ui/src/components/Datepicker/Views/Decades.tsx |
Updated logic to check selectedDate before invoking functions and updating the view date. |
packages/ui/src/components/Datepicker/Views/Months.tsx |
Introduced check for selectedDate before comparison with newDate using isDateEqual . |
packages/ui/src/components/Datepicker/Views/Years.tsx |
Implemented check for selectedDate before comparison with newDate using isDateEqual . |
src/components/Datepicker/Datepicker.spec.tsx |
Added test cases covering various date scenarios and interactions. |
Assessment against linked issues
Objective | Addressed | Explanation |
---|---|---|
Datepicker only changes on manual click (#1187) | ✅ |
In fields of code, where dates now dance, Controlled by props, they take their stance. With
value
set, no click's demand, The Datepicker's magic, at your command. Null clears the way, like a gentle breeze, A rabbit's touch, coding with ease. 🐇
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>.
-
Generate unit testing code for this file.
-
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitai
in a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file.
-
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitai
in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai generate interesting stats about this repository and render them as a table.
-
@coderabbitai show all the console.log statements in this repository.
-
@coderabbitai read src/utils.ts and generate unit testing code.
-
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
-
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 as PR comments)
-
@coderabbitai pause
to pause the reviews on a PR. -
@coderabbitai resume
to resume the paused reviews. -
@coderabbitai review
to trigger a review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai resolve
resolve all the CodeRabbit review comments. -
@coderabbitai help
to get help.
Additionally, you can add @coderabbitai ignore
anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configration File (.coderabbit.yaml
)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yaml
file to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.