1.1.0 • Published 3 years ago

vue3-otp v1.1.0

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

vue3-otp

Library to use OTP

Gifphy

Installation

To install the latest version:

npm install --save vue3-otp

Import to your components

import { Vue3Otp } from "vue3-otp";

Example:

<template>
  <vue3-otp
    :otp="otp"
    :inputsCount="9"
    @complete="handleComplete"
  />
</template>

Props

Events

Timer

Timer events:

Timer data:

Import timer hook. Example:

import { Vue3Otp, useTimer } from 'vue3-otp';

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { Vue3Otp, useTimer } from 'vue3-otp';

export default defineComponent({
  components: {
    Vue3Otp
  },
  setup() {
    const otp = ref("5");
    const handleComplete = (value: string) =>
      console.log('complete: ', value);
      
    return {
      ...useTimer(),
      otp,
      handleComplete,
    }
  }
});
</script>

<template>
  <vue3-otp
    :otp="otp"
    :inputsCount="6"
    @complete="handleComplete"
  />
  <div>
    {{ timer }}
    <button @click="reset">Reset</button>
    <button @click="stop">Stop</button>
    <button @click="resume">Resume</button>
  </div>
</template>

Resend Sms

<script lang="ts">
import { defineComponent } from 'vue';
import { Vue3Otp, useTimer } from 'vue3-otp';

export default defineComponent({
  components: {
    Vue3Otp
  },
  setup() {
    const otp = ref("");
    const { timer, reset } = useTimer();
    const resend = () => {
      /** Send sms api */

      /** Clear inputs */
      otp.value = " ";

      /** Reset timer */
      reset();
    };
    return {
      otp,
      resend,
      timer,
    }
  }
});
</script>

<template>
  <div id="app">
    <vue3-otp :otp="otp" />
    <div class="timer">
      {{ timer }}
      <a href="#" @click.prevent="resend">Send again</a>
    </div>
  </div>
</template>

Some basic styles

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.vue3-otp {
  display: inline-flex;
  gap: 10px;
}
input {
  width: 50px;
  height: 50px;
  text-align: center;
  border-color: transparent transparent #999 transparent;
  border-width: 1px;
}
input:focus {
  border-bottom-color: #000;
  outline: none;
}
.timer {
  padding-top: 50px;
}
1.1.0

3 years ago

1.0.0-rc.3

3 years ago

1.0.0-rc.2

3 years ago

1.0.0-rc.1

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago