npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-otp-code-input

v0.0.4

Published

ngx-otp-code-input is an Angular component for OTP (One-Time Password) input. This component is highly customizable, allowing for various configurations such as masking, integer-only input, autofocus, and more.

Downloads

249

Readme

ngx-otp-code-input

ngx-otp-code-input is an Angular component for OTP (One-Time Password) input. This component is highly customizable, allowing for various configurations such as masking, integer-only input, autofocus, and more.

If you like the library, please consider giving it a ⭐ on GitHub.

Features

  • Customizable Length: Specify the number of OTP input fields.
  • Masking: Hide input values, useful for password-like behavior.
  • Integer Only: Restrict input to only integers.
  • Autofocus: Automatically focus on the first input field.
  • Read-only and Disabled States: Make the input fields read-only or disabled.
  • Tab Index: Control tab navigation between input fields.
  • Events: Emit events on OTP change and completion.
  • Success/Error Status Feedback: Visually indicate the result of OTP verification with customizable icons and colors.
  • Animated Transitions: Smooth transitions or animations when focusing between OTP input fields.

Installation

Install the package via npm:

  npm install ngx-otp-code-input

Usage

Import the Module

Add NgxOtpCodeInputModule to your Angular module:

import { NgxOtpCodeInputModule } from 'ngx-otp-code-input';

@NgModule({
  declarations: [
    // your components
  ],
  imports: [
    // other modules
    NgxOtpCodeInputModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Use the Component in Your Template

Add the ngx-otp-code-input component to your template:

<ngx-otp-code-input
  [length]="6"
  [mask]="false"
  [integerOnly]="false"
  [disabled]="false"
  variant="outline"
  [readonly]="false"
  [autofocus]="true"
  [animationConfig]="{ type: 'slide', duration: '1.0s' }" <!-- Optional: Configure animations -->
  [status]="otpStatus" <!-- Bind this to a variable in your component -->
  [successIcon]="'check_circle'" <!-- Optional: Bind to a custom icon for success -->
  [failureIcon]="'cancel'" <!-- Optional: Bind to a custom icon for failure -->
  [tabIndex]="true"
  (otpChange)="onOtpChange($event)"
  (otpComplete)="onOtpComplete($event)"
></ngx-otp-code-input>

Handle Events in Your Component

Add event handlers in your component:

export class AppComponent {
  otpStatus: 'success' | 'failed' | null = null;

  onOtpComplete(event: string): void {
    console.log('OTP Complete:', event);
  }

  onOtpChange(event: string): void {
    console.log('OTP Change:', event);
  }
}

Configuration

Inputs

| Input | Type | Default | Description | | :-------- | :------- | :-------- | :----------------------| | length | number | 4 | Number of OTP input fields. | | mask | boolean | false | Hide the input values (like a password field).| | integerOnly | boolean | false | Restrict input to only integer values.| | disabled | boolean | false | Disable the input fields.| | readonly | boolean | false | Make the input fields read-only.| | autofocus | boolean | true | Automatically focus on the first input field.| | tabIndex | boolean | false | Enable tab navigation between input fields.| | inputClass | string | '' | Custom CSS class for the input fields.| | variant | MatFormFieldAppearance | 'outline', 'fill' | Appearance of the Material form field.| | regex | string | '' | Custom regex pattern for the input fields.| | status | any | null | Visual status of OTP verification.| | successIcon | string | 'check_circle' | Custom icon for success status.| | failureIcon | string | 'error' | Custom icon for failure status.| | animationConfig | { type: string, duration: string } | { type: 'slide', duration: '1.0s' } | Configuration for animations when focusing between input fields.|

Outputs

| Output | Type | Description | | :-------- | :------- | :-------------------------------- | | otpChange | EventEmitter<string> | Emits the current OTP value when it changes | | otpComplete | EventEmitter<string> | Emits the OTP value when all fields are filled. |

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss changes. 🚀

License

MIT