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): introduce input OTP component #4052

Open
wants to merge 6 commits into
base: beta/release-next
Choose a base branch
from

Conversation

macci001
Copy link
Contributor

@macci001 macci001 commented Nov 14, 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.
    • Added new routes and documentation for the input-otp component in the documentation site.
  • 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.
    • Updated sitemap to include new documentation links for the input-otp component.

Copy link

linear bot commented Nov 14, 2024

Copy link

vercel bot commented Nov 14, 2024

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

Name Status Preview Comments Updated (UTC)
nextui-docs-v2 ❌ Failed (Inspect) Nov 15, 2024 0:24am
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 15, 2024 0:24am

Copy link

changeset-bot bot commented Nov 14, 2024

🦋 Changeset detected

Latest commit: f17adf1

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 Patch
@nextui-org/theme Patch
@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
Contributor

coderabbitai bot commented Nov 14, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (5)
  • main
  • canary
  • fix/.*
  • chore/.*
  • feat/.*

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request introduces a new input-otp component from the @nextui-org library, designed for one-time password input functionality. It includes the creation of various related files and documentation, updates to routing configurations, and the addition of tests to ensure component functionality. The changes encompass the integration of this new component into the existing documentation and the overall structure of the project.

Changes

File Path Change Summary
.changeset/spotty-flies-jump.md Introduced new input-otp component from @nextui-org/input-otp.
apps/docs/config/routes.json Added new route for "Input OTP" and updated existing routes in documentation.
apps/docs/content/components/index.ts Exported input-otp component for public access.
apps/docs/content/components/input-otp/*.raw.jsx Added various React components (e.g., allowed-keys, colors, controlled, etc.) for OTP input.
apps/docs/content/components/input-otp/*.ts Created TypeScript files to export the corresponding raw components.
apps/docs/content/docs/components/input-otp.mdx Added documentation for the InputOtp component, including usage examples and API details.
apps/docs/package.json Added dependency for @nextui-org/input-otp.
packages/components/input-otp/*.md Created README and documentation for the @nextui-org/input-otp package.
packages/components/input-otp/tests/input-otp.test.tsx Introduced test suite for the InputOtp component.
packages/components/input-otp/package.json Created package configuration for @nextui-org/input-otp.
packages/components/input-otp/src/*.tsx Implemented core functionality for the InputOtp component and its context.
packages/core/react/package.json Added dependency for @nextui-org/input-otp.
packages/core/react/src/index.ts Exported input-otp component from the main entry point.
packages/core/theme/src/components/index.ts Exported input-otp component for public access.
packages/core/theme/src/components/input-otp.ts Created component with styling variants and configurations for input-otp.
apps/docs/public/sitemap-0.xml Updated sitemap with new URLs for the input-otp component.

Assessment against linked issues

Objective Addressed Explanation
New component "Input OTP" (#2678)

Possibly related PRs

Suggested labels

👀 Status: In Review

Suggested reviewers

  • wingkwong

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.

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

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

6-6: Enhance the changeset description

The current description could be more informative. Consider expanding it to better describe the changes and their impact.

-Adding new input-otp component.
+Adding a new input-otp component for handling one-time password inputs. This component includes multiple color themes, variants, and customization options. Closes #2678.
🧰 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)

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

6-6: Consider matching default value length with OTP length

The default value "123" is shorter than the specified length of 4, which might be confusing for users viewing the documentation. Consider using a 4-digit default value to match the length prop.

-      <InputOtp isDisabled defaultValue="123" length={4} />
+      <InputOtp isDisabled defaultValue="1234" length={4} />

5-7: Add aria-label for better accessibility

Since this is a disabled input field, adding an aria-label would improve accessibility by providing context to screen readers about why the input is disabled.

-      <InputOtp isDisabled defaultValue="123" length={4} />
+      <InputOtp 
+        isDisabled 
+        defaultValue="123" 
+        length={4} 
+        aria-label="Disabled OTP input example"
+      />
apps/docs/content/components/input-otp/description.raw.jsx (1)

3-9: Consider enhancing the example with accessibility and validation features.

While the basic implementation is correct, this being a documentation example, it could better demonstrate:

  1. Proper ARIA labels for accessibility
  2. Error handling
  3. Value validation
  4. Completion callback

Consider enhancing the example:

 export default function App() {
   return (
     <div className="flex w-full flex-wrap md:flex-nowrap gap-4">
-      <InputOtp description="This is description to the OTP component." length={4} />
+      <InputOtp
+        description="This is description to the OTP component."
+        length={4}
+        aria-label="OTP input"
+        onComplete={(value) => console.log("Completed:", value)}
+        validateChar={(value) => !isNaN(Number(value))}
+      />
     </div>
   );
 }
apps/docs/content/components/input-otp/error-message.raw.jsx (2)

3-13: Add accessibility improvements and type safety

While the example effectively demonstrates error messaging, consider these improvements:

  1. Add an aria-label for better screen reader support
  2. Add type safety for the length prop

Here's the suggested implementation:

 export default function App() {
   return (
     <div className="flex w-full flex-wrap md:flex-nowrap gap-4">
       <InputOtp
         isInvalid
         errorMessage="This is custom error message for the OTP component."
         length={4}
+        aria-label="OTP input example with error"
+        inputProps={{
+          "aria-label": "OTP digit",
+        }}
       />
     </div>
   );
 }

6-10: Consider enhancing the documentation example

Since this is a documentation example, it would be valuable to demonstrate:

  1. Error state management with validation logic
  2. How to handle the length constraint

Would you like me to provide an enhanced example that includes state management and validation?

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

5-9: Consider adding JSDoc documentation for exported items.

While the code is clean and follows best practices, adding JSDoc documentation would improve developer experience and code maintainability.

Here's a suggested improvement:

+/**
+ * Context and hook for managing OTP input state.
+ * Must be used within an InputOtp component.
+ */
 export const [InputOtpProvider, useInputOtpContext] = createContext<UseInputOtpReturn>({
   name: "InputOtpContext",
   errorMessage:
     "useInputOtpContext: `context` is undefined. Seems like you forgot to wrap all input-otp components within `<InputOtp />`",
 });
+
+/** Type of the context value */
+export type InputOtpContextValue = UseInputOtpReturn;
apps/docs/content/components/input-otp/controlled.raw.jsx (1)

4-5: Consider adding input validation for OTP values

While the controlled component implementation is correct, consider adding validation to ensure only valid OTP characters are stored in state.

 export default function App() {
-  const [value, setValue] = React.useState("");
+  const [value, setValue] = React.useState("");
+  const handleValueChange = (newValue) => {
+    // Ensure only numeric values are accepted
+    if (/^\d*$/.test(newValue)) {
+      setValue(newValue);
+    }
+  };
apps/docs/content/components/input-otp/sizes.raw.jsx (1)

1-1: Consider adding type imports for better type safety

Since this is a TypeScript-based project (NextUI), consider importing types for the InputOtp component props.

-import {InputOtp} from "@nextui-org/react";
+import {InputOtp, InputOtpProps} from "@nextui-org/react";
apps/docs/content/components/input-otp/radius.raw.jsx (1)

3-19: Consider adding ARIA labels for accessibility

While the implementation is clean and follows React best practices, consider enhancing accessibility by adding descriptive ARIA labels to help users understand the different radius variants.

 <div
   key={radius}
   className="inline-flex flex-col flex-wrap md:flex-nowrap mb-6 md:mb-0 gap-4"
+  role="group"
+  aria-label={`OTP input with ${radius} radius`}
 >
   <div className="text-foreground/60">radius: {radius}</div>
-  <InputOtp length={4} radius={radius} />
+  <InputOtp 
+    length={4} 
+    radius={radius}
+    aria-label={`Enter OTP code with ${radius} radius`}
+  />
 </div>
apps/docs/content/components/input-otp/variants.raw.jsx (3)

1-1: Consider adding type safety to the component

Since this is a documentation example, adding PropTypes or TypeScript types would help users understand the expected props and their types.

+import {InputOtpProps} from "@nextui-org/react";
 import {InputOtp} from "@nextui-org/react";

3-4: Move variants array outside component for better performance

The variants array is static and doesn't need to be recreated on every render. Consider moving it outside the component.

+const variants = ["flat", "bordered", "underlined", "faded"] as const;
+
 export default function App() {
-  const variants = ["flat", "bordered", "underlined", "faded"];

14-14: Enhance example with more use cases

The current example only shows a fixed length of 4. Consider demonstrating:

  1. Different OTP lengths (e.g., 6 for Google Authenticator)
  2. Validation and error states
  3. Disabled state
-          <InputOtp length={4} variant={variant} />
+          <div className="flex flex-col gap-4">
+            <InputOtp length={4} variant={variant} />
+            <InputOtp length={6} variant={variant} />
+            <InputOtp length={4} variant={variant} isInvalid defaultValue="1234" />
+            <InputOtp length={4} variant={variant} isDisabled />
+          </div>
apps/docs/content/components/input-otp/colors.raw.jsx (1)

3-4: Consider extracting colors array outside component.

The colors array is static and doesn't need to be recreated on each render.

+const colors = ["default", "primary", "secondary", "success", "warning", "danger"];
+
 export default function App() {
-  const colors = ["default", "primary", "secondary", "success", "warning", "danger"];
apps/docs/content/components/input-otp/allowed-keys.raw.jsx (1)

12-22: Enhance documentation examples with error states and validation.

As this is a documentation example, consider adding:

  1. Error state demonstration
  2. Validation feedback
  3. Completion handling example

Example implementation:

   return (
     <div className="w-full flex flex-wrap gap-6">
       {allowedKeysConfig.map((config) => (
         <div key={config.value} className="flex w-full flex-col flex-wrap md:flex-nowrap mb-6 md:mb-0 gap-4">
           <div className="text-foreground/60" id={`otp-label-${config.value}`}>{config.name}</div>
           <InputOtp
             allowedKeys={config.value}
             length={4}
             aria-labelledby={`otp-label-${config.value}`}
+            onComplete={(value) => console.log("Completed:", value)}
+            isInvalid={false} // Add state to demonstrate error
+            errorMessage="Invalid input"
           />
         </div>
       ))}
     </div>
   );
packages/components/input-otp/src/input-otp-segment.tsx (1)

29-39: Enhance accessibility with ARIA attributes

While the component includes role="presentation", it could benefit from additional ARIA attributes to improve screen reader support.

Apply this diff to enhance accessibility:

     <div
       className={clsx(slots.segment?.({class: segmentStyles}))}
       data-active={dataAttr(props.isActive)}
       data-has-value={dataAttr(!!props.char)}
       data-slot="segment"
       role="presentation"
+      aria-hidden="true"
     >
       {displayValue}
     </div>
packages/core/react/src/index.ts (1)

48-48: Consider maintaining alphabetical order of exports

While the export addition is correct, consider moving it between @nextui-org/input and @nextui-org/kbd to maintain alphabetical ordering, which helps with maintainability and readability.

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

10-10: Document the InputOtpProps interface

The empty interface extension suggests that all props are inherited from UseInputOtpProps. Consider documenting the available props for better developer experience.

-export interface InputOtpProps extends UseInputOtpProps {}
+/**
+ * Props for the InputOtp component.
+ * @extends UseInputOtpProps from use-input-otp
+ */
+export interface InputOtpProps extends UseInputOtpProps {}

32-54: Enhance accessibility for helper section

While the implementation is correct, consider adding ARIA attributes for better screen reader support.

-          <div {...getErrorMessageProps()}>{errorMessage}</div>
+          <div {...getErrorMessageProps()} role="alert" aria-live="polite">{errorMessage}</div>
-          <div {...getDescriptionProps()}>{description}</div>
+          <div {...getDescriptionProps()} aria-live="polite">{description}</div>
packages/components/input-otp/__tests__/input-otp.test.tsx (1)

8-15: Consider improving the mock implementation

The current mock implementation of document.elementFromPoint could be enhanced:

  1. Move it to a separate test setup file to avoid global pollution
  2. Return a more specific mock element that matches the actual use case
-beforeAll(() => {
-  document.elementFromPoint = jest.fn(() => {
-    const mockElement = document.createElement("div");
-
-    return mockElement;
-  });
-});
+// Move to __mocks__/dom.ts
+export const setupDomMocks = () => {
+  document.elementFromPoint = jest.fn(() => {
+    const mockElement = document.createElement("div");
+    // Add necessary properties and attributes
+    mockElement.setAttribute("data-segment", "true");
+    return mockElement;
+  });
+};
packages/components/input-otp/stories/input-otp.stories.tsx (3)

34-39: Consider expanding validation behavior options

The validation behavior options are currently limited to 'aria' and 'native'. Consider adding 'manual' validation behavior to support custom validation scenarios.

 validationBehavior: {
   control: {
     type: "select",
   },
-  options: ["aria", "native"],
+  options: ["aria", "native", "manual"],
 },

233-241: Follow naming conventions for story exports

The story name 'isInvalid' doesn't follow the PascalCase naming convention used by other stories.

-export const isInvalid = {
+export const InvalidState = {
   render: Template,
   args: {
     ...defaultProps,
     length: 4,
     isInvalid: true,
     errorMessage: "Invalid OTP",
   },
 };

258-271: Use design tokens for custom styling

The CustomWithClassNames story uses hardcoded color values. Consider using design tokens for better maintainability and theme consistency.

 export const CustomWithClassNames = {
   render: Template,
   args: {
     ...defaultProps,
     length: 4,
     classNames: {
-      segment: "bg-gradient-to-tr from-pink-500 to-yellow-500",
-      caret: "bg-red-700",
+      segment: "bg-gradient-to-tr from-[var(--primary-500)] to-[var(--secondary-500)]",
+      caret: "bg-[var(--danger-700)]",
     },
     radius: "md",
     description: "custom otp component",
   },
 };
apps/docs/content/docs/components/input-otp.mdx (3)

1-10: Enhance component description for better clarity

The current description is quite basic and repeated. Consider expanding it to include:

  • Common use cases (2FA, email verification, etc.)
  • Key features (customization options, accessibility support)
  • Security considerations
---
title: "Input OTP"
-description: "InputOtp is a component that allows users to enter OTP."
+description: "InputOtp is a secure input component for handling one-time passwords (OTP), commonly used in two-factor authentication, email verification, and other secure validation flows."
---

-InputOtp is a component that allows users to enter OTP.
+InputOtp provides a user-friendly interface for entering one-time passwords, featuring customizable styling, accessibility support, and secure input handling. It's ideal for implementing two-factor authentication (2FA), email verification, and similar security-focused workflows.

105-107: Improve grammar and clarity in allowed keys description

-* Users are only allowed to type certain keys. Any input other than allowed keys is simply ignored.
-* Allowed Keys can be modified by `allowedKeys` property which accepts the regex of the keys which are allowed.
-* By default, the value of `allowedKeys` is `^[0-9]*$` (i.e. only numerical digits are allowed).
+* Users can only enter characters that match the allowed pattern. Any other input is ignored.
+* The `allowedKeys` property accepts a regular expression that defines the allowed characters.
+* By default, `allowedKeys` is set to `^[0-9]*$` (only numerical digits 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)


157-179: Enhance API documentation with validation details

The API documentation should include more information about validation and error handling.

Add the following properties to the API documentation:

| Attribute          | Type                                | Description                                                                                | Default |
| ----------------- | ----------------------------------- | ------------------------------------------------------------------------------------------ | ------- |
| validationState   | `valid` \| `invalid`                | The validation state of the input                                                          | -       |
| onValidate        | `(value: string) => boolean`        | Custom validation function called when the input value changes                             | -       |

Also, consider adding a "Validation" section with examples of common validation patterns.

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

276-282: Consider enhancing the keywords for better searchability.

The route configuration follows the correct structure and conventions. However, the keywords could be more comprehensive to improve documentation searchability.

Consider expanding the keywords to include related terms:

-  "keywords": "input, otp, auth",
+  "keywords": "input, otp, auth, one-time password, authentication, verification code, security code, 2fa, two-factor authentication",
packages/core/theme/src/components/input-otp.ts (3)

43-43: Remove unnecessary empty string in helperWrapper class list

The helperWrapper slot contains an empty string "" in its class list, 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-125: Ensure consistent text sizing in size variants

In the size variants, both sm and md use text-small, while lg uses text-medium. For consistency, consider updating the md variant to use a medium text size.

Apply this diff if a larger text size is appropriate for the md variant:

 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",
 },

131-451: Refactor compoundVariants to reduce repetition

The compoundVariants section has significant repetition for different combinations of variant and color. Consider refactoring to reduce duplication, possibly by using a function to generate these combinations or leveraging a utility to merge common styles.

This refactor will enhance maintainability and make future updates more manageable.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c6326d1 and bafa07f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (48)
  • .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/allowed-keys.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/allowed-keys.ts (1 hunks)
  • apps/docs/content/components/input-otp/colors.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/colors.ts (1 hunks)
  • apps/docs/content/components/input-otp/controlled.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/controlled.ts (1 hunks)
  • apps/docs/content/components/input-otp/description.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/description.ts (1 hunks)
  • apps/docs/content/components/input-otp/disabled.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/disabled.ts (1 hunks)
  • apps/docs/content/components/input-otp/error-message.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/error-message.ts (1 hunks)
  • apps/docs/content/components/input-otp/index.ts (1 hunks)
  • apps/docs/content/components/input-otp/password.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/password.ts (1 hunks)
  • apps/docs/content/components/input-otp/radius.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/radius.ts (1 hunks)
  • apps/docs/content/components/input-otp/readonly.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/readonly.ts (1 hunks)
  • apps/docs/content/components/input-otp/required.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/required.ts (1 hunks)
  • apps/docs/content/components/input-otp/sizes.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/sizes.ts (1 hunks)
  • apps/docs/content/components/input-otp/usage.raw.jsx (1 hunks)
  • apps/docs/content/components/input-otp/usage.ts (1 hunks)
  • apps/docs/content/components/input-otp/variants.raw.jsx (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 (17)
  • apps/docs/content/components/input-otp/allowed-keys.ts
  • apps/docs/content/components/input-otp/colors.ts
  • apps/docs/content/components/input-otp/controlled.ts
  • apps/docs/content/components/input-otp/description.ts
  • apps/docs/content/components/input-otp/disabled.ts
  • apps/docs/content/components/input-otp/error-message.ts
  • apps/docs/content/components/input-otp/index.ts
  • apps/docs/content/components/input-otp/password.ts
  • apps/docs/content/components/input-otp/radius.ts
  • apps/docs/content/components/input-otp/readonly.ts
  • apps/docs/content/components/input-otp/required.ts
  • apps/docs/content/components/input-otp/sizes.ts
  • apps/docs/content/components/input-otp/usage.ts
  • apps/docs/content/components/input-otp/variants.ts
  • packages/components/input-otp/package.json
  • 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 (1)
Learnt from: macci001
PR: nextui-org/nextui#3748
File: packages/components/input-otp/__tests__/input-otp.test.tsx:237-237
Timestamp: 2024-11-12T02:48:07.324Z
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.
🪛 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

[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] ~141-~141: 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] ~186-~186: 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 (44)
.changeset/spotty-flies-jump.md (1)

1-4: LGTM: Version bumps are appropriate

The minor version bumps for both packages are correct as this change:

  • Adds new functionality without breaking changes
  • Requires theme support for the new component
packages/components/input-otp/src/index.ts (3)

6-7: Verify useInputOtp hook implementation

The hook follows React naming conventions. Let's verify its implementation follows React's rules of hooks.

#!/bin/bash
# Description: Check hook implementation and documentation

# Look for hook implementation details
ast-grep --pattern 'export function useInputOtp($_) {
  $$$
}'

# Check if hook uses other hooks correctly
rg "use[A-Z]" packages/components/input-otp/src/use-input-otp.ts

3-4: Verify InputOtpProps type documentation

The type export follows React conventions. Let's ensure it's properly documented for consumers.

#!/bin/bash
# Description: Check for type documentation in the source file

# Look for type documentation
rg -A 5 "export.*interface.*InputOtpProps|export.*type.*InputOtpProps" packages/components/input-otp/src

1-10: Well-organized barrel file with clear separation of concerns!

The file follows best practices by:

  • Organizing exports by type (types, hooks, components)
  • Using clear and consistent naming conventions
  • Maintaining a clean and readable structure

Let's verify the imports and exports to ensure there are no circular dependencies:

✅ Verification successful

Barrel file structure is well-organized and free of circular dependencies

The verification confirms that:

  • All exported entities (InputOtp, InputOtpProps, useInputOtp) exist in their respective files
  • No circular dependencies are present (no imports from index.ts in any of the component files)
  • The component follows a clean architecture with proper separation of concerns:
    • Component logic in input-otp.tsx
    • Hook logic in use-input-otp.ts
    • Types and exports consolidated in index.ts

The original review comment's approval is justified, and the barrel file structure is maintainable.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential circular dependencies and verify file existence

# Check if all imported files exist
fd --type f "input-otp.ts|use-input-otp.ts" packages/components/input-otp/src

# Look for any circular imports
rg -l "from.*index" packages/components/input-otp/src

Length of output: 17148


Script:

#!/bin/bash
# Let's verify the imports and exports more thoroughly

# Check for the existence of input-otp.ts and its exports
ast-grep --pattern 'export type InputOtpProps = $_'

# Check for any imports from index.ts in other files
rg "from ['\"].*index['\"]" packages/components/input-otp/src/

# Check if input-otp.ts exists and exports the component
ast-grep --pattern 'export default function InputOtp($_) {
  $$$
}'

# List all files in the input-otp directory
fd . packages/components/input-otp/src/

Length of output: 487


Script:

#!/bin/bash
# Let's check the actual content of input-otp.tsx and its exports

# Check the exports in input-otp.tsx
ast-grep --pattern 'export interface InputOtpProps {
  $$$
}'

# Check the component definition
ast-grep --pattern 'const InputOtp = $_'

# Check for any circular dependencies by looking at imports in input-otp.tsx
rg "^import.*from" packages/components/input-otp/src/input-otp.tsx

# Check imports in use-input-otp.ts
rg "^import.*from" packages/components/input-otp/src/use-input-otp.ts

Length of output: 6211

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

1-1: LGTM!

The import statement is clean and correctly imports the InputOtp component.

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

1-1: LGTM!

The import statement correctly imports the InputOtp component from the main package entry point.


3-9: Consider enhancing security and user experience

As this is a documentation example for password input, consider demonstrating these important features:

  1. Input validation and error handling
  2. Visual feedback for successful/failed input
  3. Clear user instructions
  4. Configurable length prop for different OTP lengths

Let's verify if these features are documented in the component's implementation:

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

1-9: LGTM! Clean and well-structured example

The component effectively demonstrates the disabled state of the InputOtp component. The flex layout classes provide appropriate responsive behavior, and the implementation is concise and clear.

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

1-1: LGTM: Import statement is correct

The import statement correctly imports the InputOtp component from the main NextUI package.

apps/docs/content/components/input-otp/description.raw.jsx (3)

1-1: LGTM! Clean import statement.

The import is correctly structured and imports specifically what's needed from the package.


6-6: Consider documenting the maximum length constraint.

The length prop is set to 4, but users should know if there's a maximum limit for OTP length.

#!/bin/bash
# Search for length validation in the InputOtp component implementation
ast-grep --pattern 'prop: {
  $$$
  length: {
    $$$
  }
  $$$
}'

5-7: Verify responsive behavior across different viewport sizes.

The component uses responsive classes (flex-wrap md:flex-nowrap), but we should ensure the OTP input remains usable across different screen sizes.

✅ Verification successful

The responsive behavior appears to be properly implemented

The component's implementation shows thoughtful consideration for different viewport sizes:

  • The parent container uses flex-wrap for mobile and md:flex-nowrap for larger screens, ensuring proper layout adaptation
  • The InputOTP component has built-in responsive features:
    • Multiple size variants (sm, md, lg) with appropriate dimensions for each segment
    • Configurable border radius variants for different visual styles
    • Fixed width/height ratios maintained across sizes to preserve the square shape of segments
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for responsive test cases in the test files
rg -l "viewport|screen|responsive|mobile" --type tsx --type jsx | grep -i "input-otp.*test"

# Look for existing responsive utilities or mixins
rg -l "breakpoint|media query|screen" --type css --type scss | grep -i "input-otp"

Length of output: 163


Script:

#!/bin/bash
# Search for responsive styles in the component and its test files
rg -g "**/*input-otp*" "flex-wrap|flex-nowrap|md:|sm:|lg:|xl:|mobile|responsive|screen|viewport" -A 3 -B 3

# Look for any existing responsive tests or documentation
fd "input-otp" --type file --exec grep -l -i "responsive|mobile|screen|viewport|breakpoint" {} \;

# Check the component's implementation for responsive handling
ast-grep --pattern 'const InputOtp = $_$ => {
  $$$
}'

Length of output: 10934

apps/docs/content/components/input-otp/error-message.raw.jsx (1)

1-1: LGTM: Import statement is correct

The import statement follows the recommended pattern for NextUI components.

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

1-3: LGTM! Clean import structure.

The imports are well-organized with a clear separation between function and type imports.

apps/docs/content/components/input-otp/controlled.raw.jsx (2)

1-2: LGTM! Imports are clean and minimal.


1-13: Verify documentation references

The controlled input example looks good, but let's ensure it's properly referenced in the documentation.

✅ Verification successful

Documentation references are properly set up

The controlled example is correctly referenced in the documentation:

  • The raw example is imported in controlled.ts
  • The controlled example is properly exported in the main index.ts file as part of the inputOtpContent object
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if this example is referenced in the documentation
rg -l "controlled.raw" apps/docs/content/components/input-otp/

Length of output: 115


Script:

#!/bin/bash
# Check the content of the controlled.ts file to verify proper referencing
cat apps/docs/content/components/input-otp/controlled.ts

Length of output: 174


Script:

#!/bin/bash
# Check if the controlled example is referenced in the main documentation file
rg -A 5 "controlled\.(ts|raw)" apps/docs/content/components/input-otp/page.tsx

Length of output: 168


Script:

#!/bin/bash
# Find the main documentation file for input-otp component
fd "index|page" apps/docs/content/components/input-otp/

Length of output: 105


Script:

#!/bin/bash
# Check the content of index.ts to verify if the controlled example is properly referenced
cat apps/docs/content/components/input-otp/index.ts

Length of output: 709

apps/docs/content/components/input-otp/usage.raw.jsx (2)

1-1: LGTM!

The import statement is clean and correctly structured.


1-14: Verify NextUI theming integration

Let's ensure the component follows NextUI's theming system consistently.

✅ Verification successful

Let me gather more specific information about the InputOtp component's theming implementation.


Let me check one more crucial aspect about the theming implementation by looking at the theme configuration.


NextUI theming integration is properly implemented

The InputOtp component follows NextUI's theming system correctly:

  • It uses the tv() (tailwind-variants) utility for styling
  • Properly integrates with NextUI's theme system through @nextui-org/theme
  • Implements consistent slot-based styling pattern
  • Correctly handles color variants through the NextUI provider context

The example usage in the docs is valid and follows the established patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent theme implementation across NextUI components

# Search for other NextUI input components' theme implementations
rg -A 5 "defaultVariants|variants" packages/components/input

# Search for color prop usage in other components
ast-grep --pattern 'color="primary"'

Length of output: 1309


Script:

#!/bin/bash
# Check InputOtp component's theme implementation
rg -A 10 "InputOtp" packages/components/input-otp/src

# Check for color variants in the component
rg -A 5 "variants.*color" packages/components/input-otp/src

# Look for theme integration in the component
rg -A 5 "useTheme|theme" packages/components/input-otp/src

# Check if the component uses tailwind-variants
rg -A 5 "tv\(" packages/components/input-otp/src

Length of output: 13258


Script:

#!/bin/bash
# Check theme configuration for InputOtp
rg -A 10 "inputOtp" packages/core/theme/src
rg -A 10 "inputOtp" packages/components/theme/src

# Check for variant definitions
rg -A 10 "variants.*inputOtp" packages/core/theme/src packages/components/theme/src

Length of output: 1603

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

7-17: Consider responsive behavior for mobile devices

While the layout uses flex-wrap for mobile responsiveness, the gap between items might need adjustment for smaller screens.

Let's check if there are any existing responsive gap utilities in the codebase:

✅ Verification successful

The previous search might have failed due to incorrect path. Let's try to locate the Tailwind config and check existing usage of responsive gap utilities in the codebase to make a more informed decision.


Let's verify the Tailwind configuration and check how other similar components handle responsive gaps to make a more informed recommendation.


The gap utilities are appropriately responsive

The current implementation already follows the established pattern across the Input OTP component examples, where:

  • The vertical gap (gap-4) remains consistent across breakpoints, which is appropriate for vertical stacking
  • The component uses proper responsive classes (flex-wrap to md:flex-nowrap) for layout adaptation
  • Similar patterns are consistently used across other Input OTP examples in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for responsive gap utilities in Tailwind config
rg -A 5 "gap:" apps/docs/tailwind.config.js

Length of output: 43


Script:

#!/bin/bash
# Let's check the actual Tailwind configuration file location and content
fd -e js -e cjs tailwind.config

# Also check for any existing responsive gap utilities in the codebase
rg "gap-\d+\s+md:gap-\d+" apps/docs/content

Length of output: 431


Script:

#!/bin/bash
# Let's check the content of both Tailwind configs
cat apps/docs/tailwind.config.js
cat packages/storybook/tailwind.config.js

# Let's also check for other similar components' responsive patterns
rg -A 2 "flex.*gap-\d+" apps/docs/content/components/input-otp/

Length of output: 21870

apps/docs/content/components/input-otp/radius.raw.jsx (3)

7-17: LGTM! Well-structured layout implementation

The layout implementation is well-structured with:

  • Proper use of flex layout for responsive design
  • Consistent spacing using gap utilities
  • Correct key usage in the map function
  • Clear visual hierarchy with the radius label above each input

4-4: Validate radius values against component props

The radiusValues array contains predefined radius options. Let's verify these values match the allowed prop types of the InputOtp component.

#!/bin/bash
# Description: Verify radius prop types in InputOtp component
# Expected: Find the radius prop type definition

# Search for InputOtp component type definitions
ast-grep --pattern 'interface InputOtpProps {
  $$$
  radius?: $_
  $$$
}'

1-1: Verify the import path and component availability

The code imports the InputOtp component directly from "@nextui-org/react". Let's verify this component is properly exported.

✅ Verification successful

Import statement is correct and component is properly available

The InputOtp component is correctly exported from "@nextui-org/react". The verification shows that:

  • The input-otp package is listed as a dependency in @nextui-org/react's package.json
  • The component is properly exported from packages/components/input-otp/src/index.ts
  • The component is available through the main package for consumption
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify InputOtp component export in @nextui-org/react
# Expected: Find the export statement for InputOtp component

# Search for InputOtp export in the codebase
rg -g '!node_modules' -g '!dist' -g '!*.raw.*' 'export.*InputOtp'

Length of output: 171


Script:

#!/bin/bash
# Let's try different approaches to verify the InputOtp component

# 1. Search for InputOtp in index files that might export it
rg -g '!node_modules' -g '!dist' "InputOtp" "packages/*/src/index.ts"

# 2. Look for the actual component definition
rg -g '!node_modules' -g '!dist' "const InputOtp|class InputOtp|function InputOtp"

# 3. Search for any file named input-otp
fd -g '*input-otp*' -t f

# 4. Check package.json files for dependencies
fd "package.json" -t f -x grep -l "@nextui-org/react"

Length of output: 3174


Script:

#!/bin/bash
# Let's verify if InputOtp is exported from the main package

# 1. Check the core react package's index file for InputOtp export
rg "InputOtp" "packages/core/react/src/index.ts"

# 2. Check if the input-otp package is included in the core react package
cat "packages/core/react/package.json"

# 3. Look at the input-otp package's index file
cat "packages/components/input-otp/src/index.ts"

Length of output: 3646

apps/docs/content/components/input-otp/colors.raw.jsx (2)

1-1: LGTM! Clean import statement.

The import is correctly using named import from the NextUI library.


1-19: Verify InputOtp component's accessibility features.

Since this is a new component for handling OTP input, we should ensure it meets accessibility standards.

apps/docs/content/components/input-otp/allowed-keys.raw.jsx (1)

1-3: LGTM! Clean and well-structured component setup.

The import statement and component structure follow React best practices.

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

21-21: LGTM! Export placement is correct.

The new input-otp export follows the established pattern and maintains alphabetical ordering between input and textarea components.


21-21: Verify input-otp module and documentation.

Let's ensure the module exists and is properly documented.

✅ Verification successful

Let me verify the content of the documentation and module implementation to ensure they are properly set up.


Let me check the correct path for the implementation files.


Let me check the implementation files to ensure everything is properly set up.


Input OTP module and documentation are properly implemented and verified

The module is well-structured with:

  • Complete documentation with examples and API reference
  • Proper implementation with TypeScript support
  • Comprehensive test coverage including:
    • Basic rendering
    • Accessibility features
    • User interactions
    • Form integration
    • Error handling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of input-otp module and its documentation

# Check for the module directory
echo "Checking for input-otp module..."
fd -t d "input-otp" packages/

# Check for documentation
echo "Checking for documentation..."
fd -t f "input-otp.mdx" apps/docs/content/

Length of output: 295


Script:

#!/bin/bash
# Check the content of the documentation
echo "Documentation content:"
cat apps/docs/content/docs/components/input-otp.mdx

# Check the implementation
echo -e "\nModule implementation:"
cat packages/components/input-otp/index.ts

Length of output: 13303


Script:

#!/bin/bash
# List contents of the input-otp module directory
echo "Input OTP module contents:"
ls -R packages/components/input-otp/

# Check for the main implementation file
echo -e "\nChecking for implementation files:"
fd -t f "index.tsx?" packages/components/input-otp/

Length of output: 631


Script:

#!/bin/bash
# Check the main implementation file
echo "Main index.ts content:"
cat packages/components/input-otp/src/index.ts

# Check the component implementation
echo -e "\nComponent implementation:"
cat packages/components/input-otp/src/input-otp.tsx

# Check test file
echo -e "\nTest file content:"
cat packages/components/input-otp/__tests__/input-otp.test.tsx

Length of output: 8530

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

20-20: LGTM! Export follows established conventions

The new export for input-otp is correctly positioned alphabetically and follows the same pattern as other component exports.


20-20: Verify the input-otp module

Let's ensure the referenced module exists and check for potential circular dependencies.

✅ Verification successful

The input-otp module exists and is properly implemented

The input-otp module exists as a single file at packages/core/theme/src/components/input-otp.ts rather than a directory. The export in index.ts correctly references this file. The module is part of a recent feature addition that adds OTP (One-Time Password) input functionality to the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the input-otp module existence and its dependencies

# Check if the input-otp directory and index file exist
fd --type f "index.ts" packages/core/theme/src/components/input-otp

# Look for potential circular dependencies
rg -l "from.*?components/input" packages/core/theme/src/components/input-otp

Length of output: 363


Script:

#!/bin/bash
# Let's first check if the input-otp directory exists at all
fd "input-otp" packages/core/theme/src/components

# Let's also check for any files containing input-otp in their content
rg -l "input-otp" packages/core/theme/src/components

# Check the git history for any recent changes related to input-otp
git log --all -p --full-history -- "**/input-otp*"

Length of output: 116640

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

7-8: LGTM! Clean component definition with proper typing

The component is well-structured with appropriate props typing and context usage.


10-12: LGTM! Clean style initialization

The style composition using clsx is well-organized and follows best practices.


1-5: Verify the "input-otp" import source

The import from "input-otp" seems suspicious as it appears to be importing from the package name directly. This might cause issues if the package name changes or if there are version conflicts.

✅ Verification successful

The "input-otp" import is correct and verified

The import from "input-otp" is legitimate as it's a direct dependency listed in the package.json with version 1.4.1. This is a valid third-party package that the component depends on.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if SlotProps is defined in a local file
fd -e ts -e tsx -H "SlotProps" --exec rg -l "export.*SlotProps"

# Check package.json for the input-otp dependency
fd "package.json" --exec jq -r '.dependencies["input-otp"] // .devDependencies["input-otp"] // empty'

Length of output: 171


Script:

#!/bin/bash
# Let's check the actual definition of SlotProps in the local codebase
rg -l "SlotProps" --type ts --type tsx

# Check the package.json files more thoroughly
fd "package.json" --exec cat {} \; | grep -A 5 -B 5 "input-otp"

# Check if there are any local type definitions
fd -e d.ts "input-otp"

Length of output: 2041

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

48-48: Verify the input-otp package setup

The export addition looks good and aligns with the PR objectives. Let's verify the package setup.

✅ Verification successful

Let me gather more information about the package configuration.


Input OTP package is properly set up and implemented

The package setup is complete and correct with:

  • Proper package configuration in package.json with required dependencies
  • Main component implementation with proper exports
  • Integration with the base input-otp library
  • Correct peer dependencies and workspace dependencies
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the input-otp package existence and configuration

# Check if the package directory exists and has the essential files
fd -t d "input-otp$" packages/
fd -t f "package.json" packages/*/input-otp/

# Check package.json content for proper configuration
fd -t f "package.json" packages/*/input-otp/ -x cat {} | jq '. | {name, version, main, module, types, sideEffects, license}'

# Verify the component's main file exists
fd -t f "index.ts" packages/*/input-otp/src/

Length of output: 616


Script:

#!/bin/bash
# Check package.json content with proper JSON syntax
cat packages/components/input-otp/package.json | jq '{name, version, main, module, types, sideEffects, license}'

# Check the exports in index.ts
cat packages/components/input-otp/src/index.ts

# Verify the package is listed in workspace dependencies
cat package.json | jq '.dependencies["@nextui-org/input-otp"]'

Length of output: 651


Script:

#!/bin/bash
# Check package.json content with correct jq syntax
cat packages/components/input-otp/package.json

# Check if the package is properly referenced in workspace
cat package.json | jq '.workspaces'

# Verify the component implementation exists
cat packages/components/input-otp/src/input-otp.tsx 2>/dev/null || echo "File not found"

Length of output: 3808

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

12-30: LGTM! Well-structured component initialization

The component follows React best practices with proper typing, forwarded refs, and comprehensive context usage.


82-84: LGTM! Proper component naming and export

The component follows React conventions with appropriate displayName and export pattern.


1-10: Verify the "input-otp" package dependency

The component relies on the external "input-otp" package. Ensure this dependency is properly declared in the package.json.

✅ Verification successful

The "input-otp" package dependency is properly declared

The "input-otp" package is correctly declared in the component's package.json with version 1.4.1 under dependencies. No action is required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if input-otp is declared in package.json
jq '.dependencies["input-otp"] // .devDependencies["input-otp"]' package.json

Length of output: 84


Script:

#!/bin/bash
# Check package.json in the input-otp component directory
cat packages/components/input-otp/package.json

Length of output: 1638

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

65-65: LGTM! Verify component export.

The dependency addition follows the correct pattern and is properly placed in alphabetical order.

Let's verify that the component is properly exported from the package:

✅ Verification successful

Component is properly exported and integrated

The input-otp component is correctly:

  • Located in the expected workspace path packages/components/input-otp/
  • Exported from the main entry file packages/core/react/src/index.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the input-otp component is properly exported from the main package

# Check if the component is exported in the main entry file
rg -l "export \* from .*input-otp" "packages/core/react/src/"

# Verify the component's existence in the workspace
fd -t d "input-otp" "packages/"

Length of output: 155

apps/docs/package.json (1)

29-29: LGTM! Verify peer dependencies.

The addition of @nextui-org/input-otp follows the correct workspace package pattern and maintains alphabetical ordering.

Let's verify if the new component requires any peer dependencies:

✅ Verification successful

All required peer dependencies are already present

The input-otp component's peer dependencies are all satisfied in the docs app:

  • react and react-dom >=18 ✓ (^18.2.0)
  • @nextui-org/theme >=2.0.0 ✓ (workspace:*)
  • @nextui-org/system >=2.0.0 ✓ (included via @nextui-org/react)
  • framer-motion >=11.5.6 ✓ (11.9.0)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for peer dependencies in the input-otp package

# Look for package.json of input-otp component
fd --type f "package.json" --exec grep -l "input-otp" {} \; | xargs cat | jq -r '.peerDependencies // empty'

Length of output: 299


Script:

#!/bin/bash
# Check if these peer dependencies are already included in docs/package.json
cat apps/docs/package.json | jq -r '.dependencies'

Length of output: 2617

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

1-195: Overall implementation looks good!

The test suite provides comprehensive coverage of the InputOtp component's functionality. While there are suggestions for improvements, the current implementation follows testing best practices and effectively validates the component's behavior.

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

40-40: LGTM: Input OTP documentation URL properly added

The new URL for the input-otp component documentation has been correctly added to the sitemap, aligning with the PR objectives to introduce this new component.


1-76: Verify sitemap consistency and accessibility

The sitemap structure looks good with consistent metadata across all URLs. However, let's verify the accessibility of the new URLs and the sitemap's validity.

✅ Verification successful

Let me verify the existence of other new component pages in the sitemap.


Sitemap structure and content verified successfully

All new component pages listed in the sitemap (input-otp, date-input, date-picker, date-range-picker, calendar, range-calendar, time-input, and autocomplete) have corresponding documentation files in the repository. The sitemap structure follows the standard format with consistent metadata across all URLs.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify sitemap validity and new URLs accessibility

# Test 1: Validate sitemap against XML schema
curl -s https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd > sitemap.xsd
xmllint --schema sitemap.xsd apps/docs/public/sitemap-0.xml --noout

# Test 2: Check if new documentation pages exist
# Note: This checks for the existence of the documentation source files
fd -t f "input-otp.mdx" apps/docs/content/docs/components/

Length of output: 318


Script:

#!/bin/bash
# Check for existence of documentation files for new components mentioned in sitemap
fd -t f "(date-input|date-picker|date-range-picker|calendar|range-calendar|time-input|autocomplete).mdx" apps/docs/content/docs/components/

Length of output: 496

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

Line range hint 1-500: LGTM! Route structure maintains consistency and proper organization.

The changes:

  • Maintain alphabetical ordering of components
  • Follow established patterns for route configuration
  • Properly integrate new and updated components within the existing structure
packages/components/input-otp/src/use-input-otp.ts (1)

127-139: Ensure proper usage of 'useFormValidationState' and 'useFormValidation'

The useFormValidationState and useFormValidation hooks are used, but it's important to verify that the props being passed include all necessary validation-related fields.

Run the following script to check that all required validation props are correctly defined:

✅ Verification successful

Let me gather more information about the validation-related props and their usage.


Let me try a different approach to gather information about the validation hooks and their usage.


Let me try one final search to understand the validation props and their usage.


Based on the gathered information, I can now provide a final response:

The validation hooks usage is correct and properly configured

The useFormValidationState and useFormValidation hooks from @react-aria/form and @react-stately/form are being used correctly. The component properly handles validation through:

  1. The ValidationResult type which includes validation states and error details
  2. The errorMessage prop that supports both static messages and dynamic functions
  3. Proper integration with form validation behavior through the validation hooks

The props being passed include all necessary validation-related fields as evidenced by the documentation and usage patterns across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for missing validation-related props in the Props interface.

# Search for validation props usage in the code
rg 'props\.(isInvalid|isRequired|isReadOnly|errorMessage|description)'

# Ensure these props are declared in the Props interface
rg -A 5 'interface Props' packages/components/input-otp/src/use-input-otp.ts

Length of output: 1574


Script:

#!/bin/bash
# Search for Props interface and its validation-related fields in the input-otp component
ast-grep --pattern 'interface Props {
  $$$
}'  packages/components/input-otp/src/use-input-otp.ts

# Check the useFormValidationState hook implementation
fd useFormValidationState.ts --exec cat {}

# Check the useFormValidation hook implementation
fd useFormValidation.ts --exec cat {}

Length of output: 188


Script:

#!/bin/bash
# Search for the validation hooks imports
rg "import.*useFormValidation" -A 2

# Search for validation-related props and types
rg "interface.*Props" -A 15 packages/components/input-otp/src/use-input-otp.ts

# Look for validation-related types and interfaces
rg "type.*Validation|interface.*Validation" -A 5

Length of output: 6604


Script:

#!/bin/bash
# Search for ValidationResult type definition and its usage
rg "ValidationResult" -B 2 -A 10

# Search for the complete Props interface in input-otp
rg "interface Props" -B 2 -A 30 packages/components/input-otp/src/use-input-otp.ts

# Look for validation-related imports
rg "from '@react-(aria|stately)/form'" -A 1

Length of output: 101748

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

31-31: Verify the custom animation appearance-in_1s_infinite

The caret slot uses a custom animation animate-[appearance-in_1s_infinite]. Ensure that this animation is defined in your Tailwind CSS configuration or replace it with a standard animation.

If the animation is not yet defined, consider adding it to your tailwind.config.js file under the animation key or use a predefined animation from Tailwind CSS.

apps/docs/content/components/input-otp/required.raw.jsx Outdated Show resolved Hide resolved
apps/docs/content/components/input-otp/readonly.raw.jsx Outdated Show resolved Hide resolved
apps/docs/content/components/input-otp/readonly.raw.jsx 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
@wingkwong wingkwong added this to the v2.5.0 milestone Nov 15, 2024
@wingkwong wingkwong changed the title Feat(input-otp): adding input otp component feat(input-otp): introduce input OTP component Nov 15, 2024
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)
.changeset/spotty-flies-jump.md (1)

6-6: Consider expanding the changeset description.

The current description could be more informative. Consider adding context about the component's purpose and key features.

Here's a suggested improvement:

-Adding new input-otp component.
+Adding a new input-otp component for handling one-time password inputs with support for various color themes and customization options.
🧰 Tools
🪛 LanguageTool

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

(AI_EN_LECTOR_MISSING_DETERMINER_A)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bafa07f and 1f8a070.

📒 Files selected for processing (1)
  • .changeset/spotty-flies-jump.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/spotty-flies-jump.md

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

(AI_EN_LECTOR_MISSING_DETERMINER_A)

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

1-4: LGTM! Version bumps are appropriate.

The patch updates for both packages align with semantic versioning principles since this PR adds a new component without introducing breaking changes.

@jrgarciadev jrgarciadev changed the base branch from canary to beta/release-next November 15, 2024 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Input OTP
3 participants