Skip to content
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

fix(datepicker): datePicker now supports formatting of date #1314

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

dhavalveera
Copy link
Contributor

@dhavalveera dhavalveera commented Mar 25, 2024

🛠️ Enhancement: Added Date Formatting Support to DatePicker

This PR introduces date formatting support to the DatePicker component by leveraging the date-fns package. Users can now customize date formats such as dd-MMM-yyyy or dd MMM yyyy according to their preferences.

outputs/examples:

dd-MMM-yyyy // output => 11-Mar-2024

image

dd MMM yyyy // output => 11 Mar 2024

image

dd-MM-yyyyy // output => 11-03-2024

image

Summary by CodeRabbit

  • New Features

    • Introduced a new Datepicker component with customizable date formats and localization support.
    • Added documentation for setting date formats and localization in the Datepicker component.
  • Enhancements

    • Updated the Datepicker component to support multiple locales and specific date formats.
  • Documentation

    • Provided detailed guidance on date formatting and localization for the Datepicker component.
  • Tests

    • Enhanced test cases to include new date formatting options in the Datepicker component.
  • Chores

    • Added necessary dependencies to improve component functionality and development workflow.

Copy link

stackblitz bot commented Mar 25, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

vercel bot commented Mar 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-react ❌ Failed (Inspect) Apr 17, 2024 8:27am
flowbite-react-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 17, 2024 8:27am

Copy link
Contributor

coderabbitai bot commented Mar 25, 2024

Walkthrough

The recent changes enhance the Datepicker component in a UI library, focusing on date formatting and localization using date-fns. These updates make the Datepicker versatile in handling various date formats and languages.

Changes

File Path Change Summary
.../datepicker/datepicker.format.tsx, .../datepicker/datepicker.localization.tsx Introduced and updated Datepicker with specific input format and added localization support.
.../docs/components/datepicker.mdx Added documentation for date formatting and localization using inputFormat prop.
.../datepicker/index.ts Exported format from datepicker.format.
packages/ui/package.json Added build scripts and dependencies for date formatting.
.../components/Datepicker/Datepicker.spec.tsx, .../components/Datepicker/Datepicker.stories.tsx Updated test cases and added a new component with default props.
.../components/Datepicker/Datepicker.tsx, .../components/Datepicker/helpers.ts, .../components/Datepicker/DatepickerContext.tsx Enhanced support for multiple locales, custom date formats, and localization in Datepicker.

🐰✨
In the warren, beneath the moon's glow,
A Datepicker sprang up, ready to show.
With formats so wide, and locales in tow,
It hopped through the fields, where the soft winds blow.
"Pick a date!", it chirped, with a joyful crow.


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f28f280 and 95a0aeb.
Files selected for processing (2)
  • packages/ui/src/components/Datepicker/DatepickerContext.tsx (1 hunks)
  • packages/ui/src/components/Datepicker/helpers.spec.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/ui/src/components/Datepicker/helpers.spec.tsx
Additional comments not posted (2)
packages/ui/src/components/Datepicker/DatepickerContext.tsx (2)

8-8: The introduction of AvailableLocales as a type derived from the keys of date-fns/locale is a good practice for ensuring type safety and correctness.


12-12: Using AvailableLocales for the language property in DatepickerContextProps enhances type safety by ensuring only valid locale identifiers are used.


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?

Share
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.

packages/ui/package.json Outdated Show resolved Hide resolved
packages/ui/package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3d546f7 and fb35e8c.
Files ignored due to path filters (1)
  • packages/ui/package.json is excluded by: !**/*.json
Files selected for processing (7)
  • apps/web/content/docs/components/datepicker.mdx (1 hunks)
  • apps/web/examples/datepicker/datepicker.format.tsx (1 hunks)
  • apps/web/examples/datepicker/index.ts (1 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.spec.tsx (5 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.stories.tsx (1 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.tsx (4 hunks)
  • packages/ui/src/components/Datepicker/helpers.ts (3 hunks)
Additional comments: 5
apps/web/examples/datepicker/index.ts (1)
  • 2-2: The addition of the format export from datepicker.format is correctly implemented.
apps/web/examples/datepicker/datepicker.format.tsx (1)
  • 1-42: The new example file datepicker.format.tsx correctly demonstrates the usage of the inputFormat prop with the Datepicker component. The structure and export of the example are consistent with the project's standards.
packages/ui/src/components/Datepicker/Datepicker.stories.tsx (1)
  • 64-77: The addition of the FormattedDate story in Datepicker.stories.tsx correctly showcases the new inputFormat prop with a sample format. This enhances the documentation and provides a practical example of the new feature.
apps/web/content/docs/components/datepicker.mdx (1)
  • 22-29: The addition of the documentation section for setting the date format using the inputFormat prop is clear and informative. The note on format conventions is particularly helpful for guiding users in correctly specifying date formats.
packages/ui/src/components/Datepicker/Datepicker.tsx (1)
  • 100-100: The addition of the inputFormat property to the DatepickerProps interface and its usage in DatepickerRender are correctly implemented. The default value and its application in date formatting calls enhance the component's flexibility and align with the PR objectives.

Also applies to: 121-121, 206-206, 209-209, 277-277

packages/ui/src/components/Datepicker/Datepicker.spec.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fb35e8c and 97c0d72.
Files selected for processing (1)
  • packages/ui/src/components/Datepicker/helpers.spec.tsx (1 hunks)

packages/ui/src/components/Datepicker/helpers.spec.tsx Outdated Show resolved Hide resolved
packages/ui/src/components/Datepicker/helpers.spec.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 97c0d72 and 876771a.
Files ignored due to path filters (1)
  • packages/ui/package.json is excluded by: !**/*.json
Files selected for processing (5)
  • apps/web/examples/datepicker/datepicker.format.tsx (1 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.spec.tsx (5 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.tsx (3 hunks)
  • packages/ui/src/components/Datepicker/helpers.spec.tsx (1 hunks)
  • packages/ui/src/components/Datepicker/helpers.ts (3 hunks)
Files skipped from review as they are similar to previous changes (4)
  • apps/web/examples/datepicker/datepicker.format.tsx
  • packages/ui/src/components/Datepicker/Datepicker.spec.tsx
  • packages/ui/src/components/Datepicker/Datepicker.tsx
  • packages/ui/src/components/Datepicker/helpers.spec.tsx
Additional comments: 1
packages/ui/src/components/Datepicker/helpers.ts (1)
  • 1-1: The import of DateFNSFormat from 'date-fns' is correctly added to support date formatting functionality.

packages/ui/src/components/Datepicker/helpers.ts Outdated Show resolved Hide resolved
@SutuSebastian
Copy link
Collaborator

btw, what code editor are u using @dhavalveera ? It seems to me that u are not formatting the code on-save, or at all.

@dhavalveera
Copy link
Contributor Author

btw, what code editor are u using @dhavalveera ? It seems to me that u are not formatting the code on-save, or at all.

I'm using VSCode, and when I do save (Ctrl + S) it saves the files for me, but I'll check again

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 876771a and 3a690dd.
Files selected for processing (9)
  • apps/web/content/docs/components/datepicker.mdx (1 hunks)
  • apps/web/examples/datepicker/datepicker.format.tsx (1 hunks)
  • apps/web/examples/datepicker/datepicker.localization.tsx (1 hunks)
  • apps/web/examples/datepicker/index.ts (1 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.spec.tsx (5 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.stories.tsx (1 hunks)
  • packages/ui/src/components/Datepicker/Datepicker.tsx (4 hunks)
  • packages/ui/src/components/Datepicker/helpers.spec.tsx (1 hunks)
  • packages/ui/src/components/Datepicker/helpers.ts (3 hunks)
Files skipped from review as they are similar to previous changes (5)
  • apps/web/examples/datepicker/datepicker.format.tsx
  • apps/web/examples/datepicker/index.ts
  • packages/ui/src/components/Datepicker/Datepicker.spec.tsx
  • packages/ui/src/components/Datepicker/Datepicker.stories.tsx
  • packages/ui/src/components/Datepicker/Datepicker.tsx
Additional comments: 11
apps/web/examples/datepicker/datepicker.localization.tsx (3)
  • 10-10: The update to the language attribute and label attributes for the Datepicker component enhances consistency and ensures compatibility with the date-fns package.
  • 18-18: The consistency in updating the language attribute and label attributes across different parts of the file ensures uniformity in the component's usage.
  • 23-23: The consistency in updating the language attribute and label attributes across different parts of the file ensures uniformity in the component's usage.
apps/web/content/docs/components/datepicker.mdx (2)
  • 22-30: The addition of a section for setting the date format using the inputFormat prop, along with notes on date format conventions and the reliance on date-fns, is crucial for informing users about the new formatting capabilities of the Datepicker component.
  • 38-38: The note on the reliance of the Datepicker component on date-fns for localization, and guiding users to refer to available localizations from date-fns, is important for correctly utilizing the localization feature.
packages/ui/src/components/Datepicker/helpers.ts (3)
  • 1-2: The addition of imports for DateFNSFormat and DateFNSLocale is necessary for enabling the new date formatting feature, aligning with the objective of providing customizable date formatting capabilities.
  • 4-5: Defining a type for available locales enhances type safety and clarity in the code, supporting the new date formatting feature by specifying the types of locales that can be used.
  • 105-116: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [108-127]

The modification of the getFormattedDate function to include a dateFormat parameter and utilize DateFNSFormat for date formatting aligns with best practices for localization support. The approach to determining the locale ensures that the correct locale object is used for formatting.

packages/ui/src/components/Datepicker/helpers.spec.tsx (3)
  • 157-157: The update to include an additional argument for the date format string in the getFormattedDate function call is necessary for testing the new formatting capabilities. The specified format matches the expected output, ensuring the test correctly assesses the functionality.
  • 164-164: The update to include an additional argument for the date format string in the getFormattedDate function call, along with specified options, is necessary for testing the new formatting capabilities. The approach is consistent with the objective of testing the new feature.
  • 170-170: The update to test the localization feature by specifying a different language code is important for ensuring the feature works as expected across different locales. This is crucial for testing the localization aspect of the new feature.

Copy link

changeset-bot bot commented Mar 30, 2024

⚠️ No Changeset found

Latest commit: 95a0aeb

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3a690dd and 73e6290.
Files selected for processing (1)
  • packages/ui/package.json (1 hunks)
Additional Context Used
Additional comments not posted (1)
packages/ui/package.json (1)

80-80: The addition of date-fns version 3.6.0 to the dependencies is correctly implemented and aligns with the PR's objectives. Using a fixed version ensures stability but consider the trade-offs between fixed versions and version ranges for future maintenance.

@rluders
Copy link
Collaborator

rluders commented Apr 17, 2024

@dhavalveera could you please rebase it with main? I want to get this one approved. :)

@dhavalveera
Copy link
Contributor Author

@dhavalveera could you please rebase it with main? I want to get this one approved. :)

@rluders --- this conflicts, can't be done from my end, as I don't have the write access to this repository.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

@dhavalveera
Copy link
Contributor Author

@rluders --- it seems like I need to modify the helpers.ts where it's using new Intl.DateTimeFormat() as the language type is passed is getting incorrect, as date-fns package have locales as enUS whereas INTL needs it as en-US, any guidance please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants