Git Product home page Git Product logo

pincode's Introduction

@j2only/pincode

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

Vue.js pincode input component. ๐Ÿ”’ 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:

Prop Type Default Description
name String "pincode" Unique ID, in case of using several components on one page
length Number 4 Required pincode length, minimum 2, maximum 8
releaseSuccess Boolean true Reset state after delay when entered pincode is correct
releaseSuccessDelay Number 2500 Delay to reset state after entered pincode is correct (milliseconds)
releaseErrorDelay Number 500 Delay to reset state after entered pincode is invalid (milliseconds)
customButton Boolean false Show custom button

CSS Variables

Also, you can customize some styles via CSS Variables:

Variable Default Description
--pc-color-button #010101 Color of digits
--pc-color-button-pressed #474747 Color of pressed digit
--pc-color-button-bg #f6f6f6 Color of digits background
--pc-color-button-bg-pressed #eaeaea Color of pressed digit background
--pc-color-field-normal #234567 Color of fields
--pc-color-field-success #42b983 Color of fields when pincode is correct
--pc-color-field-error #eb0c0c Color of fields when pincode is invalid
--pc-custom-button-icon base64 string Custom button icon

Events

Event Description
pincode Is triggered when the entered pincode length is equal to length prop
clickButton Is triggered when the some of digit buttons is pressed
clickCustomButton Is 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 ยฉ๏ธ 2020 Weslink GmbH, MIT License

pincode's People

Contributors

j2only avatar udaberrico avatar

Stargazers

Ef avatar

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.