1.0.10 • Published 11 months ago

react-custom-otp v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

react-custom-otp

NPM

A React component library for adding OTP (One-Time Password) functionality to your project.

Install

npm install --save react-custom-otp

Usage

import React, { useState } from 'react'

import { OTP } from 'react-custom-otp'
import 'react-custom-otp/dist/index.css'

const Example = () => {
  const [stringCode , setStringCode] = useState("")
    return (
      <OTP
        setStringCode={setStringCode}
        inputsNumber={5}
      />
    )
}

Props/Options

PropTypeDescriptionRequired
inputsNumbernumberThe number of OTP input fields to render.Required
separatorReactElementThe separator element to use between each OTP digit.Optional
setStringCodeReact.Dispatch<React.SetStateAction>A callback function to handle the entered OTP as a string.Required
setSubmitStatusReact.Dispatch<React.SetStateAction>A callback function to handle the submit status of the OTP component, if returns True it means all the input fields have been filled.Optional
inputsClassesstringCSS classes to apply to the input fields.Optional
inputsStylesCSSPropertiesInline styles to apply to the input fields.Optional
containerClassesstringCSS classes to apply to the container element.Optional
containerStylesCSSPropertiesInline styles to apply to the container element.Optional

Full example

import React, { useState } from 'react';
import { OTP } from 'react-custom-otp';
import 'react-custom-otp/dist/index.css';

const Example = () => {
  const [stringCode, setStringCode] = useState('');
  const [submitStatus, setSubmitStatus] = useState(false);

  return (
    <OTP
      inputsClasses="custom-inputs"
      inputsStyles={{ background: '#f1f1f1', color: '#333' }}
      containerClasses="otp-container"
      containerStyles={{ background: '#ccc' }}
      inputsNumber={6}
      setStringCode={setStringCode}
      setSubmitStatus={setSubmitStatus}
      separator={<span>-</span>}
    />
  );
};

\ The react-custom-otp library is designed to simplify the process of adding OTP functionality to your React projects. It provides an OTP component that can be easily integrated into your codebase.

To install the library, use the provided npm command, as shown in the "Install" section. Make sure to import the necessary components and the CSS file to enable the styling.

The useState hook is used to manage the stringCode state, which holds the entered OTP value. The setStringCode function is passed as a prop to the OTP component to update the value as the user inputs the OTP.

Feel free to explore the library and customize it according to your needs!

License

MIT © Hadi Raziei

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago