0.0.5 • Published 10 months ago

@codersandip/svelte-otp v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@codersandip/svelte-otp

A Svelte component for creating OTP (One-Time Password) inputs. This component allows for customizable OTP input length, supports different input types, and handles various user interactions such as input, paste, and backspace events.

Screenshot

Screenshot of Svelte OTP Component

Features

  • Customizable OTP Input Length: Set the number of OTP input fields.
  • Supports Different Input Types: Choose between text and number input types.
  • Configurable Placeholder: Set a custom placeholder for the input fields.
  • CSS Class Customization: Apply custom CSS classes for styling.
  • Automatic Focus Management: Automatically focuses the next input field as the user types.

Installation

To install the package, use npm or yarn:

npm install @codersandip/svelte-otp

or

yarn add @codersandip/svelte-otp

Usage

Import the OTP component into your Svelte application and use it as follows:

<script>
  import {OtpInput} from '@codersandip/svelte-otp';

  let otpValue = '';

  function handleOtpChange(newOtpValue) {
    otpValue = newOtpValue;
  }
</script>

<OtpInput
  length={6}
  inputType="number"
  placeholder="•"
  value={otpValue}
  onChange={handleOtpChange}
  inputWrapClass="custom-inputwrapper-class"
  inputClass="custom-input-class"
  containerClass="custom-container-class"
/>

Props

Prop NameTypeDefaultRequiredDescription
lengthnumber6NoThe number of OTP input fields.
inputType"text" | "number" | "password" | "tel""number"NoThe type of input field.
placeholderstring"•"NoThe placeholder text for the input fields.
valuestring""NoThe initial value of the OTP input fields.
inputWrapClassstring""NoCustom CSS class for the input wrapper div.
inputClassstring""NoCustom CSS class for the input fields.
containerClassstring""NoCustom CSS class for the container.
onChangefunctionN/AYesCallback function called with the current OTP value whenever it changes.

Styling

Customize the appearance of the OTP inputs using the provided CSS classes or by adding your own styles. For example:

.custom-inputwrapper-class {
  /* Custom styles for the input wrap div */
}
.custom-input-class {
  /* Custom styles for the input fields */
}

.custom-container-class {
  /* Custom styles for the container */
}

Development

To build and test the package locally:

Clone the Repository:

git clone https://github.com/codersandipdas/svelte-otp.git
cd svelte-otp

Install Dependencies:

npm install

Build the Package:

npm run build

Link the Package Locally (for Testing):

npm link

Use the Linked Package in Your Svelte Project:

npm link @codersandip/svelte-otp

Contributing

Contributions are welcome! If you have suggestions or improvements, please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago