5.0.2 • Published 2 months ago

@siamf/otp-timer v5.0.2

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

@siamf/otp-timer

A simple and customizable react otp timer & input component with typescript support. very simple and more customizable design and smallest bundle size. You can use this component into any react and nextjs projects.

  • SSR Friendly
  • Customizable
  • TypeScript Support
  • Smallest Bundle Size(About 13kb)
  • Otp Timer & Otp Input Component

Installation

$ npm i @siamf/otp-timer

Demo

Usage?

OtpTimer Component

import { Otptimer } from "@siamf/otp-timer";

const MyComponent = () => {

  const handleResend = () => {
    //desired function to be performed on clicking resend button
  }

  return (
    <div>
      <Otptimer
          minutes={0}
          seconds={30}
          onResend={handleResend}
          renderText={(props) => <p>You can resend code in {props.minutes} minutes and {props.seconds} seconds</p>}
          renderButton={(props) => <button {...props}>
              Send Code Again
          </button>}
      />
    </div>
  );
};

export default MyComponent;

OtpInput Component

import { useState } from "react";
import { OtpInput } from "@siamf/otp-timer";

export default function App() {
  const [otp, setOtp] = useState<string>(");

  return (
    <OtpInput
      value={otp}
      onChange={setOtp}
      numInputs={4}
      renderSeparator={<span>-</span>}
      renderInput={(props) => <input {...props} />}
    />
  );
}

Customization

OtpTimer component

Options

nameDescriptionDefault Value
secondsnumber of seconds for which timer must be set30
minutesnumber of minutes for which the timer must be set0
onResendfunction that would get triggered on clicking the resend buttonn/a
renderTextCustomizable text content(See Example Code)Required
renderButtonCustomizable button content(See Example Code)Required

OtpInput component

Issues

You are welcome to create an issue.

Stay in touch

5.0.2

2 months ago

4.5.0

2 months ago

4.0.1

5 months ago

4.0.0

5 months ago