0.5.5 • Published 9 months ago

@j2only/pincode v0.5.5

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

@j2only/pincode

npm publish npm npm bundle size (scoped) CodeFactor Grade TypeScript contributions welcome GitHub

Vue.js pincode input component. :lock: Written entirely on Vue 3 Composition API with Typescript and Vite. Compatible only with Vue.js 3.x.

  • Simple pincode input field
  • Minimal style
  • Customizable
  • Smooth animations

You can check a DEMO HERE

Installation

Install this component via package manager:

yarn add @j2only/pincode

https://nodei.co/npm/@j2only/pincode.png?downloads=true&downloadRank=true&stars=true

Usage

Import the component in your app and pass some settings:

<template>
    <vue-pincode
        name="pincode"
        ref="pincodeInput"
        :length="4"
        :releaseSuccess="true"
        :releaseSuccessDelay="2500"
        :releaseErrorDelay="500"
        :customButton="true"
        @clickButton="buttonFn"
        @clickCustomButton="cButtonFn"
        @pincode="checkPincode"
    />
</template>

<script setup lang="ts">
import VuePincode from "@j2only/pincode";

const pincodeInput = ref()
const cButtonFn = ref(() => alert("the custom button clicked!"))
const answer = "1234"

function checkPincode(pincode: string) {
    setTimeout(() => {
        if (pincode === answer)
            pincodeInput.value.triggerSuccess()
        else
            pincodeInput.value.triggerMiss()
    }, 300)
}
</script>

Props

As you can see, the component accepts some props:

PropTypeDefaultDescription
nameString"pincode"Unique ID, in case of using several components on one page
lengthNumber4Required pincode length, minimum 2, maximum 8
releaseSuccessBooleantrueReset state after delay when entered pincode is correct
releaseSuccessDelayNumber2500Delay to reset state after entered pincode is correct (milliseconds)
releaseErrorDelayNumber500Delay to reset state after entered pincode is invalid (milliseconds)
customButtonBooleanfalseShow custom button

CSS Variables

Also, you can customize some styles via CSS Variables:

VariableDefaultDescription
--pc-color-button#010101Color of digits
--pc-color-button-pressed#474747Color of pressed digit
--pc-color-button-bg#f6f6f6Color of digits background
--pc-color-button-bg-pressed#eaeaeaColor of pressed digit background
--pc-color-field-normal#234567Color of fields
--pc-color-field-success#42b983Color of fields when pincode is correct
--pc-color-field-error#eb0c0cColor of fields when pincode is invalid
--pc-custom-button-iconbase64 stringCustom button icon

Events

EventDescription
pincodeIs triggered when the entered pincode length is equal to length prop
clickButtonIs triggered when the some of digit buttons is pressed
clickCustomButtonIs triggered when the custom button is pressed

Project development

  • yarn dev compiles and hot-reloads demo for development
  • yarn lint lints and fixes files
  • yarn build compiles and minifies production files and demo

Licensing

MIT License Forked from @weslinkde/vue-pincode, Dominik Lenz :copyright: 2020 Weslink GmbH, MIT License

0.5.5

9 months ago

0.5.4

12 months ago

0.5.3

1 year ago

0.4.4

1 year ago

0.5.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago