diff --git a/README.md b/README.md new file mode 100644 index 0000000..f4dd99b --- /dev/null +++ b/README.md @@ -0,0 +1,103 @@ +# OTP Input for React + +Still writing docs/examples... + +## Installation + +`npm install input-otp` + +## Default example + +The example below uses `tailwindcss` `@shadcn/ui` `tailwind-merge` `clsx`: + +```tsx +'use client' +import { OTPInput } from 'input-otp' + + ( + <> +
+ {slots.slice(0, 3).map((slot, idx) => ( + + ))} +
+ + + +
+ {slots.slice(3).map((slot, idx) => ( + + ))} +
+ + )} +/> + +// Feel free to copy. Uses @shadcn/ui tailwind colors. +function Slot(props: { char: string | null; isActive: boolean }) { + return ( +
+ {props.char !== null &&
{props.char}
} + {props.char === null && props.isActive && } +
+ ) +} + +// You can emulate a fake textbox caret! +function FakeCaret() { + return ( +
+
+
+ ) +} + +// Inspired by Stripe's MFA input. +function FakeDash() { + return ( +
+
+
+ ) +} + +// tailwind.config.ts for the blinking caret animation. +const config = { + theme: { + extend: { + keyframes: { + 'caret-blink': { + '0%,70%,100%': { opacity: '1' }, + '20%,50%': { opacity: '0' }, + }, + }, + animation: { + 'caret-blink': 'caret-blink 1.2s ease-out infinite', + }, + }, + }, +} + +// Small utility to merge class names. +import { clsx } from "clsx"; +import { twMerge } from "tailwind-merge"; + +import type { ClassValue } from "clsx"; + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)); +} +``` \ No newline at end of file