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

feat(input-otp): Adding Input OTP component #3748

Conversation

macci001
Copy link
Contributor

@macci001 macci001 commented Sep 13, 2024

Closes #2678

📝 Description

PR adds the input-otp componenet

⛳️ Current behavior (updates)

Currently NextUI do not have input-otp component.

🚀 New behavior

  • Default Color- Dark
    Screenshot 2024-11-14 at 3 37 52 PM

  • Primary Color- Dark
    Screenshot 2024-11-14 at 3 45 51 PM

  • Secondary Color- Dark
    Screenshot 2024-11-14 at 3 47 41 PM

  • Warning Color- Dark
    Screenshot 2024-11-14 at 3 48 45 PM

  • Danger Color- Dark
    Screenshot 2024-11-14 at 3 51 04 PM

  • Default Color- Light
    Screenshot 2024-11-14 at 3 37 46 PM

  • Primary Color- Light
    Screenshot 2024-11-14 at 3 45 57 PM

  • Secondary Color- Light
    Screenshot 2024-11-14 at 3 47 23 PM

  • Warning Color- Light
    Screenshot 2024-11-14 at 3 49 00 PM

  • Danger Color- Light
    Screenshot 2024-11-14 at 3 51 09 PM

input-otp gets added.

💣 Is this a breaking change (Yes/No): no

📝 Additional Information

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new input-otp component for easier one-time password entry.
    • Automatic focus on the next input field and input length validation enhance usability.
    • Integrated with existing themes for a consistent design.
    • Customizable properties for appearance, including variants and sizes.
  • Tests

    • Added unit tests to validate the functionality of the input-otp component.
  • Documentation

    • Created a README for the input-otp component to assist users.
    • Added comprehensive documentation detailing functionality and customization options.

Copy link

changeset-bot bot commented Sep 13, 2024

🦋 Changeset detected

Latest commit: 0eab6a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@nextui-org/input-otp Minor
@nextui-org/theme Minor
@nextui-org/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Sep 13, 2024

Someone is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

This update introduces a new input-otp component to the project, designed for user-friendly entry of one-time passwords (OTPs). It features automatic focus management, input validation, and visual feedback, ensuring a consistent design with existing themes. A suite of unit tests is included to validate the component's functionality and integration with React Hook Form. Additionally, documentation and package configuration are provided for the new component.

Changes

File(s) Change Summary
.changeset/spotty-flies-jump.md Added AI-generated summary of changes.
packages/components/input-otp/src/input-otp.tsx Added InputOtp component with focus management and input handling.
packages/components/input-otp/src/use-input-otp.ts Added useInputOtp hook for managing OTP input logic.
packages/components/input-otp/stories/input-otp.stories.tsx Added Storybook configuration for InputOtp component.
packages/components/input-otp/package.json Added package configuration for @nextui-org/input-otp.
packages/components/input-otp/README.md Added documentation for input-otp component.
packages/core/theme/src/components/input-otp.ts Added theming support for input-otp.
index.ts Updated exports for InputOtp and related types.
packages/core/theme/src/components/input-otp.ts Added types and configurations for theming the input-otp component.
apps/docs/content/docs/components/input-otp.mdx Added detailed documentation for the InputOtp component.
routes.json Added new entry for input-otp documentation.
New files in packages/components/input-otp: allowedKeys.ts, colors.ts, controlled.ts, etc. Introduced various utility files for the InputOtp component configurations and usage.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InputOtp
    participant Form

    User->>InputOtp: Enter OTP digit
    InputOtp->>InputOtp: Validate input
    InputOtp->>InputOtp: Focus next input field
    InputOtp->>Form: Submit OTP
    Form->>Form: Process OTP
Loading

Assessment against linked issues

Objective Addressed Explanation
Introduce input-otp component (#[2678])
Facilitate OTP input for user-friendly access (#[2678])

Possibly related PRs

Suggested labels

📋 Scope : Docs, 👀 Status: In Review

Suggested reviewers

  • wingkwong
  • jrgarciadev

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@wingkwong wingkwong added this to the v2.5.0 milestone Sep 13, 2024
@macci001 macci001 marked this pull request as ready for review September 15, 2024 17:51
@macci001
Copy link
Contributor Author

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Sep 15, 2024

Actions performed

Full review triggered.

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

Outside diff range and nitpick comments (5)
.changeset/spotty-flies-jump.md (2)

2-3: Consider using a minor version bump for the new component.

Since you're adding a new input-otp component, it would be more appropriate to use a minor version bump (minor) instead of a patch (patch) for the @nextui-org/input-otp package. Patch versions are typically used for bug fixes, while minor versions are used for new features that are non-breaking.

-"@nextui-org/input-otp": patch
+"@nextui-org/input-otp": minor
 "@nextui-org/theme": patch

6-6: Provide more context in the changeset message.

The current changeset message briefly mentions the addition of the new input-otp component. To provide more clarity and context for the change, consider expanding the message to include details such as:

  • The motivation behind adding this component (e.g., to facilitate the input of one-time passwords)
  • How the component fits into the overall NextUI library
  • Any notable features or benefits of using this component
packages/components/input-otp/README.md (2)

1-5: LGTM! Consider using the synonym "brief" to strengthen the wording.

The component description is concise and clearly states the purpose of the component. It also sets the context for the intended audience by mentioning that it is an internal utility.

Based on the static analysis hint, consider using the synonym "brief" instead of "quick" to strengthen the wording:

-A Quick description of the component
+A brief description of the component
Tools
LanguageTool

[style] ~3-~3: Consider using the synonym “brief” (= concise, using a few words, not lasting long) to strengthen your wording.
Context: # @nextui-org/input-otp A Quick description of the component > This is...

(QUICK_BRIEF)


15-19: LGTM! Add a comma before "please" for grammatical correctness.

The contribution section encourages community involvement by referring to the contribution guidelines.

Based on the static analysis hint, add a comma before "please" at the end of the sentence for grammatical correctness:

-Yes please! See the
+Yes, please! See the
Tools
LanguageTool

[typographical] ~17-~17: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

packages/components/input-otp/stories/input-otp.stories.tsx (1)

39-39: Consider making the otplength prop configurable.

The Template function currently hardcodes the otplength prop to 4. To enhance the flexibility of the InputOtp component in the Storybook, consider making the otplength prop configurable through the Storybook controls.

You can add the otplength prop to the argTypes object and provide a control type and options for selection. For example:

argTypes: {
  // ...existing argTypes
  otplength: {
    control: { type: "number", min: 1, max: 10 },
    defaultValue: 4,
  },
},

Then, update the Template function to use the otplength prop from the args:

const Template = (args: InputOtpProps) => <InputOtp {...args} />;

This way, users can easily configure the otplength prop directly in the Storybook, providing more flexibility and customization options.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5b5a974 and 84ac1d0.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (13)
  • .changeset/spotty-flies-jump.md (1 hunks)
  • packages/components/input-otp/README.md (1 hunks)
  • packages/components/input-otp/tests/input-otp.test.tsx (1 hunks)
  • packages/components/input-otp/package.json (1 hunks)
  • packages/components/input-otp/src/index.ts (1 hunks)
  • packages/components/input-otp/src/input-otp-segment.tsx (1 hunks)
  • packages/components/input-otp/src/input-otp.tsx (1 hunks)
  • packages/components/input-otp/src/use-input-otp.ts (1 hunks)
  • packages/components/input-otp/stories/input-otp.stories.tsx (1 hunks)
  • packages/components/input-otp/tsconfig.json (1 hunks)
  • packages/components/input-otp/tsup.config.ts (1 hunks)
  • packages/core/theme/src/components/index.ts (1 hunks)
  • packages/core/theme/src/components/input-otp.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/components/input-otp/src/index.ts
Additional context used
LanguageTool
packages/components/input-otp/README.md

[style] ~3-~3: Consider using the synonym “brief” (= concise, using a few words, not lasting long) to strengthen your wording.
Context: # @nextui-org/input-otp A Quick description of the component > This is...

(QUICK_BRIEF)


[typographical] ~17-~17: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

Additional comments not posted (34)
packages/components/input-otp/tsup.config.ts (1)

1-8: LGTM!

The tsup configuration for the OTP input component is well-defined and follows best practices:

  • Cleaning the output before each build ensures a clean slate and prevents interference from old files.
  • Targeting ECMAScript 2019 allows the use of modern JavaScript features while maintaining compatibility with older environments.
  • Providing both CommonJS and ECMAScript Modules as output formats enhances flexibility and caters to different module systems.
  • Including a banner to indicate client-side execution helps clarify the intended execution environment for the generated code.

Overall, this configuration streamlines the build process and ensures compatibility with various JavaScript environments.

packages/components/input-otp/tsconfig.json (1)

1-10: LGTM!

The TypeScript configuration for the OTP input component is well-structured and follows best practices:

  • Extending the base configuration ensures consistency with the project's TypeScript settings.
  • The baseUrl and path mapping settings facilitate cleaner imports and usage of the tailwind-variants package.
  • The include array comprehensively covers the relevant source files for compilation.

No issues or inconsistencies are identified. The configuration is appropriate for the component.

packages/components/input-otp/README.md (2)

7-13: LGTM!

The installation instructions are clear and provide the necessary commands for both Yarn and npm.


21-24: LGTM!

The license section clearly states the project's licensing under the MIT license.

packages/core/theme/src/components/index.ts (1)

20-20: LGTM!

The export statement for the new input-otp component follows the existing pattern in the file and aligns with the PR objectives. The change does not introduce any breaking changes.

packages/components/input-otp/stories/input-otp.stories.tsx (3)

1-33: LGTM!

The import statements and default export configuration for the Storybook setup are correctly structured. The argTypes object properly defines the customizable properties for the InputOtp component, enhancing its usability and flexibility within Storybook.


35-37: LGTM!

The defaultProps object is correctly defined using the spread operator to include the inputOtp.defaultVariants from the NextUI theme. This ensures consistency with the theme's default variants for the InputOtp component.


41-46: LGTM!

The Default export is correctly structured and specifies the render function and args for the Storybook story. It properly uses the Template function as the render function and sets the args using the spread operator to include the defaultProps.

packages/components/input-otp/src/input-otp-segment.tsx (4)

1-6: LGTM!

The import statements are correctly used to bring in the required dependencies for the component. The imported dependencies are used in the component implementation, and there are no apparent issues with the import statements.


7-59: LGTM!

The InputOtpSegment component implementation is well-structured and follows best practices. The use of useMemo hook is appropriate to optimize performance by memoizing values that depend on props. The component correctly calculates whether it is active based on the current value length and the focused state. The component applies conditional class names for styling using the clsx utility, which is a good practice. The component renders a div that reflects the active state and whether it contains a value, enhancing the user experience for OTP input fields. There are no apparent issues with the component implementation.


26-32: LGTM!

The use of useMemo hook is appropriate to memoize the isActive value, as it depends on the value and isInputFocused props. The calculation of the isActive value is correct and handles the edge case when the current value length is equal to the otplength and the accessorIndex is equal to otplength - 1. The dependencies array of the useMemo hook is correctly specified with [value, isInputFocused].


38-47: LGTM!

The use of useMemo hook is appropriate to memoize the displayValue, as it depends on the hasValue, value, and isActive values. The calculation of the displayValue is correct and handles the different cases based on the hasValue and isActive values. The displayValue is set to the character at the accessorIndex of the value string when hasValue is true, which is the expected behavior. The displayValue is set to a div element with the slots.caret class name when isActive is true and hasValue is false, indicating the active state of the input segment. The displayValue is set to null when both hasValue and isActive are false, which is the expected behavior.

packages/components/input-otp/package.json (3)

1-26: LGTM!

The package metadata looks good:

  • The package name follows the NextUI naming convention.
  • The version aligns with the NextUI ecosystem.
  • The main entry point correctly points to the TypeScript source file.
  • The author and repository details are consistent with other NextUI packages.

27-35: LGTM!

The package scripts are well-defined:

  • The build scripts use tsup for fast and efficient bundling.
  • The dev script enables quick development with watch mode.
  • The clean script ensures a clean build environment.
  • The typecheck script helps catch type errors early.
  • The prepack and postpack scripts maintain a clean package distribution.

36-58: LGTM!

The package dependencies are properly defined:

  • The peer dependencies ensure compatibility with React and other NextUI packages.
  • The dependencies on NextUI utility packages and React Aria libraries provide necessary functionality and accessibility features.
  • The dev dependencies include essential tools for development and testing.
  • The clean-package configuration file helps maintain a clean package structure.
packages/components/input-otp/src/input-otp.tsx (1)

1-95: LGTM! The InputOtp component is a great addition to the NextUI library.

The component is well-structured, follows best practices, and enhances the library's functionality without introducing any breaking changes. Here are a few observations and suggestions:

  1. The use of useMemo for the three sections (Segments, Input, and Helper) is a good performance optimization.
  2. The component is properly typed using TypeScript, which enhances type safety and maintainability.
  3. The component is accessible and customizable through the use of props and the useInputOtp hook.
  4. The component follows best practices such as using forwardRef for ref forwarding and displayName for better debugging.

Suggestions for improvement:

  1. Consider adding more documentation and examples to showcase the usage and customization options of the component.
  2. Consider adding unit tests to ensure the component's behavior and edge cases are properly covered.
  3. Consider adding accessibility attributes (e.g., aria-label, aria-describedby) to improve the component's accessibility.

Overall, great work on this new component! It will be a valuable addition to the NextUI library.

packages/components/input-otp/src/use-input-otp.ts (1)

83-259: Excellent work on the useInputOtp hook implementation!

The hook encapsulates the logic for managing the state and behavior of an OTP input component in a reusable and maintainable way. It uses the inputOtp function from the theme to generate the styles and slots objects, ensuring consistency with the theme. The use of the useFocusRing and useHover hooks from react-aria enhances the accessibility of the component. The validation of user input against the allowed keys regex ensures that only valid characters are entered. The getter functions provided by the hook promote a clean and readable component implementation.

Overall, the implementation is well-structured, follows best practices, and promotes reusability and maintainability.

packages/components/input-otp/__tests__/input-otp.test.tsx (12)

15-19: LGTM!

The test case correctly verifies that the component renders without errors.


21-26: LGTM!

The test case correctly verifies that the component forwards refs as expected.


28-48: LGTM!

The test case correctly verifies that clicking on the input selects the first segment and sets the appropriate attributes on the base, input, and segment elements.


50-59: LGTM!

The test case correctly verifies that the input is not focused when the component is disabled.


61-86: LGTM!

The test case correctly verifies that typing a valid digit shifts the focus to the next segment and updates the appropriate attributes on the input and segment elements.


88-115: LGTM!

The test case correctly verifies that the input can be erased using the backspace key and updates the appropriate attributes on the input and segment elements.


117-133: LGTM!

The test case correctly verifies that a value can be pasted into the input and updates the value attribute on the input element.


135-152: LGTM!

The test case correctly verifies that non-allowed inputs are not accepted by the component and do not update the value attribute on the input element or the data-active attribute on the segment elements.


154-173: LGTM!

The test case correctly verifies that inputs matching a custom regex are allowed by the component and update the value attribute on the input element and the data-active attribute on the segment elements.


175-195: LGTM!

The test case correctly verifies that the onFill callback is called when the input is completely filled by checking the value of a test variable that is updated in the callback.


240-244: LGTM!

The test case correctly verifies that the component works with default values provided by React Hook Form by checking the value attribute of the InputOtp elements.


246-262: LGTM!

The test cases correctly verify the form submission behavior when a required InputOtp field is empty or filled by checking the number of times the onSubmit callback has been called.

packages/core/theme/src/components/input-otp.ts (5)

1-4: LGTM!

The imports are correctly used for defining the component's variants and using the tv utility.


5-45: Great work on defining the component slots!

The slots are correctly defined with appropriate styling classes. The use of data attributes for conditional styling is a good practice. The slot names are descriptive and follow a consistent naming convention.


46-110: The component variants are well-defined!

The variants are correctly defined with appropriate styling classes. The variant names are descriptive and follow a consistent naming convention. The defaultVariants are also correctly defined.


111-340: Excellent use of compound variants!

The compound variants are correctly defined with appropriate styling classes. The use of compound variants provides a comprehensive styling solution for various use cases. The compound variants cover all possible combinations of variant and color.


342-346: Great job on exporting the necessary types and the component!

The exported types facilitate type safety and enhance the developer experience when using this component in TypeScript. The component is correctly exported.

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

Outside diff range and nitpick comments (3)
packages/components/input-otp/README.md (2)

3-3: Consider using "brief" instead of "quick".

To strengthen the wording and better convey the intent of a concise description, consider using the synonym "brief" instead of "quick".

-A Quick description of the component
+A brief description of the component
Tools
LanguageTool

[style] ~3-~3: Consider using the synonym “brief” (= concise, using a few words, not lasting long) to strengthen your wording.
Context: # @nextui-org/input-otp A Quick description of the component > This is...

(QUICK_BRIEF)


17-17: Add a comma before "please".

To improve readability and align with grammatical conventions, add a comma before "please" at the end of the sentence.

-Yes please! See the
+Yes, please! See the
Tools
LanguageTool

[typographical] ~17-~17: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

packages/components/input-otp/stories/input-otp.stories.tsx (1)

39-39: Consider making the otplength prop configurable.

The Template function currently hardcodes the otplength prop to 4. To make it more flexible for different use cases, consider adding otplength to the args object or providing a default value that can be overridden.

You can modify the Template function like this:

-const Template = (args: InputOtpProps) => <InputOtp {...args} otplength={4} />;
+const Template = (args: InputOtpProps) => <InputOtp {...args} otplength={args.otplength || 4} />;

This way, the otplength can be configured through the args object, and if not provided, it will default to 4.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5b5a974 and 84ac1d0.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (13)
  • .changeset/spotty-flies-jump.md (1 hunks)
  • packages/components/input-otp/README.md (1 hunks)
  • packages/components/input-otp/tests/input-otp.test.tsx (1 hunks)
  • packages/components/input-otp/package.json (1 hunks)
  • packages/components/input-otp/src/index.ts (1 hunks)
  • packages/components/input-otp/src/input-otp-segment.tsx (1 hunks)
  • packages/components/input-otp/src/input-otp.tsx (1 hunks)
  • packages/components/input-otp/src/use-input-otp.ts (1 hunks)
  • packages/components/input-otp/stories/input-otp.stories.tsx (1 hunks)
  • packages/components/input-otp/tsconfig.json (1 hunks)
  • packages/components/input-otp/tsup.config.ts (1 hunks)
  • packages/core/theme/src/components/index.ts (1 hunks)
  • packages/core/theme/src/components/input-otp.ts (1 hunks)
Additional context used
LanguageTool
packages/components/input-otp/README.md

[style] ~3-~3: Consider using the synonym “brief” (= concise, using a few words, not lasting long) to strengthen your wording.
Context: # @nextui-org/input-otp A Quick description of the component > This is...

(QUICK_BRIEF)


[typographical] ~17-~17: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

Additional comments not posted (43)
.changeset/spotty-flies-jump.md (1)

1-6: LGTM!

The changeset file follows the correct format and accurately describes the changes made in this patch release. The addition of the input-otp component is a valuable feature that improves user experience and security. The patch to the @nextui-org/theme package ensures a consistent design language for the new component.

The changes described in this file should not introduce any breaking changes or negative impacts to the codebase.

packages/components/input-otp/tsup.config.ts (5)

4-4: LGTM!

Setting clean to true is a good practice to ensure a clean build output directory.


5-5: LGTM!

Targeting "es2019" is a good balance between using modern JavaScript features and maintaining compatibility with older environments.


6-6: LGTM!

Generating both CommonJS (cjs) and ECMAScript Modules (esm) output enhances versatility for different module systems.


7-7: LGTM!

Including the "use client"; banner in the generated JavaScript files is a good practice for Next.js applications to differentiate between server-side and client-side code.


3-8: LGTM!

The tsup configuration for the OTP input component is well-defined and follows best practices. It enhances the build process by streamlining output management and ensuring compatibility across various JavaScript environments.

packages/components/input-otp/src/index.ts (1)

1-10: LGTM!

The index.ts file is well-structured and follows best practices for exporting components, types, and hooks. It serves as a centralized export hub for the InputOtp component and its related entities, which promotes better organization and ease of use.

The file has the following positive aspects:

  • Clear separation of imports, type exports, hook exports, and component exports.
  • Consistent naming convention for the component, type, and hook.
  • Named exports for clarity and avoiding naming conflicts.
  • Enhances type safety and clarity in TypeScript usage by exporting the InputOtpProps type.

Great job on creating this export file!

packages/components/input-otp/tsconfig.json (1)

1-10: LGTM!

The TypeScript configuration for the OTP input component is well-structured and follows best practices:

  • Extending the base configuration ensures consistency with the overall project settings.
  • The baseUrl and path mapping simplify import statements and module resolution within the component.
  • Including both the src directory and index.ts file ensures all necessary source files are compiled.

This setup enhances the development experience by streamlining module resolution and maintaining adherence to project-wide TypeScript configurations.

packages/components/input-otp/README.md (1)

1-24: README looks good with minor nitpicks!

The README.md file provides a clear and informative overview of the @nextui-org/input-otp component. It covers the essential aspects, including the component's purpose, installation instructions, contribution guidelines, and licensing details.

The suggested nitpicks regarding the wording and grammar are minor improvements that enhance the quality of the documentation.

Overall, the file is well-structured and serves its purpose effectively.

Tools
LanguageTool

[style] ~3-~3: Consider using the synonym “brief” (= concise, using a few words, not lasting long) to strengthen your wording.
Context: # @nextui-org/input-otp A Quick description of the component > This is...

(QUICK_BRIEF)


[typographical] ~17-~17: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

packages/core/theme/src/components/index.ts (1)

20-20: LGTM! Verify the implementation of the input-otp module.

The export statement is syntactically correct and aligns with the PR objective of adding an "Input OTP" component. However, please ensure that the implementation of the input-otp module integrates correctly with the existing codebase and follows the project's coding standards and best practices.

packages/components/input-otp/stories/input-otp.stories.tsx (3)

1-33: LGTM!

The import statements and the default export for the Storybook configuration are correctly set up. The argTypes are properly defined for the component's props, specifying their control types and options.


35-37: LGTM!

The defaultProps object is correctly defined using the spread operator to include the inputOtp.defaultVariants from the theme. This ensures consistency with the default styling of the component.


41-46: LGTM!

The Default export is correctly set up with the render property pointing to the Template function. The args property spreads the defaultProps object, ensuring that the default props are applied to the component in the Storybook.

packages/components/input-otp/src/input-otp-segment.tsx (5)

1-15: LGTM!

The imports and interface definition are correct and appropriate for the component.


17-33: LGTM!

The component definition and memoized values are implemented correctly. The use of useMemo is a good optimization technique to avoid unnecessary re-calculations.


35-47: LGTM!

The usage of clsx for combining class names and memoizing displayValue is implemented correctly. The logic for determining the displayValue based on hasValue and isActive states is accurate and enhances the user experience.


49-58: LGTM!

The component's return statement is implemented correctly. It applies the segment styles, sets the appropriate data attributes, and renders the displayValue within the div. This allows for dynamic styling and behavior based on the component's state.


1-59: Great work on the InputOtpSegment component!

The component is well-structured, modular, and reusable. It effectively manages individual segments of an OTP input field by accepting relevant props and utilizing React hooks for performance optimization. The logic and rendering are implemented correctly, providing a clean and efficient solution.

Some key highlights:

  • Proper use of memoization to optimize performance.
  • Conditional rendering based on the component's state.
  • Utilization of utility functions for combining class names.
  • Well-defined prop types using an interface.

Overall, this component is a valuable addition to the NextUI library and enhances the functionality of OTP input handling.

packages/components/input-otp/package.json (3)

1-26: Metadata and configuration look good!

The package metadata and configuration follow the NextUI conventions and best practices. The package name, main entry point, public access, and repository details are all properly specified.

Please ensure that the version 2.0.0 aligns with the NextUI release cycle and follows semantic versioning.


27-35: Package scripts are well-defined!

The package scripts cover essential tasks such as building, cleaning, type-checking, and managing package cleanliness. The use of tsup for builds, rimraf for cleaning, and clean-package for package management aligns with best practices. The dev script enhances the development experience with fast builds and watch mode.


36-58: Dependencies are properly specified!

The package dependencies are well-structured and include the necessary peer dependencies, dependencies, and dev dependencies.

  • The peer dependencies ensure compatibility with React, React DOM, and NextUI packages, which is essential for seamless integration.
  • The dependencies on NextUI utilities and React Aria libraries provide crucial functionality and accessibility features.
  • The dev dependencies include relevant packages for development and testing, such as React, React DOM, and react-hook-form for form handling.

The use of clean-package as a dev dependency aligns with the package cleanliness management setup in the scripts.

packages/components/input-otp/src/input-otp.tsx (3)

1-7: LGTM!

The imports and interfaces are properly organized and follow the necessary conventions. The InputOtpProps interface extending UseInputOtpProps allows for proper prop type checking and validation.


9-91: LGTM!

The main InputOtp component is well-structured and follows best practices:

  • The use of forwardRef allows for ref forwarding to the underlying DOM element.
  • Memoizing the sections improves performance by avoiding unnecessary re-renders.
  • The dynamic creation of InputOtpSegment components based on otplength provides flexibility.
  • The standard HTML input element serves as a fallback for OTP entry.
  • The conditional rendering in the helperSection enhances the user experience by providing relevant feedback.

The component is modular, reusable, and maintains a clean separation of concerns.


93-95: LGTM!

The component export and display name are properly set:

  • Exporting the component as the default export makes it easily accessible for use in other parts of the application.
  • Setting the display name to "NextUI.InputOtp" follows the naming convention for NextUI components.
packages/components/input-otp/src/use-input-otp.ts (1)

83-259: LGTM! The useInputOtp hook is well-implemented and provides a robust solution for managing OTP input.

The hook encapsulates the complex logic of handling OTP input, including state management, accessibility features, and input validation. It offers a flexible API through various props and callbacks, allowing customization and integration with other components.

Some key highlights:

  • Effective use of useFocusRing and useHover for enhanced accessibility and user experience.
  • Proper validation of user input against the allowed keys regex.
  • Triggering the onFill callback when the input is complete.
  • Support for dynamic class names through the classNames prop for customizable styling.

The use of TypeScript ensures type safety and helps catch potential errors during development.

Overall, this hook promotes reusability, maintainability, and provides a consistent user experience for OTP input scenarios.

packages/components/input-otp/__tests__/input-otp.test.tsx (13)

15-19: LGTM!

The test case correctly verifies that the component renders without errors.


21-26: LGTM!

The test case correctly verifies that the component forwards the ref.


28-48: LGTM!

The test case correctly verifies that clicking on the input selects the first segment.


50-59: LGTM!

The test case correctly verifies that the component does not gain focus when disabled.


61-86: LGTM!

The test case correctly verifies that typing a valid digit shifts the focus to the next segment.


88-115: LGTM!

The test case correctly verifies that the input can be erased using backspace and the active segment is updated accordingly.


117-133: LGTM!

The test case correctly verifies that a value can be pasted into the input.


135-152: LGTM!

The test case correctly verifies that non-allowed inputs are not accepted.


154-173: LGTM!

The test case correctly verifies that inputs based on a custom regex are allowed.


175-195: LGTM!

The test case correctly verifies that the onFill callback is called when the input is completely filled.


240-244: LGTM!

The test case correctly verifies that the InputOtp components work with default values.


246-252: LGTM!

The test case correctly verifies that the form is not submitted when the required field is empty.


254-262: LGTM!

The test case correctly verifies that the form is submitted when the required field is not empty.

packages/core/theme/src/components/input-otp.ts (5)

1-4: LGTM!

The import statements and the inputOtp component definition using the tv utility look good.

Also applies to: 5-5


6-45: LGTM!

The slots definition provides a clear and modular structure for the component. The use of Tailwind CSS classes allows for easy customization and consistent styling.


46-105: LGTM!

The variants definition provides flexibility in customizing the component's appearance. The use of Tailwind CSS classes ensures consistent styling across different variants.


106-110: LGTM!

The defaultVariants ensure a consistent default appearance for the component. The compoundVariants provide fine-grained control over the styling based on specific variant and color combinations. The use of Tailwind CSS classes in the compound variants maintains consistency with the overall styling approach.

Also applies to: 111-340


342-346: LGTM!

Exporting the types improves the developer experience by providing type information for the component's props, slots, and return type. Exporting the inputOtp component allows it to be imported and used in other parts of the codebase.

@macci001 macci001 force-pushed the macci001/add-input-otp-component branch from 84ac1d0 to 520b54d Compare September 16, 2024 17:41
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

Outside diff range and nitpick comments (1)
packages/components/input-otp/README.md (1)

1-24: LGTM! The README.md file provides clear and concise information about the component.

The file structure and content are well-organized, making it easy for developers to understand the purpose, installation, contribution, and licensing details of the @nextui-org/input-otp component. The clear statement that this is an internal utility not intended for public usage sets the right context for its intended audience.

Minor suggestions based on static analysis hints:

  • Consider using the synonym "brief" instead of "quick" to strengthen the wording in line 3.
  • Consider adding a comma before "please" in line 17 to improve readability.

Overall, the changes in this file are approved.

Tools
LanguageTool

[style] ~3-~3: Consider using the synonym “brief” (= concise, using a few words, not lasting long) to strengthen your wording.
Context: # @nextui-org/input-otp A Quick description of the component > This is...

(QUICK_BRIEF)


[typographical] ~17-~17: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 84ac1d0 and 520b54d.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (13)
  • .changeset/spotty-flies-jump.md (1 hunks)
  • packages/components/input-otp/README.md (1 hunks)
  • packages/components/input-otp/tests/input-otp.test.tsx (1 hunks)
  • packages/components/input-otp/package.json (1 hunks)
  • packages/components/input-otp/src/index.ts (1 hunks)
  • packages/components/input-otp/src/input-otp-segment.tsx (1 hunks)
  • packages/components/input-otp/src/input-otp.tsx (1 hunks)
  • packages/components/input-otp/src/use-input-otp.ts (1 hunks)
  • packages/components/input-otp/stories/input-otp.stories.tsx (1 hunks)
  • packages/components/input-otp/tsconfig.json (1 hunks)
  • packages/components/input-otp/tsup.config.ts (1 hunks)
  • packages/core/theme/src/components/index.ts (1 hunks)
  • packages/core/theme/src/components/input-otp.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • .changeset/spotty-flies-jump.md
  • packages/components/input-otp/tsconfig.json
Files skipped from review as they are similar to previous changes (9)
  • packages/components/input-otp/tests/input-otp.test.tsx
  • packages/components/input-otp/package.json
  • packages/components/input-otp/src/index.ts
  • packages/components/input-otp/src/input-otp-segment.tsx
  • packages/components/input-otp/src/use-input-otp.ts
  • packages/components/input-otp/stories/input-otp.stories.tsx
  • packages/components/input-otp/tsup.config.ts
  • packages/core/theme/src/components/index.ts
  • packages/core/theme/src/components/input-otp.ts
Additional context used
LanguageTool
packages/components/input-otp/README.md

[style] ~3-~3: Consider using the synonym “brief” (= concise, using a few words, not lasting long) to strengthen your wording.
Context: # @nextui-org/input-otp A Quick description of the component > This is...

(QUICK_BRIEF)


[typographical] ~17-~17: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

Additional comments not posted (3)
packages/components/input-otp/src/input-otp.tsx (3)

35-51: LGTM!

The Segments Section is implemented correctly:

  • The use of useMemo is appropriate to memoize the segment components and avoid unnecessary re-renders.
  • The Array.from(Array(otplength)) pattern is used effectively to create an array of the specified length for mapping over.
  • The InputOtpSegment component is rendered with the required props, and the key prop is correctly set using the index to ensure unique keys for each segment.

53-59: LGTM!

The Input Section is implemented correctly:

  • The use of useMemo is appropriate to memoize the input element and avoid unnecessary re-renders.
  • The input element is correctly rendered with the props returned by the getInputProps function from the useInputOtp hook.
  • The input element is wrapped in a div element with props returned by the getInputWrapperProps function from the useInputOtp hook.

61-82: LGTM!

The Helper Section is implemented correctly:

  • The use of useMemo is appropriate to memoize the helper section and avoid unnecessary re-renders.
  • The helper section is conditionally rendered based on the hasHelper prop.
  • The error message is conditionally rendered based on the isInvalid and errorMessage props.
  • The description is rendered if there is no error message.
  • The helper section is wrapped in a div element with props returned by the getHelperWrapperProps function from the useInputOtp hook.
  • The error message and description are wrapped in div elements with props returned by the getErrorMessageProps and getDescriptionProps functions from the useInputOtp hook, respectively.

@macci001 macci001 force-pushed the macci001/add-input-otp-component branch from 19d9bf5 to 9c8ed60 Compare September 16, 2024 18:23
@wingkwong wingkwong self-assigned this Sep 20, 2024
Copy link

vercel bot commented Sep 20, 2024

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

Name Status Preview Comments Updated (UTC)
nextui-docs-v2 ❌ Failed (Inspect) Oct 4, 2024 11:40am
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 11:40am

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Here's my comments.

  1. please add documentation as well
  2. please add arrow left / right key navigation

.changeset/spotty-flies-jump.md Outdated Show resolved Hide resolved
packages/components/input-otp/README.md Outdated Show resolved Hide resolved
packages/components/input-otp/README.md Outdated Show resolved Hide resolved
packages/components/input-otp/src/input-otp.tsx Outdated Show resolved Hide resolved
packages/components/input-otp/src/input-otp.tsx Outdated Show resolved Hide resolved
packages/components/input-otp/src/use-input-otp.ts Outdated Show resolved Hide resolved
packages/components/input-otp/src/use-input-otp.ts Outdated Show resolved Hide resolved
packages/components/input-otp/__tests__/input-otp.test.tsx Outdated Show resolved Hide resolved
packages/components/input-otp/__tests__/input-otp.test.tsx Outdated Show resolved Hide resolved
@wingkwong wingkwong removed the request for review from jrgarciadev September 20, 2024 12:55
@wingkwong wingkwong assigned macci001 and unassigned wingkwong Sep 20, 2024
@wingkwong wingkwong marked this pull request as draft September 20, 2024 12:55
@macci001 macci001 force-pushed the macci001/add-input-otp-component branch 2 times, most recently from bfb0b0d to a168061 Compare September 22, 2024 14:48
@macci001
Copy link
Contributor Author

macci001 commented Sep 22, 2024

Applied the comments in a168061.

Will add the documentation as well.

Also talking about keyboard left/right navigation, I thought it would be nice UX that whenever a user selects the input-otp component, the segment which needs to be filled will be in focus automatically and they can either add or remove the OTP restricting them not to navigate, given the length of the OTP is usually small. Also most of the UI libraries follows this pattern and the current implementation was done keeping this in mind.

// @wingkwong

@macci001
Copy link
Contributor Author

Comments are addressed(a168061) and docs are added(bc5286c)
The PR is ready for the next round of review.

@wingkwong, can you please have look at the PR again?

@macci001 macci001 marked this pull request as ready for review September 27, 2024 11:01
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: 24

🧹 Outside diff range and nitpick comments (41)
.changeset/spotty-flies-jump.md (1)

6-6: Consider expanding the description.

While the current description is concise, it would be beneficial to provide more details about the new input-otp component. Consider adding information about its key features, use cases, or any notable implementation details.

Here's a suggested expansion:

-Adding new input-otp component.
+Adding new input-otp component for handling one-time password inputs. This component includes features such as automatic focus shifting between input fields and customizable styling options. It enhances the user experience for authentication flows requiring OTP entry.
apps/docs/content/components/input-otp/usage.ts (1)

15-17: LGTM: Export structure is clean and extensible.

The default export using the spread operator is a good approach, allowing for easy addition of more examples in the future if needed.

For improved clarity, you might consider naming the export. For example:

const examples = {
  ...react,
};

export default examples;

This makes the purpose of the export more explicit when imported in other files.

apps/docs/content/components/input-otp/password.ts (3)

1-9: LGTM! Consider adding props documentation.

The App component structure and usage of InputOtp look good. The flex layout classes provide a responsive design, which is a nice touch for the example.

Consider adding comments or documentation for the InputOtp props to enhance the example's educational value. For instance:

<InputOtp 
  type="password" 
  // Add other common props here with explanations
  // e.g., placeholder, disabled, etc.
/>

11-13: LGTM! Consider adding type annotation.

The 'react' object structure looks good, mapping the component to a file path. This is likely used for documentation or dynamic imports.

Consider adding a type annotation for better clarity:

const react: Record<string, string> = {
  "/App.jsx": App,
};

15-17: LGTM! Consider adding export type.

The default export structure is good, allowing for easy expansion if more examples are added in the future.

Consider adding a type for the exported object for better type safety:

interface ExampleComponents {
  [key: string]: string;
}

export default {
  ...react,
} as ExampleComponents;
apps/docs/content/components/input-otp/disabled.ts (2)

1-9: LGTM! Consider adding an aria-label for accessibility.

The component implementation correctly demonstrates the usage of the disabled InputOtp component. The flex container provides a good foundation for responsive design.

Consider adding an aria-label to the InputOtp component to improve accessibility. For example:

-      <InputOtp length={4} isDisabled />
+      <InputOtp length={4} isDisabled aria-label="Disabled OTP input" />

This will help screen readers understand the purpose of the input, especially since it's disabled.


11-17: LGTM! Consider adding TypeScript types for improved type safety.

The export structure is appropriate for documentation or example purposes. The use of the spread operator ensures flexibility if additional properties are added to the react object in the future.

To improve type safety and make the code more robust, consider adding TypeScript types. For example:

interface ReactExamples {
  [key: string]: string;
}

const react: ReactExamples = {
  "/App.jsx": App,
};

export default {
  ...react,
} as const;

This will provide better type inference and catch potential errors at compile-time.

apps/docs/content/components/input-otp/required.ts (2)

1-9: LGTM! Consider adding a label for accessibility.

The App component correctly demonstrates the usage of the new InputOtp component with the required prop, which aligns with the PR objectives. The flex container provides a responsive layout, which is a good practice.

For improved accessibility, consider adding a label to the InputOtp component. You can do this by using the label prop or by wrapping it in a <label> element. For example:

 <div className="flex w-full flex-wrap md:flex-nowrap gap-4">
-  <InputOtp length={4} isRequired />
+  <InputOtp label="Enter OTP" length={4} isRequired />
 </div>

15-17: LGTM! Consider naming the export for clarity.

The default export correctly spreads the react object, allowing for easy expansion if more examples are added in the future. This is a good practice for documentation setups.

For improved clarity, consider naming the exported object. This can make it easier to understand the purpose of the export at a glance. For example:

-export default {
+export default const requiredInputOtpExample = {
   ...react,
 };
apps/docs/content/components/input-otp/readonly.ts (2)

1-9: LGTM! Consider enhancing the flex layout for better responsiveness.

The component structure effectively demonstrates the usage of InputOtp in read-only mode. The flex layout is a good start for responsive design.

Consider adding items-center to the div's className for vertical alignment:

-    <div className="flex w-full flex-wrap md:flex-nowrap gap-4">
+    <div className="flex w-full flex-wrap md:flex-nowrap gap-4 items-center">

This will ensure that the InputOtp is vertically centered when the container grows in height.


11-13: LGTM! Consider adding a comment for clarity.

The export mechanism is appropriate for a system that dynamically loads components.

Consider adding a comment to explain the purpose of this object:

+// Object containing component examples for dynamic loading in documentation
 const react = {
   "/App.jsx": App,
 };

This will help other developers understand the role of this object in the documentation system.

apps/docs/content/components/input-otp/description.ts (1)

1-17: Overall assessment: Functional but with room for improvement

The file successfully introduces an example of the new InputOtp component, which aligns with the PR objectives. However, there are several areas where the implementation could be improved:

  1. The use of string templates for component definitions, while possibly intentional for documentation purposes, could be replaced with actual JSX for better developer experience and type safety.
  2. The object structure and naming could be more semantic and type-safe.
  3. Consider adding more comprehensive examples showcasing different props and use cases of the InputOtp component.

These improvements would enhance the quality of the documentation and make it easier for developers to understand and use the new InputOtp component.

As you continue to develop this component and its documentation, consider the following:

  1. Implement a consistent structure for all component examples in the documentation.
  2. Add TypeScript type definitions for better type safety and autocompletion.
  3. Include examples that demonstrate various props, states, and edge cases of the InputOtp component.
  4. Consider adding comments within the code examples to explain key features or usage patterns.
packages/components/input-otp/src/input-otp-context.ts (1)

1-9: LGTM! Consider a minor improvement to the error message.

The implementation of the InputOtp context is well-structured and follows best practices. It correctly uses the createContext function from NextUI's react-utils, provides proper typing with UseInputOtpReturn, and exports both the provider and a custom hook for using the context.

Consider slightly modifying the error message for clarity:

-    "useInputOtpContext: `context` is undefined. Seems like you forgot to wrap all input-otp components within `<InputOtp />`",
+    "useInputOtpContext: `context` is undefined. Ensure all input-otp components are wrapped within an `<InputOtp />` component.",

This change makes the message more direct and professional while maintaining its helpfulness.

apps/docs/content/components/input-otp/controlled.ts (1)

1-15: LGTM! Consider adding input validation.

The implementation of the controlled InputOtp component is correct and follows React best practices. It demonstrates proper usage of the useState hook and correctly implements the controlled input pattern.

Consider adding input validation or formatting to ensure the OTP follows the expected pattern (e.g., only numbers, specific length). This could be done by modifying the onValueChange handler:

onValueChange={(newValue) => {
  // Example: Ensure only numbers and max 6 digits
  const formattedValue = newValue.replace(/\D/g, '').slice(0, 6);
  setValue(formattedValue);
}}
apps/docs/content/components/input-otp/radius.ts (2)

1-15: LGTM! Consider adding aria-label for accessibility.

The implementation effectively demonstrates the InputOtp component with various radius options. The use of Tailwind CSS classes ensures a responsive layout.

Consider adding an aria-label to the outer div to improve accessibility:

-    <div className="w-full flex flex-wrap gap-6">
+    <div className="w-full flex flex-wrap gap-6" aria-label="InputOtp radius examples">

17-23: LGTM! Consider using PascalCase for the object name.

The export structure is appropriate for documentation or example purposes. It allows the component to be imported as if it were a separate file, which is useful for demonstration.

Consider using PascalCase for the object name to follow common JavaScript naming conventions for objects that represent module-like structures:

-const react = {
+const React = {
   "/App.jsx": App,
 };

 export default {
-  ...react,
+  ...React,
 };
apps/docs/content/components/input-otp/variants.ts (2)

5-14: Approved with a minor suggestion for accessibility.

The component's structure is well-organized and follows React best practices. The use of flex layout and responsive classes (flex-wrap, md:flex-nowrap, etc.) ensures good adaptability across different screen sizes. The key prop is correctly used in the map function, which is crucial for React's reconciliation process.

For improved accessibility, consider adding an aria-label to the outer div to describe the purpose of this group of inputs. For example:

- <div className="w-full flex flex-wrap gap-6">
+ <div className="w-full flex flex-wrap gap-6" aria-label="Input OTP variants">

21-23: Consider simplifying the export statement.

The current export statement uses the spread operator to include the react object:

export default {
  ...react,
};

While this approach allows for easy expansion if more objects need to be included in the future, it's currently redundant as it's only spreading a single object.

You could simplify this to:

export default react;

This achieves the same result with less code. However, if you anticipate adding more objects to this export in the future, the current structure is fine and provides flexibility for future additions.

apps/docs/content/components/input-otp/colors.ts (1)

1-23: Update file extension and add explanatory comment

The file contains JSX code but has a .ts extension. Additionally, a brief comment explaining the purpose of this example would be helpful for documentation.

  1. Change the file extension from .ts to .tsx to match the content.
  2. Add a comment at the beginning of the file explaining its purpose. For example:
/**
 * This file demonstrates the usage of the InputOtp component
 * with various color options available in NextUI.
 * It's part of the documentation to showcase the component's flexibility.
 */

These changes will improve consistency and provide context for developers reading the documentation.

apps/docs/content/components/input-otp/index.ts (2)

1-13: LGTM! Well-organized imports for OTP component features.

The imports are clear, concise, and follow a consistent naming convention. Each import likely represents a different feature or configuration of the OTP input component, which is a good modular approach.

Consider using a barrel file (index.ts) in the parent directory to simplify these imports. This could reduce the number of import statements and make it easier to manage in the future. For example:

import {
  usage,
  disabled,
  readonly,
  // ... other imports
} from ".";

15-29: LGTM! Well-structured inputOtpContent object.

The inputOtpContent object effectively aggregates all OTP-related modules, providing a clean and organized way to access these features throughout the application.

To improve maintainability, consider using the object property shorthand syntax when the property names match the variable names:

export const inputOtpContent = {
  usage,
  disabled,
  readonly,
  // ... other properties
};

This makes the code more concise and easier to maintain, especially when adding or removing properties in the future.

packages/components/input-otp/README.md (2)

5-5: Minor typo in component name

There's a small typo in the component name. Please add a space between "InputOTP" and "component".

Apply this change:

-This package contains the InputOTPcomponent.
+This package contains the InputOTP component.

19-23: Consider adding a comma for improved readability

The contribution section looks good. For improved readability, consider adding a comma before "please".

Apply this change:

-Yes please! See the
+Yes, please! See the
🧰 Tools
🪛 LanguageTool

[typographical] ~21-~21: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

packages/components/input-otp/src/input-otp-segment.tsx (3)

7-9: Interface definition is clear and concise.

The InputOtpSegmentProps interface is well-defined, extending HTMLNextUIProps<"div"> for comprehensive prop support. The accessorIndex prop is a good addition for segment positioning.

Consider adding JSDoc comments to explain the purpose of accessorIndex for better code documentation. For example:

interface InputOtpSegmentProps extends HTMLNextUIProps<"div"> {
  /** The index of this segment within the OTP input */
  accessorIndex: number;
}

12-20: Context usage and state calculations are well-implemented.

The use of useInputOtpContext and useMemo for state calculations shows good performance considerations. The logic for determining isActive and hasValue is sound.

Consider adding a comment to explain the isActive calculation logic, as it's not immediately obvious. For example:

// isActive when this segment is the next to be filled or when it's the last segment and all are filled
const isActive = useMemo(
  () =>
    (value.length == accessorIndex || (value.length == length && accessorIndex == length - 1)) &&
    isInputFocused,
  [value, isInputFocused],
);

42-51: Render method is well-structured and uses best practices.

The component's render method effectively uses conditional attributes, data attributes for styling hooks, and slots for flexible composition. This approach allows for easy customization and maintains a clear separation of concerns.

Consider adding an aria-label to improve accessibility. For example:

<div
  className={clsx(slots.segment?.({class: segmentStyles}))}
  data-active={dataAttr(isActive)}
  data-has-value={dataAttr(hasValue)}
  data-slot="segment"
  aria-label={`OTP digit ${accessorIndex + 1}`}
>
  {displayValue}
</div>
packages/components/input-otp/package.json (2)

1-15: Enhance package metadata for improved discoverability and usability.

While most of the metadata is correctly set up, consider the following improvements:

  1. Add a meaningful description to the description field. This helps users understand the purpose of the package when browsing the npm registry.
  2. Expand the keywords array to include more relevant terms, such as "otp", "one-time password", "input", "nextui", "react", etc. This will improve the package's discoverability.
  3. The main field is currently set to "src/index.ts". Typically, this should point to the built JavaScript file in the dist directory. Consider changing it to "dist/index.js" or similar, depending on your build output.

Here's a suggested diff for these changes:

 {
   "name": "@nextui-org/input-otp",
   "version": "2.0.0",
-  "description": "",
+  "description": "A customizable Input OTP (One-Time Password) component for NextUI",
   "keywords": [
-    "input-otp"
+    "input-otp",
+    "otp",
+    "one-time password",
+    "input",
+    "nextui",
+    "react"
   ],
   "author": "Junior Garcia <[email protected]>",
   "homepage": "https://nextui.org",
   "license": "MIT",
-  "main": "src/index.ts",
+  "main": "dist/index.js",
   "sideEffects": false,
   "files": [
     "dist"
   ],

16-26: Configuration looks good. Consider adding a types field.

The package configuration is well set up:

  • publishConfig correctly set for public access.
  • Repository and bug reporting information properly configured.
  • Use of clean-package for maintaining a clean published package.

One suggestion to improve TypeScript integration:

Consider adding a types field to specify the location of your TypeScript declaration files. This helps TypeScript users to get better type information. Add the following line:

   "main": "dist/index.js",
+  "types": "dist/index.d.ts",
   "sideEffects": false,

This assumes that your TypeScript build process outputs declaration files to the dist directory.

Also applies to: 60-61

packages/components/input-otp/stories/input-otp.stories.tsx (5)

47-91: Template functions are well-implemented.

The three template functions (Template, WithReactHookFormTemplate, and ControlledTemplate) effectively demonstrate different aspects of the InputOtp component. They provide a good foundation for the various stories.

Consider adding a type annotation for the data parameter in the onSubmit function of WithReactHookFormTemplate:

- const onSubmit = (data: any) => {
+ const onSubmit = (data: { otp: string }) => {

This will improve type safety and make the expected shape of the form data more explicit.


93-126: Basic stories cover fundamental use cases effectively.

The Default, Required, Disabled, and ReadOnly stories provide a good overview of the InputOtp component's basic functionalities. They align well with the requirements mentioned in the past review comments.

For the ReadOnly story, consider adding a placeholder prop to demonstrate how placeholder text appears in a read-only state:

export const ReadOnly = {
  render: Template,
  args: {
    ...defaultProps,
    length: 4,
    value: "12",
    isReadOnly: true,
+   placeholder: "****",
  },
};

This will help users understand how placeholders interact with the read-only state.


128-186: Advanced stories provide comprehensive coverage of complex features.

The WithDescription, WithErrorMessage, Password, WithErrorMessageFunction, isInvalid, and Controlled stories effectively demonstrate the InputOtp component's advanced capabilities. They cover a wide range of scenarios and use cases.

In the WithErrorMessageFunction story, consider expanding the error message function to handle more validation cases:

errorMessage: (value: ValidationResult) => {
  if (value.validationDetails.tooShort) {
    return "Value is too short";
  }
+ if (value.validationDetails.empty && value.validationDetails.isRequired) {
+   return "This field is required";
+ }
+ return value.isInvalid ? "Invalid input" : undefined;
},

This will provide a more comprehensive example of how to handle different validation scenarios.


188-201: CustomWithClassNames story effectively demonstrates styling capabilities.

The CustomWithClassNames story showcases how to apply custom styles to the InputOtp component using the classNames prop. It provides a good example of customizing both the segment and caret elements.

Consider adding an example of how to style the input when it's in focus:

classNames: {
  segment: "bg-gradient-to-tr from-pink-500 to-yellow-500",
  caret: "bg-red-700",
+ input: "focus:ring-2 focus:ring-blue-500",
},

This will demonstrate how to enhance the component's visual feedback when interacted with.


1-201: Overall, excellent implementation of InputOtp stories.

The stories provide comprehensive coverage of the InputOtp component's features, from basic usage to advanced scenarios and customization. They align well with the requirements mentioned in past review comments and offer a solid foundation for users to understand and test the component.

To further enhance the stories:

  1. Consider adding a story that demonstrates the validationBehavior prop in action, showing the difference between "aria" and "native" validation behaviors.
  2. If applicable, add a story showcasing integration with a custom validation library other than React Hook Form to demonstrate the component's flexibility.

These additions would provide an even more comprehensive set of examples for users of the InputOtp component.

apps/docs/content/docs/components/input-otp.mdx (4)

29-41: LGTM: Clear import instructions and usage example provided.

The import section offers both main and individual import options, catering to different user preferences. The usage of CodeDemo suggests an interactive example, which is excellent for documentation.

Consider adding a brief description of what the basic usage example demonstrates, just before line 41. This would give users a quick overview of what to expect in the code demo.


43-113: LGTM: Comprehensive coverage of component properties and variants.

This section thoroughly documents the various properties and customization options of the InputOtp component, providing code demos for each. The inclusion of allowed keys and controlled input demonstrates advanced usage scenarios.

On line 106, consider adding a comma after "property" for better readability:

-Allowed Keys can be modified by `allowedKeys` property which accepts the regex of the keys which are allowed.
+Allowed Keys can be modified by `allowedKeys` property, which accepts the regex of the keys which are allowed.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~106-~106: Possible missing comma found.
Context: ...d Keys can be modified by allowedKeys property which accepts the regex of the keys whi...

(AI_HYDRA_LEO_MISSING_COMMA)


115-147: LGTM: Detailed explanation of slots and data attributes.

The slots section provides excellent information for customizing the component, while the data attributes section clearly explains the different states, which is crucial for styling and accessibility.

On line 123, consider adding an article before "password":

-The passwordChar represents the text styling when input-type is password. 
+The passwordChar represents the text styling when input-type is a password. 
🧰 Tools
🪛 LanguageTool

[grammar] ~123-~123: Is an article like ‘a’ or ‘an’ missing?
Context: ...esents the text styling when input-type is password. - helperWrapper: Wraps t...

(BE_NN)


[style] ~145-~145: This phrase is redundant. Consider writing “filled”.
Context: ...data-filled*: When the input-otp is completely filled. - data-disabled: When the input ...

(COMPLETELY_ANNIHILATE)


159-191: LGTM: Comprehensive API documentation provided.

The API section offers a detailed and well-structured overview of the InputOtp Props and Events, which is crucial for developers integrating the component.

Consider the following minor improvements:

  1. On line 145, remove "completely" for conciseness:
-When the input-otp is completely filled.
+When the input-otp is filled.
  1. Similarly, on line 191:
-Handler that is called when the element's value is completely filled.
+Handler that is called when the element's value is filled.
🧰 Tools
🪛 LanguageTool

[style] ~191-~191: This phrase is redundant. Consider writing “filled”.
Context: ...t is called when the element's value is completely filled. ...

(COMPLETELY_ANNIHILATE)

packages/components/input-otp/__tests__/input-otp.test.tsx (1)

260-260: Remove unnecessary CSS classes in test code

The className prop in the form element is unnecessary for the test and can be removed to simplify the code.

Update the form element:

- <form className="flex flex-col gap-4" onSubmit={handleSubmit(onSubmit)}>
+ <form onSubmit={handleSubmit(onSubmit)}>
packages/core/theme/src/components/input-otp.ts (3)

44-44: Remove unnecessary empty string in 'helperWrapper' classes

An empty string is included in the helperWrapper classes array, which is unnecessary and can be removed to clean up the code.

Apply this diff to remove the empty string:

 helperWrapper: ["text-xs", "mt-0.5", "font-extralight", ""],
+helperWrapper: ["text-xs", "mt-0.5", "font-extralight"],

115-116: Consider updating font size for 'md' size variant

The md size variant uses text-small, the same as the sm variant, while the lg variant uses text-medium. To maintain a consistent scaling of text size with the component size, consider using text-medium for the md variant.

Apply this diff to update the font size:

 md: {
-  segment: "h-10 min-h-10 w-10 min-w-10 text-small",
+  segment: "h-10 min-h-10 w-10 min-w-10 text-medium",
 },

418-418: Correct typo in comment: 'anf' should be 'and'

There's a typo in the comment on line 418. Replace 'anf' with 'and' for clarity.

Apply this diff to fix the typo:

-// isInvalid anf underlined
+// isInvalid and underlined
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 397b9fa and bc5286c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (31)
  • .changeset/spotty-flies-jump.md (1 hunks)
  • apps/docs/config/routes.json (1 hunks)
  • apps/docs/content/components/index.ts (1 hunks)
  • apps/docs/content/components/input-otp/allowedKeys.ts (1 hunks)
  • apps/docs/content/components/input-otp/colors.ts (1 hunks)
  • apps/docs/content/components/input-otp/controlled.ts (1 hunks)
  • apps/docs/content/components/input-otp/description.ts (1 hunks)
  • apps/docs/content/components/input-otp/disabled.ts (1 hunks)
  • apps/docs/content/components/input-otp/errorMessage.ts (1 hunks)
  • apps/docs/content/components/input-otp/index.ts (1 hunks)
  • apps/docs/content/components/input-otp/password.ts (1 hunks)
  • apps/docs/content/components/input-otp/radius.ts (1 hunks)
  • apps/docs/content/components/input-otp/readonly.ts (1 hunks)
  • apps/docs/content/components/input-otp/required.ts (1 hunks)
  • apps/docs/content/components/input-otp/sizes.ts (1 hunks)
  • apps/docs/content/components/input-otp/usage.ts (1 hunks)
  • apps/docs/content/components/input-otp/variants.ts (1 hunks)
  • apps/docs/content/docs/components/input-otp.mdx (1 hunks)
  • apps/docs/package.json (1 hunks)
  • apps/docs/public/sitemap-0.xml (1 hunks)
  • packages/components/input-otp/README.md (1 hunks)
  • packages/components/input-otp/tests/input-otp.test.tsx (1 hunks)
  • packages/components/input-otp/package.json (1 hunks)
  • packages/components/input-otp/src/input-otp-context.ts (1 hunks)
  • packages/components/input-otp/src/input-otp-segment.tsx (1 hunks)
  • packages/components/input-otp/src/input-otp.tsx (1 hunks)
  • packages/components/input-otp/src/use-input-otp.ts (1 hunks)
  • packages/components/input-otp/stories/input-otp.stories.tsx (1 hunks)
  • packages/core/react/package.json (1 hunks)
  • packages/core/react/src/index.ts (1 hunks)
  • packages/core/theme/src/components/input-otp.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
apps/docs/content/docs/components/input-otp.mdx

[uncategorized] ~106-~106: Possible missing comma found.
Context: ...d Keys can be modified by allowedKeys property which accepts the regex of the keys whi...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~123-~123: Is an article like ‘a’ or ‘an’ missing?
Context: ...esents the text styling when input-type is password. - helperWrapper: Wraps t...

(BE_NN)


[style] ~145-~145: This phrase is redundant. Consider writing “filled”.
Context: ...data-filled*: When the input-otp is completely filled. - data-disabled: When the input ...

(COMPLETELY_ANNIHILATE)


[style] ~191-~191: This phrase is redundant. Consider writing “filled”.
Context: ...t is called when the element's value is completely filled. ...

(COMPLETELY_ANNIHILATE)

packages/components/input-otp/README.md

[typographical] ~21-~21: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

🔇 Additional comments (37)
.changeset/spotty-flies-jump.md (1)

1-4: Version bumps look good.

The minor version bumps for both "@nextui-org/input-otp" and "@nextui-org/theme" are appropriate for introducing a new component and its associated styling changes.

apps/docs/content/components/input-otp/usage.ts (1)

11-13: LGTM: React object structure is appropriate for documentation.

The react object with the "/App.jsx" key is well-structured for documentation or example purposes. This format is commonly used in documentation systems or code playgrounds to represent file structures.

apps/docs/content/components/input-otp/required.ts (1)

11-13: LGTM! Appropriate structure for documentation.

The react object is correctly structured for documentation or example purposes. The use of the ".jsx" extension in the key is appropriate for a React component.

apps/docs/content/components/input-otp/readonly.ts (1)

15-17: LGTM! Export structure is flexible and extensible.

The export structure using the spread operator is appropriate and allows for easy addition of more examples in the future if needed.

apps/docs/content/components/input-otp/errorMessage.ts (2)

11-13: Clarify the purpose of the 'react' object.

The 'react' object is defined with a single key-value pair, mapping "/App.jsx" to the App component. However, the purpose and usage of this object are not immediately clear from the context provided.

Could you please clarify:

  1. How is this 'react' object used in the broader context of the application?
  2. Is "/App.jsx" meant to represent a file path or a route?
  3. Are there plans to add more components to this object in the future?

Understanding the intended use will help ensure that this implementation aligns with the overall architecture and design patterns of the project.


15-17: Export syntax is future-proof but currently redundant.

The use of the spread operator in the default export is a good practice for maintaining modularity and allowing easy expansion in the future. However, given that the 'react' object currently only contains one property, it's slightly redundant at this point.

This implementation is approved as it allows for easy addition of more exports in the future. If no immediate plans exist to expand this object, you could simplify it to:

export default react;

But the current implementation is perfectly acceptable and future-proof.

apps/docs/content/components/input-otp/controlled.ts (1)

17-23: Clarify the purpose of this export structure.

The current export structure, using a template string for the component and exporting it within an object, is unconventional for typical React applications. This approach might be specific to your documentation or example system.

Could you please clarify the intended use of this file? If it's not required by your documentation system, consider refactoring to a more standard React component export:

import React from 'react';
import {InputOtp} from "@nextui-org/react";

export default function App() {
  const [value, setValue] = React.useState("");

  return (
    <div className="w-full flex flex-col gap-2 max-w-[240px]">
      <InputOtp
        value={value}
        onValueChange={setValue}
      />
      <p className="text-default-500 text-small">InputOtp value: {value}</p>
    </div>
  );
}

This would make the component more reusable and easier to understand for developers familiar with React conventions.

apps/docs/content/components/input-otp/sizes.ts (1)

5-14: Rendering logic looks good

The component's rendering logic is well-structured and follows React best practices. It correctly uses the key prop in mapped elements and demonstrates different sizes of the InputOtp component as intended.

The use of Tailwind CSS classes for styling is consistent and provides a responsive layout. Good job on this implementation!

apps/docs/content/components/input-otp/variants.ts (2)

1-23: Summary and request for additional context

The file apps/docs/content/components/input-otp/variants.ts appears to be part of a documentation or example system for the InputOtp component. It demonstrates different variants of the component in a structured manner. However, the unusual structure of defining the component as a string and exporting it in an object with a file path as the key suggests a specific use case that isn't immediately clear from the code alone.

To ensure this review is as helpful as possible:

  1. Could you provide more context on how this file is used in the project?
  2. Are there any specific guidelines or requirements for files in this directory that we should be aware of?
  3. Is this structure common across other similar files in the project?

This additional information would help in providing more targeted and relevant feedback.

To gather more context, let's check for similar files in the project:

#!/bin/bash
# Search for similar files in the project
fd -e ts -e tsx -p apps/docs/content/components

17-19: Please clarify the purpose of the export structure.

The export structure is unusual:

  1. An object react is created with a single property "/App.jsx".
  2. The value of this property is the App component defined as a string.

This structure suggests that the file might be used for documentation, a code playground, or some other special purpose. Could you please clarify the intended use of this file and why the component is exported in this manner? This information would help ensure that the implementation aligns with its intended purpose.

To better understand the usage of this file, let's check for similar patterns in other files:

apps/docs/content/components/input-otp/colors.ts (1)

5-13: Well-structured JSX with good use of responsive design

The component's structure is well-organized and follows React best practices. The use of Tailwind CSS classes for responsive design is effective, ensuring a good layout on both mobile and desktop views. The key prop is correctly used in the map function, which is crucial for React's reconciliation process.

apps/docs/content/components/input-otp/index.ts (1)

1-29: Overall, excellent organization and structure for the OTP component.

This file effectively aggregates all OTP-related modules into a single, easily importable object. The modular approach and clear naming conventions contribute to good maintainability and potential for code splitting. The minor suggestions provided earlier can further enhance the code quality, but the current implementation is already solid and follows good practices.

packages/components/input-otp/README.md (2)

11-17: Installation instructions look good

The installation instructions for both yarn and npm are clear and correct.


25-28: License information is correct

The license section correctly states that the project is licensed under the MIT license and provides a link to the full license text.

apps/docs/content/components/input-otp/allowedKeys.ts (2)

9-18: JSX structure looks good

The JSX structure is well-organized and follows React best practices. Good job on:

  • Using the map function to render multiple InputOtp components
  • Providing a unique key for each mapped element
  • Correctly passing the allowedKeys prop to the InputOtp component
  • Using Tailwind CSS classes for responsive styling

21-27: Clarify the purpose of this file structure

The current file structure, with the component wrapped in a string and exported as part of an object, is unconventional for typical React applications.

Could you please clarify the intended use of this file? Is it part of a documentation system or used for generating examples? Understanding the context would help in providing more accurate feedback.

To investigate further, let's check if there are similar files in the project:

This will help us understand if this is a common pattern in your project or an isolated case.

apps/docs/content/components/index.ts (1)

21-21: LGTM: New export for input-otp component added correctly.

The new export statement for the input-otp component has been added in a consistent manner with the existing export pattern. This change aligns well with the PR objectives to introduce the new Input OTP component to the NextUI library.

To ensure the referenced module exists, please run the following script:

If the script doesn't return any results, please ensure that the input-otp module has been created and is located in the correct directory.

✅ Verification successful

Verified: The input-otp module exists and the export statement is correctly added.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the input-otp module file

# Test: Check if the input-otp.ts or input-otp/index.ts file exists
fd -e ts -p "input-otp(\.ts|/index\.ts)$" apps/docs/content/components

Length of output: 120

packages/components/input-otp/src/input-otp-segment.tsx (4)

1-5: Imports look good and are properly organized.

The imports are relevant to the component's functionality and show good modularization practices. The use of the custom hook useInputOtpContext indicates proper separation of concerns.


22-24: Style definitions are clean and flexible.

The use of clsx for conditional class names is a good practice, allowing for easy composition of styles. Deriving styles from the context enables customization and maintains consistency across the component.


26-40: Display value logic is comprehensive and well-optimized.

The useMemo hook is correctly used to optimize the calculation of displayValue. The logic covers all possible states (password type, has value, is active) and returns appropriate JSX or null. This implementation ensures that the component renders correctly in all scenarios.


1-52: Overall, the InputOtpSegment component is well-implemented and aligns with the PR objectives.

This new component effectively addresses the feature request for an "input-otp" component in the NextUI library. It demonstrates good use of React patterns, including hooks, context, and performance optimizations. The component is flexible, allowing for customization through context and slots.

The implementation aligns well with the objectives outlined in the PR description and the linked issue (#2678). It provides a dedicated component for OTP input, which should enhance the user experience in authentication scenarios.

A few minor suggestions were made for improving documentation and accessibility, but these are small enhancements to an already solid implementation.

packages/core/react/src/index.ts (1)

46-46: LGTM: New Input OTP component export added successfully.

The addition of export * from "@nextui-org/input-otp"; is consistent with the existing export structure and aligns with the PR objectives to introduce the Input OTP component to the NextUI library.

Let's verify the existence and correctness of the @nextui-org/input-otp package:

✅ Verification successful

LGTM: New Input OTP component export verified successfully.

  • The @nextui-org/input-otp package exists and is correctly structured.
  • All essential files (src/index.ts, package.json, README.md) are present.
  • The package name is correctly set in package.json.
  • The input-otp.tsx component file is present.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and basic structure of the input-otp package

# Test 1: Check if the package directory exists
if [ -d "packages/components/input-otp" ]; then
    echo "input-otp package directory found."
else
    echo "Error: input-otp package directory not found."
    exit 1
fi

# Test 2: Check for essential files
essential_files=("src/index.ts" "package.json" "README.md")
for file in "${essential_files[@]}"; do
    if [ -f "packages/components/input-otp/$file" ]; then
        echo "$file found in input-otp package."
    else
        echo "Error: $file not found in input-otp package."
        exit 1
    fi
done

# Test 3: Verify package.json content
if grep -q '"name": "@nextui-org/input-otp"' packages/components/input-otp/package.json; then
    echo "Package name correctly set in package.json."
else
    echo "Error: Package name not correctly set in package.json."
    exit 1
fi

# Test 4: Check for component file
if [ -f "packages/components/input-otp/src/input-otp.tsx" ]; then
    echo "input-otp.tsx component file found."
else
    echo "Error: input-otp.tsx component file not found."
    exit 1
fi

echo "All checks passed. The input-otp package appears to be correctly structured and named."

Length of output: 1238

packages/components/input-otp/package.json (3)

27-35: Scripts section looks good!

The scripts section is well-organized and includes all necessary commands for development, building, and package management. The use of clean-package for prepack and postpack scripts is a good practice for ensuring clean npm packages.


1-61: Overall, the package.json is well-configured with minor improvements suggested.

The package.json file for the Input OTP component is well-structured and follows best practices for npm packages in a monorepo environment. It includes all necessary configurations for building, development, and publication.

Key strengths:

  1. Correct peer dependencies setup.
  2. Comprehensive script definitions.
  3. Proper repository and bug reporting information.
  4. Use of clean-package for maintaining a clean published package.

The suggested improvements are minor and focus on enhancing discoverability and usability:

  1. Adding a meaningful description.
  2. Expanding keywords for better npm registry search results.
  3. Adjusting the main entry point to the built JavaScript file.
  4. Adding a types field for better TypeScript integration.
  5. Clarifying the usage of react-hook-form as a dev dependency.

Once these small adjustments are made, this package.json will be in excellent shape for the new Input OTP component.


36-59: Dependencies look good, but consider publishing setup and clarify react-hook-form usage.

The dependencies are well-organized and seem appropriate for an Input OTP component. A few points to consider:

  1. The use of "workspace:*" for internal dependencies is good for monorepo development. However, ensure that these are correctly resolved when publishing the package to npm.

  2. It's good to see React and React DOM listed in both peerDependencies and devDependencies. This is the correct setup for a React component library.

  3. The inclusion of react-hook-form as a devDependency is interesting. Could you clarify its purpose? If it's used for testing or examples, consider moving it to a separate examples or test folder to keep the main package lightweight.

To ensure all dependencies are correctly listed and up-to-date, you can run the following command:

This will help identify any packages that might have updates available.

packages/core/react/package.json (1)

65-65: LGTM: New dependency added correctly.

The addition of "@nextui-org/input-otp" as a workspace dependency is consistent with the PR objectives and follows the existing pattern for internal dependencies.

Let's verify that this new dependency is consistent with others:

✅ Verification successful

Verified: "@nextui-org/input-otp" is correctly set as a workspace dependency in package.json.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all @nextui-org dependencies use "workspace:*"

# Test: Check if all @nextui-org dependencies use "workspace:*"
grep -E '"@nextui-org/[^"]+": "workspace:\*",' packages/core/react/package.json

# Test: Ensure the new dependency is present
grep '"@nextui-org/input-otp": "workspace:*",' packages/core/react/package.json

Length of output: 2002


Script:

#!/bin/bash
# Description: Verify that "@nextui-org/input-otp" is present and set to "workspace:*" in package.json

# Test: Check if "@nextui-org/input-otp" exists and is set to "workspace:*"
jq '.dependencies["@nextui-org/input-otp"] == "workspace:*"' packages/core/react/package.json

Length of output: 100

apps/docs/package.json (1)

29-29: LGTM: New dependency added for Input OTP component.

The addition of "@nextui-org/input-otp": "workspace:*" is consistent with the PR objectives to introduce an Input OTP component to the NextUI library. The use of workspace:* suggests this is a local package, which is appropriate for a new component being developed within the project.

To ensure the new component is properly integrated, let's verify its usage in the documentation:

packages/components/input-otp/stories/input-otp.stories.tsx (1)

1-41: LGTM! Component configuration is comprehensive.

The imports and component configuration are well-structured and cover all necessary aspects for the InputOtp component's Storybook stories. The validationBehavior prop has been correctly added as requested in a previous review comment.

apps/docs/public/sitemap-0.xml (3)

1-76: XML structure and consistency look good.

The sitemap follows the correct XML structure and maintains consistency in changefreq and priority values across all URLs. The lastmod timestamps are also consistent, with only a negligible 1-millisecond difference in some entries.


9-10: New component and API reference URLs added successfully.

The sitemap has been updated with several new URLs, including:

  • The input-otp component URL (line 33), which is the main focus of this PR.
  • New date-related components: calendar, date-input, date-picker, date-range-picker, and time-input.
  • API references for cli-api and nextui-provider.
  • Blog post URLs for v2.3.0 and v2.4.0.

These additions align well with the PR objectives and the linked issue.

Also applies to: 12-13, 20-20, 27-29, 33-33, 56-56


1-76: Verify completeness of new component documentation.

The sitemap has been successfully updated with the input-otp component URL and other new entries, aligning well with the PR objectives. To ensure completeness:

  1. Please verify that all documentation pages related to the newly added components (calendar, date-input, date-picker, date-range-picker, time-input) are included in the sitemap.
  2. Check if there are any additional pages or sections (e.g., examples, API references) for these new components that should be added to the sitemap.
apps/docs/content/docs/components/input-otp.mdx (3)

1-11: LGTM: Header and introduction are well-structured.

The metadata, import statement, and brief introduction provide a clear and concise overview of the InputOtp component.


15-27: LGTM: Comprehensive installation instructions provided.

The installation section covers all major package managers, ensuring users can easily install the component regardless of their preferred tool.


151-157: LGTM: Concise and informative accessibility section.

The accessibility section effectively highlights the use of native elements and ARIA attributes, demonstrating a commitment to creating accessible components.

apps/docs/config/routes.json (1)

261-267: LGTM: New "Input OTP" component entry added correctly

The new entry for the "Input OTP" component has been added correctly to the routes configuration. It follows the existing structure and conventions:

  1. Positioned alphabetically within the "components" section
  2. Includes all necessary properties (key, title, keywords, path, newPost)
  3. Uses consistent naming conventions for the path
  4. Relevant keywords are provided
  5. Marked as a new post with "newPost": true

This addition aligns well with the PR objectives to introduce the "Input OTP" component to the NextUI library.

packages/components/input-otp/src/use-input-otp.ts (2)

128-129: Use props instead of originalProps after destructuring.

You should use the local props variable instead of originalProps to maintain consistency and clarity.


80-83: Exporting ValueTypes may be unnecessary as slots is already defined below.

Consider removing the ValueTypes export if it is not used.

apps/docs/content/components/input-otp/usage.ts Outdated Show resolved Hide resolved
apps/docs/content/components/input-otp/errorMessage.ts Outdated Show resolved Hide resolved
apps/docs/content/components/input-otp/sizes.ts Outdated Show resolved Hide resolved
apps/docs/content/components/input-otp/sizes.ts Outdated Show resolved Hide resolved
packages/components/input-otp/__tests__/input-otp.test.tsx Outdated Show resolved Hide resolved
packages/components/input-otp/__tests__/input-otp.test.tsx Outdated Show resolved Hide resolved
packages/core/theme/src/components/input-otp.ts Outdated Show resolved Hide resolved
packages/components/input-otp/src/use-input-otp.ts Outdated Show resolved Hide resolved
packages/components/input-otp/src/use-input-otp.ts 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.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
packages/components/input-otp/README.md (1)

17-21: Improve grammar in the contribution section

The contribution section is concise and provides a link to the contributing guidelines. However, there's a minor grammatical issue that can be improved:

- Yes please! See the
+ Yes, please! See the

This change adds a comma before "please," which is grammatically correct and improves readability.

🧰 Tools
🪛 LanguageTool

[typographical] ~19-~19: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bc5286c and 0166f8f.

📒 Files selected for processing (7)
  • apps/docs/content/components/input-otp/allowedKeys.ts (1 hunks)
  • apps/docs/content/components/input-otp/usage.ts (1 hunks)
  • packages/components/input-otp/README.md (1 hunks)
  • packages/components/input-otp/tests/input-otp.test.tsx (1 hunks)
  • packages/components/input-otp/src/input-otp.tsx (1 hunks)
  • packages/components/input-otp/src/use-input-otp.ts (1 hunks)
  • packages/core/theme/src/components/input-otp.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • apps/docs/content/components/input-otp/allowedKeys.ts
  • apps/docs/content/components/input-otp/usage.ts
  • packages/components/input-otp/tests/input-otp.test.tsx
  • packages/components/input-otp/src/input-otp.tsx
  • packages/components/input-otp/src/use-input-otp.ts
  • packages/core/theme/src/components/input-otp.ts
🧰 Additional context used
🪛 LanguageTool
packages/components/input-otp/README.md

[typographical] ~19-~19: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

🔇 Additional comments (3)
packages/components/input-otp/README.md (3)

9-15: Installation instructions look good

The installation instructions are clear, concise, and provide options for both Yarn and npm package managers. This section is well-written and doesn't require any changes.


23-26: License information is appropriate

The license section clearly states that the project is under the MIT license and provides a link to the full license text. This information is sufficient and doesn't require any changes.


1-26: Overall, the README provides essential information but could be more comprehensive

The README file for the InputOTP component covers the basic requirements of component documentation. It includes an introduction, installation instructions, contribution guidelines, and license information. However, there are opportunities to enhance its usefulness:

  1. The introduction could be expanded to include key features, a basic usage example, and a brief overview of the component's props.
  2. A minor grammatical improvement in the contribution section would enhance readability.

With these suggested improvements, the README will provide a more comprehensive and user-friendly introduction to the InputOTP component, aligning well with the PR objectives of introducing a new public component to the NextUI library.

🧰 Tools
🪛 LanguageTool

[typographical] ~19-~19: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

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: 22

🧹 Outside diff range and nitpick comments (41)
.changeset/spotty-flies-jump.md (1)

6-6: Consider enhancing the change description.

The current description is concise but could be more informative. Consider expanding it to provide more context about the new component and its purpose.

Here's a suggested improvement:

- Adding new input-otp component.
+ Adding a new input-otp component for handling one-time password entries.

This change addresses the grammar issue and provides more context about the component's functionality.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~6-~6: You might be missing the article “a” here.
Context: ... "@nextui-org/theme": minor --- Adding new input-otp component.

(AI_EN_LECTOR_MISSING_DETERMINER_A)

packages/components/input-otp/src/index.ts (2)

3-4: LGTM: Type export is correct.

The export of InputOtpProps type is done correctly, allowing for proper type checking when using the component.

For consistency with the other sections, consider adding a newline after the type export:

 // export types
 export type {InputOtpProps} from "./input-otp";
+

1-10: Overall structure is excellent, with a minor suggestion for improvement.

The file structure is clean and follows common patterns for React component exports. It provides a clear entry point for the InputOtp feature, exporting the component, its props type, and the associated hook.

Consider grouping the imports at the top of the file for better readability:

 import InputOtp from "./input-otp";
+import {InputOtpProps} from "./input-otp";
+import {useInputOtp} from "./use-input-otp";

 // export types
-export type {InputOtpProps} from "./input-otp";
+export type {InputOtpProps};

 // export hooks
-export {useInputOtp} from "./use-input-otp";
+export {useInputOtp};

 // export component
 export {InputOtp};

This change would centralize all imports and make the file structure even cleaner.

apps/docs/content/components/input-otp/password.ts (2)

1-9: LGTM! Consider enhancing the flex layout for better responsiveness.

The App component effectively demonstrates the usage of InputOtp with type="password". The flex layout provides a good base for responsive design.

Consider adding items-center to the flex container for vertical alignment:

-    <div className="flex w-full flex-wrap md:flex-nowrap gap-4">
+    <div className="flex w-full flex-wrap md:flex-nowrap gap-4 items-center">

This will ensure that the InputOtp is vertically centered within its container, improving the visual presentation.


11-17: LGTM! Consider adding a comment for clarity.

The export mechanism is well-structured for use in a documentation or example system. The use of the spread operator ensures all properties of the react object are included in the default export.

Consider adding a comment to explain the purpose of this export structure:

+// Export for documentation example system
 export default {
   ...react,
 };

This will help other developers understand the intent behind this export mechanism.

apps/docs/content/components/input-otp/required.ts (2)

1-9: LGTM! Consider adding an aria-label for accessibility.

The App component correctly demonstrates the usage of the new InputOtp component with the required prop. The flexbox styling allows for responsive layout.

Consider adding an aria-label to the InputOtp component for better accessibility:

-      <InputOtp length={4} isRequired />
+      <InputOtp length={4} isRequired aria-label="Enter OTP" />

1-17: Overall, the file is well-structured and serves its purpose effectively.

The file successfully demonstrates the usage of the new InputOtp component in a required field scenario, aligning with the PR objectives. It's well-organized for documentation purposes.

For improved code organization, consider extracting the App template string into a separate constant at the top of the file:

const APP_TEMPLATE = `...`;

const App = APP_TEMPLATE;

const react = {
  "/App.jsx": App,
};

export default {
  ...react,
};

This separation can make the file easier to read and maintain, especially if more complex examples are added in the future.

apps/docs/content/components/input-otp/disabled.ts (1)

1-9: LGTM! Consider adding a label for clarity.

The App component effectively demonstrates the usage of a disabled InputOtp. The implementation is correct and showcases the component's properties well.

Consider adding a label to the InputOtp component to improve the example's clarity:

 <div className="flex w-full flex-wrap md:flex-nowrap gap-4">
+  <label>
+    Disabled OTP Input
   <InputOtp length={4} isDisabled defaultValue="123" />
+  </label>
 </div>
apps/docs/content/components/input-otp/readonly.ts (2)

1-9: LGTM! Consider adding a comment for clarity.

The App component is well-defined and correctly uses the InputOtp component with appropriate props. The responsive layout is a good practice.

Consider adding a comment at the beginning of the App definition to explain its purpose as an example or documentation code:

+// Example usage of InputOtp component in read-only mode
 const App = `import {InputOtp} from "@nextui-org/react";
 
 export default function App() {
   // ... rest of the code
 }`;

11-17: LGTM! Consider using consistent naming for better clarity.

The react object and default export are well-structured for a documentation system. The use of the spread operator in the default export allows for easy extension.

For consistency with the file name and the component's purpose, consider renaming the object key:

 const react = {
-  "/App.jsx": App,
+  "/ReadOnlyExample.jsx": App,
 };

This change would better reflect the specific example being showcased.

packages/components/input-otp/src/input-otp-context.ts (1)

1-9: Well-structured context implementation for OTP input.

The implementation of the InputOtpContext is clean, well-organized, and follows best practices. Good job on providing a named context and including an informative error message.

Consider slightly rewording the error message for clarity:

-    "useInputOtpContext: `context` is undefined. Seems like you forgot to wrap all input-otp components within `<InputOtp />`",
+    "useInputOtpContext: `context` is undefined. Ensure all input-otp components are wrapped within an `<InputOtp />` component.",
apps/docs/content/components/input-otp/errorMessage.ts (2)

1-9: Use template literals for better code readability

The current implementation defines the component as a plain string. As suggested in a previous review, using template literals (backticks) instead of single quotes would improve readability and enable better syntax highlighting in most editors.

Apply this change to use template literals:

-const App = `import {InputOtp} from "@nextui-org/react";
+const App = `import {InputOtp} from "@nextui-org/react";

 export default function App() {
   return (
     <div className="flex w-full flex-wrap md:flex-nowrap gap-4">
       <InputOtp errorMessage="This is custom error message for the OTP component." isInvalid />
     </div>
   );
 }`;

This change will improve code readability and maintainability while preserving the multi-line formatting.

The overall structure of the component looks good. It correctly demonstrates the usage of InputOtp with an error message and invalid state.


11-13: Consider using a more descriptive name for the object

The current name 'react' for the object might be confusing as it's not directly related to the React library. A more descriptive name would better convey its purpose.

Consider renaming the object to something more specific, such as 'componentExamples' or 'appCodeExamples':

-const react = {
+const componentExamples = {
   "/App.jsx": App,
 };

This change would make the code more self-explanatory and easier to understand at a glance.

apps/docs/content/components/input-otp/controlled.ts (1)

1-15: LGTM! Consider adding input validation.

The App component demonstrates correct usage of the InputOtp component with controlled input behavior. It properly manages state using the useState hook and provides visual feedback of the current input value.

Consider adding input validation to enhance user experience. For example, you could add a check for the OTP length and display an error message if it's incomplete:

 export default function App() {
   const [value, setValue] = React.useState("");
+  const [error, setError] = React.useState("");
+
+  const handleValueChange = (newValue) => {
+    setValue(newValue);
+    setError(newValue.length < 6 ? "Please enter a 6-digit OTP" : "");
+  };

   return (
     <div className="w-full flex flex-col gap-2 max-w-[240px]">
       <InputOtp
         value={value}
-        onValueChange={setValue}
+        onValueChange={handleValueChange}
+        errorMessage={error}
       />
       <p className="text-default-500 text-small">InputOtp value: {value}</p>
     </div>
   );
 }

This addition would improve the component by providing immediate feedback to the user about the validity of their input.

apps/docs/content/components/input-otp/sizes.ts (1)

1-23: Summary of review findings

This file requires significant refactoring to address several issues:

  1. The React component is incorrectly defined as a template string.
  2. The sizes array should be defined as a constant or enum outside the component.
  3. The purpose of the react object needs clarification.
  4. The export logic is unnecessarily complex.

These issues were largely identified in previous reviews and remain unaddressed. Please refer to the individual comments for detailed explanations and suggested improvements.

Consider restructuring this file to follow React best practices and improve its maintainability. If you need assistance with any of these refactoring tasks, please let me know.

apps/docs/content/components/input-otp/radius.ts (1)

21-23: Consider simplifying the default export

The current export spreads the properties of the 'react' object into a new object. While this allows for easy expansion in the future, it's currently equivalent to directly exporting the 'react' object.

If no additional properties are planned to be added to this export, you could simplify it to:

export default react;

However, if you anticipate adding more properties in the future, the current structure is fine. In that case, consider adding a comment explaining the purpose of this export structure for future developers.

packages/components/input-otp/README.md (1)

17-21: Minor grammatical improvement in the contribution section

The content of the contribution section is appropriate. However, there's a small grammatical improvement that can be made:

- Yes please! See the
+ Yes, please! See the

This change adds a comma before "please," which is typically used in this context.

🧰 Tools
🪛 LanguageTool

[typographical] ~19-~19: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

apps/docs/content/components/input-otp/usage.ts (1)

28-30: LGTM! Consider adding a comment for clarity.

The react object structure looks good and seems to be used for organizing components in a documentation system. To improve clarity, consider adding a brief comment explaining its purpose:

// Object mapping component names to their string representations for documentation
const react = {
  "/App.jsx": App,
};

This comment will help other developers understand the purpose of this object more quickly.

apps/docs/content/components/input-otp/allowedKeys.ts (2)

21-23: Add clarifying comment for the react object

The purpose of the react object with the "/App.jsx" key is not immediately clear. If this structure is used for documentation or code examples, consider adding a comment to explain its usage:

// Object containing code examples for documentation rendering
const react = {
  "/App.jsx": App,
};

This will help other developers understand the intention behind this structure more quickly.


25-27: Consider simplifying the export or add explanatory comment

The current export spreads the react object, which is unnecessary if there's only one property. If no expansion is planned, you could simplify it to:

export default react;

However, if this structure is intentional for future expansion, consider adding a comment to explain:

// Exporting as a spread object to allow for easy addition of more examples in the future
export default {
  ...react,
};

This will clarify the intention behind the current structure.

packages/core/react/src/index.ts (1)

46-46: LGTM! Consider alphabetical ordering.

The addition of the input-otp export is correct and follows the established pattern in the file. This change successfully makes the new Input OTP component available for import, which aligns with the PR objectives.

For better maintainability, consider sorting the exports alphabetically. This would place the new input-otp export between input and kbd:

 export * from "@nextui-org/input";
+export * from "@nextui-org/input-otp";
 export * from "@nextui-org/kbd";
packages/components/input-otp/package.json (2)

1-26: Enhance package metadata for improved discoverability and information.

Consider the following improvements:

  1. Add a meaningful description to the "description" field.
  2. Expand the "keywords" array with relevant terms like "otp", "one-time-password", "authentication", "input", "react", "nextui".
  3. Verify if the version "2.0.0" is correct for a new package, or if it should start at "1.0.0".

These changes will help users better understand the package's purpose and improve its discoverability on npm.


36-41: Consider using more specific version ranges for peer dependencies.

While using ">=" for version specifications provides flexibility, it may lead to compatibility issues if major versions of the dependencies change. Consider using more specific version ranges:

"peerDependencies": {
  "react": "^18.0.0",
  "react-dom": "^18.0.0",
  "@nextui-org/theme": "^2.0.0",
  "@nextui-org/system": "^2.0.0"
}

This approach ensures compatibility with the current major versions while allowing for minor and patch updates.

packages/core/react/package.json (1)

65-65: LGTM! Consider updating the package version.

The addition of the "@nextui-org/input-otp" dependency is correct and aligns with the PR objectives. The "workspace:*" version is appropriate for a monorepo setup.

Consider updating the package version in the "version" field at the top of the file to reflect this new feature addition, following semantic versioning principles.

apps/docs/package.json (1)

Version bump to 2.0.0 may not be necessary

No breaking changes were identified in recent commits related to the input-otp component. Consider using a minor version bump (e.g., 1.1.0) instead, unless there are other breaking changes not reflected in the commit messages.

🔗 Analysis chain

Line range hint 2-2: Version bump to 2.0.0 - Ensure proper semantic versioning

The package version has been updated to 2.0.0, which indicates a major release. This aligns with the addition of the new input-otp component. However, please ensure that this version bump adheres to semantic versioning principles:

  1. If there are breaking changes, this major version bump is appropriate.
  2. If there are no breaking changes but only new features, consider using a minor version bump (e.g., 1.1.0) instead.

To confirm if there are breaking changes, you can run:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for breaking changes in commit messages or PR description
git log --oneline -n 50 | grep -i "breaking change"

Length of output: 299


Script:

#!/bin/bash
# Search for commit messages related to 'input-otp' in the last 50 commits
git log --oneline -n 50 --grep="input-otp"

# Additionally, search for any commit messages indicating potential breaking changes
git log --oneline -n 50 --grep="breaking change"

Length of output: 1034

packages/components/input-otp/stories/input-otp.stories.tsx (5)

1-41: LGTM! Consider adding JSDoc comments for better documentation.

The imports and default export are well-structured and follow Storybook conventions. The argTypes definition provides a good range of controls for the component props.

Consider adding JSDoc comments to the default export to provide more context about the InputOtp component and its usage in Storybook. This can help other developers understand the purpose and capabilities of the component more quickly.


47-129: Great job on covering various use cases! Consider enhancing error handling.

The template functions provide excellent coverage of different scenarios for the InputOtp component, including basic usage, form integration with react-hook-form, and controlled component usage.

In the RequiredTemplate and WithReactHookFormTemplate, consider adding more comprehensive error handling. For example, you could include validation for the OTP length or format, and display appropriate error messages. This would demonstrate the component's flexibility in handling different types of validation scenarios.


131-192: Excellent coverage of component states! Consider adding an accessibility-focused story.

The exported stories provide a comprehensive showcase of the InputOtp component's various configurations and states. The inclusion of scenarios like disabled, read-only, and password input demonstrates the component's versatility.

To further enhance the component's testability, consider adding a story specifically focused on accessibility. This could include setting ARIA labels, testing keyboard navigation, and ensuring the component works well with screen readers. For example:

export const Accessible = {
  render: Template,
  args: {
    ...defaultProps,
    length: 4,
    aria-label: "Enter your 4-digit OTP",
    // Add other accessibility-related props as needed
  },
};

This addition would help ensure that the component meets accessibility standards and works well for all users.


194-232: Great job on advanced scenarios! Consider standardizing naming conventions.

The advanced story exports effectively demonstrate complex scenarios such as custom error handling, invalid states, and integration with react-hook-form. These examples provide valuable insights into the component's flexibility and real-world usage.

For consistency, consider standardizing the naming convention for your story exports. For instance, isInvalid uses camelCase, while other exports use PascalCase. Changing isInvalid to IsInvalid would maintain consistency:

export const IsInvalid = {
  // ... existing code
};

This small change would improve the overall code consistency and make it easier for other developers to navigate the stories.


234-247: Excellent demonstration of customization! Consider expanding on styling options.

The CustomWithClassNames story effectively showcases the InputOtp component's ability to accept custom styles through the classNames prop. The use of gradient backgrounds and custom caret color demonstrates the component's flexibility in terms of visual customization.

To further illustrate the component's customization capabilities, consider expanding this story or adding another one that demonstrates a wider range of styling options. For example:

export const FullyCustomized = {
  render: Template,
  args: {
    ...defaultProps,
    length: 4,
    classNames: {
      base: "gap-4",
      segment: "bg-gradient-to-tr from-pink-500 to-yellow-500 border-2 border-purple-600",
      caret: "bg-red-700",
      input: "text-2xl font-bold text-white",
      label: "text-purple-700 font-semibold",
      description: "italic text-sm text-gray-600",
    },
    radius: "lg",
    description: "Fully customized OTP component",
    label: "Custom OTP Input",
  },
};

This enhancement would provide a more comprehensive example of the various elements that can be styled, giving developers a better understanding of the component's customization potential.

apps/docs/content/docs/components/input-otp.mdx (6)

15-37: LGTM: Comprehensive installation instructions

The installation section covers multiple package managers and provides clear import instructions. This is very helpful for users with different project setups.

Consider adding a brief note about any peer dependencies that might be required for the InputOtp component, if applicable. This could help users avoid potential setup issues.


39-110: LGTM: Comprehensive prop documentation with examples

The usage section effectively covers a wide range of props with clear explanations and code demos. This will greatly assist developers in understanding and implementing the InputOtp component.

Consider adding a brief example or note about combining multiple props (e.g., size with color, or variant with radius) to showcase how different props interact. This could provide users with a more complete understanding of the component's flexibility.


115-127: LGTM: Clear explanation of component slots

The slots section provides a good breakdown of the InputOtp component's structure, which is valuable for developers who need to customize or style specific parts of the component.

Consider adding a simple diagram or visual representation of how these slots relate to each other within the component. This could enhance understanding of the component's structure, especially for visual learners.

🧰 Tools
🪛 LanguageTool

[grammar] ~123-~123: Is an article like ‘a’ or ‘an’ missing?
Context: ...esents the text styling when input-type is password. - helperWrapper: Wraps t...

(BE_NN)


151-157: Good start on accessibility, but could be more comprehensive

The accessibility section provides a good foundation by mentioning the use of native elements and ARIA attributes. This is crucial information for ensuring the component is usable by all.

Consider expanding this section to include:

  1. Details on keyboard navigation within the OTP input fields.
  2. Specific behavior with screen readers, including any announcements made.
  3. Color contrast considerations, especially for different component states.
  4. Any additional ARIA attributes or roles used that are specific to this component.

These additions would provide a more comprehensive guide for developers aiming to create fully accessible implementations.


159-191: LGTM: Comprehensive API documentation with minor improvements needed

The API section provides a detailed and well-structured overview of the InputOtp component's props and events. The table format is clear and easy to read.

Consider the following improvements:

  1. For the isReadOnly prop (line 177), add the default value (presumably false).
  2. For the validationState prop (line 181), consider removing it entirely if it's deprecated, or clearly mark it as deprecated in the table.
  3. For the classNames prop (line 183), consider breaking down the long type definition into multiple lines for better readability.
  4. In the events table, consider adding a brief example of how to use each event, especially for onValueChange and onFill.

These changes would enhance the clarity and completeness of the API documentation.

🧰 Tools
🪛 LanguageTool

[style] ~191-~191: This phrase is redundant. Consider writing “filled”.
Context: ...t is called when the element's value is completely filled. ...

(COMPLETELY_ANNIHILATE)


145-145: Minor style improvements

Consider the following style improvements:

  1. On line 145, change "completely filled" to simply "filled".
  2. On line 191, change "completely filled" to simply "filled".

These changes would make the text more concise without losing meaning.

Also applies to: 191-191

🧰 Tools
🪛 LanguageTool

[style] ~145-~145: This phrase is redundant. Consider writing “filled”.
Context: ...data-filled*: When the input-otp is completely filled. - data-disabled: When the input ...

(COMPLETELY_ANNIHILATE)

packages/components/input-otp/src/input-otp.tsx (1)

33-33: Use template literals for cleaner key generation.

For improved readability, consider using template literals when generating keys.

Apply this diff:

- <InputOtpSegment key={"segment-" + idx} accessorIndex={idx} />
+ <InputOtpSegment key={`segment-${idx}`} accessorIndex={idx} />
packages/components/input-otp/__tests__/input-otp.test.tsx (2)

138-138: Fix Typo in Comment

There's a typo in the comment on line 138: "segement[2]" should be "segment[2]".


178-178: Improve Terminology in Comment

In the comment on line 178, consider replacing "unallowed letter" with "disallowed character" or "invalid input" for clarity and correctness.

packages/core/theme/src/components/input-otp.ts (2)

43-43: Remove unnecessary empty string in helperWrapper classes

The helperWrapper slot contains an unnecessary empty string in the class list. Removing it will clean up the code and prevent potential issues.

Apply this diff to fix the issue:

-        helperWrapper: ["text-xs", "mt-0.5", "font-extralight", ""],
+        helperWrapper: ["text-xs", "mt-0.5", "font-extralight"],

423-423: Typo in comment: 'anf' should be 'and'

There's a typo in the comment at line 423. Correcting it improves readability.

Apply this diff to fix the typo:

-        // isInvalid anf underlined
+        // isInvalid and underlined
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cab6a94 and ec98d8f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (35)
  • .changeset/spotty-flies-jump.md (1 hunks)
  • apps/docs/config/routes.json (1 hunks)
  • apps/docs/content/components/index.ts (1 hunks)
  • apps/docs/content/components/input-otp/allowedKeys.ts (1 hunks)
  • apps/docs/content/components/input-otp/colors.ts (1 hunks)
  • apps/docs/content/components/input-otp/controlled.ts (1 hunks)
  • apps/docs/content/components/input-otp/description.ts (1 hunks)
  • apps/docs/content/components/input-otp/disabled.ts (1 hunks)
  • apps/docs/content/components/input-otp/errorMessage.ts (1 hunks)
  • apps/docs/content/components/input-otp/index.ts (1 hunks)
  • apps/docs/content/components/input-otp/password.ts (1 hunks)
  • apps/docs/content/components/input-otp/radius.ts (1 hunks)
  • apps/docs/content/components/input-otp/readonly.ts (1 hunks)
  • apps/docs/content/components/input-otp/required.ts (1 hunks)
  • apps/docs/content/components/input-otp/sizes.ts (1 hunks)
  • apps/docs/content/components/input-otp/usage.ts (1 hunks)
  • apps/docs/content/components/input-otp/variants.ts (1 hunks)
  • apps/docs/content/docs/components/input-otp.mdx (1 hunks)
  • apps/docs/package.json (1 hunks)
  • apps/docs/public/sitemap-0.xml (1 hunks)
  • packages/components/input-otp/README.md (1 hunks)
  • packages/components/input-otp/tests/input-otp.test.tsx (1 hunks)
  • packages/components/input-otp/package.json (1 hunks)
  • packages/components/input-otp/src/index.ts (1 hunks)
  • packages/components/input-otp/src/input-otp-context.ts (1 hunks)
  • packages/components/input-otp/src/input-otp-segment.tsx (1 hunks)
  • packages/components/input-otp/src/input-otp.tsx (1 hunks)
  • packages/components/input-otp/src/use-input-otp.ts (1 hunks)
  • packages/components/input-otp/stories/input-otp.stories.tsx (1 hunks)
  • packages/components/input-otp/tsconfig.json (1 hunks)
  • packages/components/input-otp/tsup.config.ts (1 hunks)
  • packages/core/react/package.json (1 hunks)
  • packages/core/react/src/index.ts (1 hunks)
  • packages/core/theme/src/components/index.ts (1 hunks)
  • packages/core/theme/src/components/input-otp.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/components/input-otp/tsconfig.json
  • packages/components/input-otp/tsup.config.ts
🧰 Additional context used
📓 Learnings (1)
packages/components/input-otp/__tests__/input-otp.test.tsx (2)
Learnt from: macci001
PR: nextui-org/nextui#3748
File: packages/components/input-otp/__tests__/input-otp.test.tsx:237-237
Timestamp: 2024-09-27T13:04:57.391Z
Learning: In test files, mock functions are typically declared as `let onSubmit: () => void` rather than specifying them as `jest.Mock` to follow the existing pattern in other tests.
Learnt from: macci001
PR: nextui-org/nextui#3748
File: packages/components/input-otp/__tests__/input-otp.test.tsx:57-59
Timestamp: 2024-09-27T13:04:45.348Z
Learning: In our tests, we use `act()` wrappers around `userEvent` calls to follow existing patterns.
🪛 LanguageTool
.changeset/spotty-flies-jump.md

[uncategorized] ~6-~6: You might be missing the article “a” here.
Context: ... "@nextui-org/theme": minor --- Adding new input-otp component.

(AI_EN_LECTOR_MISSING_DETERMINER_A)

apps/docs/content/docs/components/input-otp.mdx

[grammar] ~123-~123: Is an article like ‘a’ or ‘an’ missing?
Context: ...esents the text styling when input-type is password. - helperWrapper: Wraps t...

(BE_NN)


[style] ~145-~145: This phrase is redundant. Consider writing “filled”.
Context: ...data-filled*: When the input-otp is completely filled. - data-disabled: When the input ...

(COMPLETELY_ANNIHILATE)


[style] ~191-~191: This phrase is redundant. Consider writing “filled”.
Context: ...t is called when the element's value is completely filled. ...

(COMPLETELY_ANNIHILATE)

packages/components/input-otp/README.md

[typographical] ~19-~19: Usually, a comma is necessary before ‘Yes’ at the end of a sentence. Did you mean “, please”?
Context: ...-org/input-otp ``` ## Contribution Yes please! See the [contributing guidelines](http...

(COMMA_BEFORE_PLEASE)

🔇 Additional comments (43)
.changeset/spotty-flies-jump.md (1)

1-4: LGTM: Version bumps are correct.

The minor version bumps for "@nextui-org/input-otp" and "@nextui-org/theme" are appropriate for introducing a new component without breaking changes.

packages/components/input-otp/src/index.ts (2)

1-1: LGTM: Component import looks good.

The import statement for the InputOtp component is correct and follows standard practices.


6-10: LGTM: Hook and component exports are correct.

The exports for the useInputOtp hook and the InputOtp component are done correctly. This structure allows for flexible usage of both the component and its associated hook.

apps/docs/content/components/input-otp/password.ts (1)

1-17: Overall, excellent implementation of the InputOtp password example.

This file effectively demonstrates the usage of the InputOtp component with type="password". The structure is well-suited for a documentation or example system, providing a clear and concise representation of the component's functionality.

The minor suggestions provided earlier will further enhance the clarity and presentation of this example. Great job on implementing this new feature!

apps/docs/content/components/input-otp/required.ts (2)

11-13: LGTM! Object structure is appropriate for documentation.

The react object correctly maps the App component to a file-like key, which is suitable for documentation or example purposes.


15-17: LGTM! Export structure allows for future expansion.

The default export using the spread operator is appropriate. It allows for easy addition of more examples in the future if needed.

apps/docs/content/components/input-otp/disabled.ts (2)

11-13: LGTM! Object structure is appropriate for documentation purposes.

The react object correctly maps the App component to a file path-like key. This structure is suitable for documentation systems that render examples.


15-17: LGTM! Export structure is flexible and extensible.

The default export using the spread operator on the react object is a good practice. It allows for easy addition of more examples in the future without modifying the export statement.

packages/components/input-otp/src/input-otp-context.ts (3)

5-9: Excellent context creation and export implementation.

The creation and export of the InputOtpContext follow React best practices:

  • Using a generic type UseInputOtpReturn ensures type safety.
  • Directly exporting the provider and hook from createContext is efficient.
  • Naming conventions are correctly followed (PascalCase for InputOtpProvider, camelCase for useInputOtpContext).

1-9: Overall excellent implementation of the InputOtp context.

This file demonstrates a high-quality implementation of a React context for managing OTP input:

  • Concise and focused on a single responsibility.
  • Follows TypeScript and React best practices.
  • Provides clear and typed exports for use in other components.
  • Includes a helpful error message for proper usage.

Great job on creating a robust foundation for the OTP input functionality!


1-3: Imports are correctly utilized and follow project conventions.

The use of createContext from "@nextui-org/react-utils" and the local import of UseInputOtpReturn demonstrate good modularization and adherence to project standards.

Let's verify the local import path:

apps/docs/content/components/input-otp/errorMessage.ts (1)

15-17: Export structure looks good

The current export structure is flexible and allows for easy expansion if more examples are added in the future.

The export looks good as is. However, remember to update this export if you rename the 'react' object as suggested in the previous comment:

 export default {
-  ...react,
+  ...componentExamples,
 };

This will ensure consistency throughout the file.

apps/docs/content/components/input-otp/controlled.ts (1)

17-23: Please clarify the purpose of the export structure.

The export configuration uses an unusual structure with a file path as a key. While this might be intentional for a specific system (e.g., documentation or example rendering), it's not immediately clear why this structure is used.

Could you provide more context on why this export structure is necessary? If it's for a specific documentation or example system, consider adding a comment explaining its purpose:

+// Export structure used by the documentation system to render live examples
 const react = {
   "/App.jsx": App,
 };

 export default {
   ...react,
 };
apps/docs/content/components/input-otp/sizes.ts (4)

1-15: Convert template string to a proper React component

The component is still defined as a template string, which can lead to issues with syntax highlighting, code analysis, and potentially runtime errors. This issue was previously mentioned in a past review comment and remains unaddressed.

Please refer to the previous comment for the suggested refactoring to use standard React syntax.


4-4: Consider defining sizes as a constant or enum

The sizes array is still defined within the component. For better maintainability and reusability, it should be defined as a constant or enum outside the component, as suggested in a previous review comment.

Please refer to the previous comment for an example of how to refactor this for improved maintainability and type safety.


21-23: Simplify the export logic

The current export logic remains unnecessarily complex for a single component. This issue was previously mentioned in a past review comment and has not been addressed.

Please refer to the previous comment for suggestions on simplifying the export to directly export the App component. If there's a specific reason for the current structure, consider adding a comment explaining the rationale.


17-19: Clarify the purpose of the react object

The react object seems to map the App component to a file path. However, the purpose of this mapping is not clear from the current context.

Could you please clarify the intended use of this react object? Is it part of a larger system for handling multiple components? If so, consider adding a comment explaining its role in the overall architecture.

apps/docs/content/components/input-otp/radius.ts (1)

17-19: Clarify the purpose of the 'react' object

The purpose and usage of the 'react' object are not immediately clear from the context provided.

Could you please clarify:

  1. What is the intended use of this object?
  2. Is it part of a larger system for managing code examples or documentation?
  3. Why is the key "/App.jsx" used instead of a more straightforward name like "App"?

Understanding the purpose will help ensure that this implementation aligns with the overall project structure and goals.

apps/docs/content/components/input-otp/variants.ts (2)

17-19: Clarify the purpose of the react object and consider type safety improvements.

The react object's purpose is not immediately clear from the context. It appears to be mapping a file path to the App component, which might be used in a documentation system or code playground. However, this approach raises some concerns:

  1. The use of a string key "/App.jsx" makes the code more prone to typos and harder to refactor.
  2. The .jsx extension in the key doesn't match the .ts file extension, which could lead to confusion.

Could you please clarify the intended use of this object? Depending on its purpose, consider the following improvements:

  1. If it's for internal use, consider using a more type-safe approach:
const react = {
  App: App
};
  1. If it's required for an external system, consider adding type safety:
type ReactComponents = {
  "/App.jsx": React.ComponentType;
};

const react: ReactComponents = {
  "/App.jsx": App
};

This approach maintains the current structure while adding type safety.


21-23: 🛠️ Refactor suggestion

Consider simplifying the export mechanism for improved clarity.

The current export mechanism uses the spread operator to export the contents of the react object. While this approach allows for easy expansion in the future, it's not immediately clear why this indirect method is necessary, especially since react only contains one component.

For improved clarity and maintainability, consider simplifying the export:

export default { App };

This direct export makes it immediately clear what's being exported from the module.

If there's a specific reason for the current approach (e.g., consistency with other files or a requirement of the build system), please clarify. Otherwise, the simpler export would be preferable.

Could you explain the rationale behind the current export mechanism? Is it required for compatibility with other parts of the system?

packages/components/input-otp/README.md (2)

9-15: Installation instructions look good

The installation section provides clear instructions for both Yarn and npm users. This is helpful and covers the most common package managers.


23-26: License information is clear and concise

The license section provides the necessary information about the project's licensing terms and includes a link to the full license text. This is sufficient for users to understand the terms under which they can use the component.

apps/docs/content/components/input-otp/index.ts (3)

1-13: Well-organized imports covering comprehensive OTP features

The imports are well-structured and provide a comprehensive coverage of various aspects of the OTP input component. This organization suggests thorough documentation of the component's features and use cases.


15-29: Well-structured export for centralized OTP content access

The inputOtpContent constant is well-organized, providing a single point of access for all OTP-related documentation. This structure facilitates easy import and use of OTP content throughout the application.


1-29: Excellent module organization for OTP documentation

This file demonstrates excellent module organization for the OTP input component documentation. By centralizing all OTP-related imports and exporting them as a single object, it enhances maintainability and facilitates easy updates to the documentation structure. This approach is particularly beneficial for large projects, allowing for modular documentation that can be easily extended or modified in the future.

apps/docs/content/components/input-otp/usage.ts (1)

32-34: LGTM! Clean and extensible export structure.

The default export using the spread operator is a good choice. It allows for easy expansion if more components are added in the future, while keeping the export statement clean and concise.

apps/docs/content/components/index.ts (1)

21-21: LGTM: New component export added correctly

The new export statement for the "input-otp" component has been added correctly. It maintains the alphabetical order of the exports, which is consistent with the existing pattern in the file. This change aligns well with the PR objective of introducing the new Input OTP component to the NextUI library.

packages/core/theme/src/components/index.ts (1)

20-20: LGTM! New export added correctly.

The new export for the input-otp module has been added in the correct alphabetical order, maintaining consistency with the existing structure of the file. This change aligns with the PR objectives to introduce the new Input OTP component.

Let's verify the existence of the input-otp.ts file:

✅ Verification successful

LGTM! The input-otp.ts file exists and the export is correctly added.

The verification confirms that the input-otp.ts file is present in the components directory. The new export statement has been added in the appropriate alphabetical order, maintaining consistency with the existing structure of the file.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the input-otp.ts file in the components directory

# Test: Check if the input-otp.ts file exists
fd -p 'packages/core/theme/src/components/input-otp.ts'

Length of output: 103

packages/components/input-otp/package.json (2)

27-35: LGTM: Well-structured scripts section.

The scripts section is comprehensive and follows good practices:

  • Uses tsup for building, which is efficient for TypeScript projects.
  • Includes separate scripts for fast builds and watching during development.
  • Incorporates type checking and cleaning operations.
  • Utilizes clean-package for managing package.json during publishing.

This setup should provide a smooth development and build process.


42-59: LGTM: Well-structured dependencies. Clarify react-hook-form usage.

The dependencies and devDependencies sections are well-organized:

  • Appropriate use of workspace dependencies for NextUI packages.
  • Specific versions for external dependencies ensure consistency.

Question: The inclusion of react-hook-form as a devDependency suggests it might be used in examples or tests. Could you clarify its intended use? If it's not necessary for the core functionality of the input-otp component, consider moving it to a separate example or test package to keep this package's dependencies minimal.

apps/docs/package.json (1)

29-29: New dependency added: @nextui-org/input-otp

The addition of the @nextui-org/input-otp dependency is consistent with the PR's objective of introducing a new input-otp component. The workspace:* version suggests this is a local package within the monorepo.

To ensure proper integration, please verify:

  1. The component is correctly exported from the main package.
  2. The component is included in the documentation.

You can run the following commands:

#!/bin/bash
# Check if the component is exported in the main package
grep -r "export.*from.*input-otp" packages/core

# Verify documentation exists for the new component
find apps/docs/content -type f -name "*input-otp*.mdx"
apps/docs/public/sitemap-0.xml (2)

3-76: LGTM! Sitemap updated with new components and consistent timestamps.

The sitemap has been comprehensively updated with the following improvements:

  1. All URLs now have a consistent lastmod date of 2024-10-07T07:41:49.600Z, ensuring search engines have the most up-to-date information.
  2. New component URLs have been added, including the input-otp component (line 28), which aligns with the PR objectives.
  3. The XML structure and format are correct and consistent throughout the file.
  4. The changefreq and priority attributes are appropriately set for all URLs.

These changes will improve the discoverability of the NextUI documentation and new components in search engines.


15-15: Verify the existence of documentation for new components.

The sitemap includes URLs for new components such as calendar, date-input, date-picker, date-range-picker, input-otp, range-calendar, and time-input. Please ensure that the documentation for these components exists and is accessible at the specified URLs.

Run the following script to check the existence of the new component documentation:

Also applies to: 22-24, 28-28, 39-39, 51-51

✅ Verification successful

Documentation for New Components Verified

All documentation files for the new components (calendar, date-input, date-picker, date-range-picker, input-otp, range-calendar, and time-input) exist and are accessible at the specified locations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of documentation files for new components

new_components=(
  "calendar"
  "date-input"
  "date-picker"
  "date-range-picker"
  "input-otp"
  "range-calendar"
  "time-input"
)

for component in "${new_components[@]}"; do
  echo "Checking documentation for $component:"
  fd -t f "${component}.(mdx|md|tsx)" apps/docs/content/docs/components
done

Length of output: 1943

apps/docs/content/docs/components/input-otp.mdx (2)

1-11: LGTM: Header and introduction are well-structured

The metadata, import statement, and brief introduction provide a clear and concise start to the documentation. This structure aligns well with standard documentation practices.


130-147: LGTM: Comprehensive list of data attributes

The data attributes section provides a clear and concise list of available attributes, their conditions, and their purposes. This information is valuable for developers who need to apply custom styling or scripting based on the component's state.

🧰 Tools
🪛 LanguageTool

[style] ~145-~145: This phrase is redundant. Consider writing “filled”.
Context: ...data-filled*: When the input-otp is completely filled. - data-disabled: When the input ...

(COMPLETELY_ANNIHILATE)

apps/docs/config/routes.json (4)

261-267: LGTM: New "Input OTP" route added correctly.

The new route for the "Input OTP" component is well-structured and consistent with other component routes. The "newPost" flag is appropriately set, which will help highlight this new addition to users.


261-267: LGTM: New date-related component routes added correctly.

The new routes for "Date Input", "Date Picker", and "Range Calendar" components are well-structured and consistent with other component routes. The "newPost" flags are appropriately set for these new additions.


261-267: LGTM: Existing routes correctly marked as updated.

The "updated" flag has been consistently applied to the modified routes for "Layout", "Badge", "Checkbox", "Skeleton", "Tabs", "Tooltip", and "CLI API". This will effectively highlight recent changes to users.


261-267: Summary: Routes updated successfully to reflect new and modified components.

The changes to the routes.json file accurately reflect the addition of the new Input OTP component and other date-related components. The file structure remains consistent, and the updates align well with the PR objectives. The use of "newPost" and "updated" flags will effectively guide users to the latest changes in the documentation.

packages/components/input-otp/src/input-otp-segment.tsx (1)

42-52: Component rendering is well-structured and efficient

The component correctly renders the OTP segment with appropriate class names and data attributes. The implementation is clean and follows best practices.

packages/components/input-otp/__tests__/input-otp.test.tsx (1)

277-295: Comprehensive Integration Tests with React Hook Form

The tests effectively cover the integration of InputOtp with React Hook Form, including default values and form submission behavior. This ensures that the component works seamlessly in form contexts.

packages/components/input-otp/src/use-input-otp.ts (1)

144-148: Review the prevention of default behavior for arrow keys.

The onKeyDownCapture function prevents default behavior for the "ArrowLeft" and "ArrowRight" keys. This may interfere with the user's ability to navigate within the input field using the keyboard.

Please verify if preventing the default behavior for arrow keys is necessary. If not, consider removing the e.stopPropagation() and e.preventDefault() calls.

Run the following script to identify where onKeyDownCapture is used and assess the impact:

packages/core/theme/src/components/input-otp.ts (1)

44-45: Verify if text-tiny is a valid Tailwind CSS class

The text-tiny class used in the errorMessage and description slots may not be a standard Tailwind CSS utility class. This could lead to unintended styling issues.

Run the following script to check if text-tiny is defined in the codebase:

apps/docs/content/components/input-otp/description.ts Outdated Show resolved Hide resolved
apps/docs/content/components/input-otp/radius.ts Outdated Show resolved Hide resolved
apps/docs/content/components/input-otp/variants.ts Outdated Show resolved Hide resolved
apps/docs/content/components/input-otp/colors.ts Outdated Show resolved Hide resolved
packages/components/input-otp/src/use-input-otp.ts Outdated Show resolved Hide resolved
packages/components/input-otp/src/use-input-otp.ts Outdated Show resolved Hide resolved
packages/components/input-otp/src/use-input-otp.ts Outdated Show resolved Hide resolved
packages/core/theme/src/components/input-otp.ts Outdated Show resolved Hide resolved
packages/core/theme/src/components/input-otp.ts Outdated Show resolved Hide resolved
@wingkwong
Copy link
Member

just an update. we're finalising the design. can you DM me at discord with your email address?

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

for the documentation, please sync with canary branch once and adopt the latest format (see apps/docs/content/components/accordion).

@macci001
Copy link
Contributor Author

@coderabbitai pause

Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

✅ Actions performed

Reviews paused.

@macci001 macci001 force-pushed the macci001/add-input-otp-component branch 2 times, most recently from aa5260a to 7d2230b Compare October 23, 2024 20:09
@wingkwong
Copy link
Member

UPD: the design is finalised. please refer to the figma I shared to you in discord and update accordingly. thanks.

@wingkwong wingkwong marked this pull request as draft October 25, 2024 04:28
@jrgarciadev
Copy link
Member

Hey @macci001 please fix the conflicts

@macci001 macci001 force-pushed the macci001/add-input-otp-component branch 3 times, most recently from ec71367 to 0eab6a1 Compare November 14, 2024 06:36
@macci001 macci001 force-pushed the macci001/add-input-otp-component branch from 0eab6a1 to 9385097 Compare November 14, 2024 10:26
@macci001 macci001 marked this pull request as ready for review November 14, 2024 10:31
@macci001 macci001 changed the base branch from canary to macci001/eng-1537 November 14, 2024 19:25
@macci001 macci001 merged commit bafa07f into nextui-org:macci001/eng-1537 Nov 14, 2024
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Input OTP
3 participants