A reusable OTP (One Time Password) input component built with Next.js, Tailwind CSS, and NextUI.
🚨🚨 Project under construction 🚨🚨
OTP NextJs Library
A reusable OTP (One Time Password) input component built with Next.js, Tailwind CSS, and NextUI.
Table of Contents
Installation
You can install the
next-otp
npm
If you are using npm as your package manager, you can install
next-otp
npm i next-otp
yarn
If you are using yarn as your package manager, you can install next-otp by running the following command in your terminal:
yarn add next-otp
pnpm
If you are using pnpm as your package manager, you can install next-otp by running the following command in your terminal:
pnpm add next-otp
Usage
React
Here's how you can use the OTP input component in your React project:
import React, { useState } from "react"; import OTP from "otp-next"; import "otp-next/styles.css"; const OTPExample = () => { const [otp, setOtp] = useState(""); const handleComplete = (otp) => { console.log("OTP complete:", otp); setOtp(otp); }; return ( <div className="flex flex-col items-center justify-center min-h-screen py-2"> <h1 className="text-2xl font-bold">OTP Input Example</h1> <OTP onComplete={handleComplete} /> <p className="mt-4">Entered OTP: {otp}</p> </div> ); }; export default OTPExample;
Next.js
Here's how you can use the OTP input component in your Next.js project:
"use client"; // NOTE - Client-side rendered component import React, { useState } from "react"; import OTP from "otp-next"; import "otp-next/styles.css"; const OTPExample = () => { const [otp, setOtp] = useState(""); const handleComplete = (otp: string) => { console.log("OTP complete:", otp); setOtp(otp); }; return ( <div className="flex flex-col items-center justify-center min-h-screen py-2"> <h1 className="text-2xl font-bold">OTP Input Example</h1> <OTP onComplete={handleComplete} /> <p className="mt-4">Entered OTP: {otp}</p> </div> ); }; export default OTPExample;
Props
| Prop | Type | Default | Description | | ------------- | ---------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------- | |
length
number
onComplete
(otp: string) => void
null
accept
string
numbers
inputHeight
inputWidth
inputProps
spacing
Types
AcceptType
| Type key | Description | | -------------- | ------------------------------- | |
numbers
letters
alphanumeric
HeightClass
| Enum key | CSS Property Value Height | | ---------- | ------------------------- | |
h-0
h-1
h-2
h-3
h-4
h-5
h-6
h-7
h-8
h-9
h-10
h-11
h-12
h-14
h-16
h-20
h-24
h-28
h-32
h-36
h-40
h-44
h-48
h-52
h-56
h-60
h-64
h-72
h-80
h-96
h-auto
h-px
h-0.5
h-1.5
h-2.5
h-3.5
h-1/2
h-1/3
h-2/3
h-1/4
h-2/4
h-3/4
h-1/5
h-2/5
h-3/5
h-4/5
h-1/6
h-2/6
h-3/6
h-4/6
h-5/6
h-full
h-screen
h-svh
h-lvh
h-dvh
h-min
h-max
h-fit
WidthClass
| Enum key | CSS Property Value Width | | ---------- | ------------------------ | |
w-0
w-1
w-2
w-3
w-4
w-5
w-6
w-7
w-8
w-9
w-10
w-11
w-12
w-14
w-16
w-20
w-24
w-28
w-32
w-36
w-40
w-44
w-48
w-52
w-56
w-60
w-64
w-72
w-80
w-96
w-auto
w-px
w-0.5
w-1.5
w-2.5
w-3.5
w-1/2
w-1/3
w-2/3
w-1/4
w-2/4
w-3/4
w-1/5
w-2/5
w-3/5
w-4/5
w-1/6
w-2/6
w-3/6
w-4/6
w-5/6
w-1/12
w-2/12
w-3/12
w-4/12
w-5/12
w-6/12
w-7/12
w-8/12
w-9/12
w-10/12
w-11/12
w-full
w-screen
w-svw
w-lvw
w-dvw
w-min
w-max
w-fit
SpacingClass
| Enum key | CSS Property Value Gap | | --------- | ---------------------- | |
gap-0
gap-1
gap-2
gap-3
gap-4
gap-5
gap-6
gap-7
gap-8
gap-9
gap-10
gap-11
gap-12
gap-14
gap-16
gap-20
gap-24
gap-28
gap-32
gap-36
gap-40
gap-44
gap-48
gap-52
gap-56
gap-60
gap-64
gap-72
gap-80
gap-96
gap-px
gap-0.5
gap-1.5
gap-2.5
gap-3.5