Coder Social home page Coder Social logo

shubhadip / svelte-otp Goto Github PK

View Code? Open in Web Editor NEW
14.0 5.0 0.0 1.18 MB

OTP Input Component for Svelte

License: MIT License

HTML 7.02% JavaScript 89.99% Svelte 1.31% CSS 0.95% TypeScript 0.66% Shell 0.07%
otp otp-input svelte svelte3 typescript vite vitejs javascript masked-inputs otp-verification

svelte-otp's Introduction

Svelte Otp

Build Status

codecov

Netlify Status

A Otp Component that can be used with Svelte.

Install

npm install svelte-otp --save

yarn add svelte-otp

Demo

To view a demo online: https://svelte-otp.netlify.app/

To view demo examples locally clone the repo and run npm install && npm run dev

import OtpInput from 'svelte-otp';

// main
<OtpInput
    separator="-"
    placeholder="0000"
    ...
/>

Usage

<OtpInput
		separator="-"
		placeholder="0000"
        ...
	/>

numberOfInputs prop

    <OtpInput numberOfInputs={6} />

numberOfInputs along with separatorprop

<OtpInput numberOfInputs={4} separator="-"  />

Using numberOfInputs, separator and placeholder props

<OtpInput separator="-" placeholder="******" numberOfInputs={6}  />

Masking Input

<OtpInput separator="-" placeholder="****" numberOfInputs={4} maskInput={true} />

Change Focus on Input/Delete

<OtpInput
	...
	autoFocusNextOnInput={true}
	focusPreviousOnDelete={true}
/>

Programtic Access of value of Otp

    let otpInstance: {getValue: () => void};
    function handleClick() {
        console.log('value on click',
            otpInstance?.getValue());
    }
	...
<OtpInput
		...
		bind:this={otpInstance}
	/>

Prefill value on some other events/actions

function callbackFunction(event: CustomEvent) {
    console.log('emittedValue', event.detail);
}
function handlePrefill() {
    value = '123456';
}
<OtpInput
		...
        bind:initialValue={value}
		on:notify={callbackFunction}
		...
		emitEventOnPrefill={false}
	/>
<div class="button-otp" on:click={handleClick}> Get Value </div>

Event on Otp Filled completely

function callbackFunction(event: CustomEvent) {
    console.log('emittedValue', event.detail);
}

<OtpInput
		...
		on:notify={callbackFunction}
		...
		emitEventOnPrefill={false}
	/>

Available props

Prop Type Default Description
numberOfInputs Number 4 Number of Inputs to be shown
separator String separator between inputs
placeholder String placeholder for text inputs.
maskInput Boolean false mask input values
autoFocusNextOnInput Boolean true focus on next input after entering value
focusPreviousOnDelete Boolean true move focus to previous element on delete
customWrapperClass string false used to style wrapper element of otp
customSeparatorClass string used to style separator
customRowClass string used to style individual input
customInputWrapperClass string used to style input wrapper
customTextInputClass string used to style input box
emitEventOnPrefill string emits events on filling all input fields

Events

Only emitted event.

eventObj = { completevalue: string; isInputComplete: boolean; }

Event Output Description
notify eventObj Even is emitted when input is complete

Authors

@shubhadip

svelte-otp's People

Contributors

hey-shrey avatar semantic-release-bot avatar shubhadip avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

svelte-otp's Issues

index.css error

it always checks if i have a index.css in my folder and gives away an error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.