-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(input-otp): Adding Input OTP component #3748
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
Merged
macci001
merged 2 commits into
heroui-inc:macci001/eng-1537
from
macci001:macci001/add-input-otp-component
Nov 14, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@nextui-org/input-otp": minor | ||
| "@nextui-org/theme": minor | ||
| --- | ||
|
|
||
| Adding new input-otp component. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
apps/docs/content/components/input-otp/allowed-keys.raw.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| const exps = [ | ||
| { | ||
| name: "For below InputOtp, only lower-case alphabets (a to z) are allowed:", | ||
| value: "^[a-z]*$", | ||
| }, | ||
| {name: "For below InputOtp, only upper-case alphabets(A to Z) are allowed:", value: "^[A-Z]*$"}, | ||
| ]; | ||
|
|
||
| return ( | ||
| <div className="w-full flex flex-wrap gap-6"> | ||
| {exps.map((exp, idx) => ( | ||
| <div key={idx} className="flex w-full flex-col flex-wrap md:flex-nowrap mb-6 md:mb-0 gap-4"> | ||
| <div className="text-foreground/60">{exp.name}</div> | ||
| <InputOtp allowedKeys={exp.value} length={4} /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./allowed-keys.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| const colors = ["default", "primary", "secondary", "success", "warning", "danger"]; | ||
|
|
||
| return ( | ||
| <div className="w-full flex flex-wrap gap-6"> | ||
| {colors.map((color) => ( | ||
| <div | ||
| key={color} | ||
| className="inline-flex flex-col flex-wrap md:flex-nowrap mb-6 md:mb-0 gap-4" | ||
| > | ||
| <div className="text-foreground/60">color: {color}</div> | ||
| <InputOtp color={color} length={4} /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./colors.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
| import React from "react"; | ||
|
|
||
| export default function App() { | ||
| const [value, setValue] = React.useState(""); | ||
|
|
||
| return ( | ||
| <div className="w-full flex flex-col gap-2 max-w-[240px]"> | ||
| <InputOtp length={4} value={value} onValueChange={setValue} /> | ||
| <p className="text-default-500 text-small">InputOtp value: {value}</p> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./controlled.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| 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} /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./description.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; | ||
|
macci001 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
| <InputOtp isDisabled defaultValue="123" length={4} /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./disabled.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
13 changes: 13 additions & 0 deletions
13
apps/docs/content/components/input-otp/error-message.raw.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| 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} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./error-message.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import usage from "./usage"; | ||
| import disabled from "./disabled"; | ||
| import readonly from "./readonly"; | ||
| import required from "./required"; | ||
| import sizes from "./sizes"; | ||
| import colors from "./colors"; | ||
| import variants from "./variants"; | ||
| import radius from "./radius"; | ||
| import description from "./description"; | ||
| import errorMessage from "./error-message"; | ||
| import allowedKeys from "./allowed-keys"; | ||
| import controlled from "./controlled"; | ||
| import password from "./password"; | ||
|
|
||
| export const inputOtpContent = { | ||
| usage, | ||
| disabled, | ||
| readonly, | ||
| required, | ||
| sizes, | ||
| colors, | ||
| variants, | ||
| radius, | ||
| description, | ||
| errorMessage, | ||
| allowedKeys, | ||
| controlled, | ||
| password, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
| <InputOtp length={4} type="password" /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./password.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| const radiusValues = ["none", "sm", "md", "lg", "full"]; | ||
|
|
||
| return ( | ||
| <div className="w-full flex flex-wrap gap-6"> | ||
| {radiusValues.map((radius) => ( | ||
| <div | ||
| key={radius} | ||
| className="inline-flex flex-col flex-wrap md:flex-nowrap mb-6 md:mb-0 gap-4" | ||
| > | ||
| <div className="text-foreground/60">radius: {radius}</div> | ||
| <InputOtp length={4} radius={radius} /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./radius.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
| <InputOtp isReadOnly defaultValue={1234} length={4} /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./readonly.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
| <InputOtp isRequired length={4} /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./required.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| const sizes = ["sm", "md", "lg"]; | ||
|
|
||
| return ( | ||
| <div className="w-full flex flex-col gap-4"> | ||
| {sizes.map((size) => ( | ||
| <div | ||
| key={size} | ||
| className="flex flex-col w-full flex-wrap md:flex-nowrap mb-6 md:mb-0 gap-4" | ||
| > | ||
| <div className="text-foreground/60">size: {size}</div> | ||
| <InputOtp length={4} size={size} /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./sizes.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; | ||
|
macci001 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| const [value, setValue] = React.useState(""); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col items-start gap-4"> | ||
| <InputOtp color="primary" length={4} size="lg" value={value} onValueChange={setValue} /> | ||
| <div className="text-sm"> | ||
| OTP value: <span className="text-md font-medium">{value}</span> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./usage.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import {InputOtp} from "@nextui-org/react"; | ||
|
|
||
| export default function App() { | ||
| const variants = ["flat", "bordered", "underlined", "faded"]; | ||
|
|
||
| return ( | ||
| <div className="w-full flex flex-wrap gap-6"> | ||
| {variants.map((variant) => ( | ||
| <div | ||
| key={variant} | ||
| className="inline-flex flex-col flex-wrap md:flex-nowrap mb-6 md:mb-0 gap-4" | ||
| > | ||
| <div className="text-foreground/60">variant: {variant}</div> | ||
| <InputOtp length={4} variant={variant} /> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import App from "./variants.raw.jsx?raw"; | ||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.