1.0.6 • Published 1 year ago

@jonwasdone/react-otp v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React OTP Input

Static Badge Static Badge

A simple fully customizable OTP input component for React that focuses on versatility and robustness.

see here

Install

$ npm install --save @jonwasdone/react-otp

Usage

function App() {
  const [otp, setOtp] = useState("");

  return (
    <OTPInputGroup length={6} onChange={(otp) => setOtp(otp)} value={otp} />
  );
}

export default App;

API

PropTypeDefaultDescription
autoFocusbooleantrueWhether the input should be focused on mount.
lengthnumber4The length of the OTP input.
onChange(otp: string) => void-The callback function that is called when the OTP input changes.
onSubmit(otp: string) => void-The callback function that is called when the OTP input is completed. Once the last value of the input is entered, the onSubmit callback gets triggered.
onPaste(otp: string) => void-The callback function that is called when the OTP input is pasted.
defaultValuestring""The default value of the OTP input.
valuestring-The value of the OTP input.
styleReact.CSSProperties{}The style of the input.
inputClassNamestring-The class name of the input.
inputGroupClassNamestring-The style of the input container.
inputSeparatorRender(index: number) => React.ReactNode-The function that returns the separator between the inputs. The separator can be conditionally rendered in relation to the id of the input before.

Styling

The component is fully customizable. You can style the input and the input container by passing the style, inputClassName, and inputGroupClassName props.

<OTPInputGroup
  length={6}
  onChange={(otp) => setOtp(otp)}
  value={otp}
  style={{ color: "red" }}
  inputClassName="input"
  inputGroupClassName="input-group"
/>

To include the default styles, you can import the import "@jonwasdone/react-otp/dist/index.css"; file from the package. If you are using Tailwind CSS, you don't need to include the styles as the component is built with Tailwind.

License

Static Badge

Contributing

Static Badge

Feel free to contribute to the project by opening an issue or a pull request. 🥑

Author

Vasjon Done - GitHub

1.0.6

1 year ago

1.0.2

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago