0.5.7 • Published 1 month ago

@j2only/slide-unlock v0.5.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@j2only/slide-unlock

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

Vue.js slide to unlock component. Protect users from accidental clicks or protect your web app from bot attack. Written entirely on Vue 3 Composition API with Typescript and Vite. Coated with tests using Cypress. Compatible only with Vue.js 3.x.

You can check a DEMO HERE

Preview

Test coverage

StatementsBranchesFunctionsLines
StatementsBranchesFunctionsLines

Installation

Install this component via package manager:

yarn add @j2only/slide-unlock

or

npm install --save @j2only/slide-unlock

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

Usage

Import the component in your app and pass some settings:

<template>
    <slide-unlock
        ref="vueslideunlock"
        :auto-width="true"
        :circle="true"
        :width="400"
        :height="60"
        text="slide to unlock"
        success-text="success"
        name="slideunlock"
        @completed="complete()"
    />
</template>

<script>
import SlideUnlock from "@j2only/slide-unlock"

export default {
    components: {
        SlideUnlock
    }
}
</script>

As you can see, the component accepts some props:

PropTypeDefaultDescription
autoWidthBooleantrueAuto width for component
circleBooleantrueAll parts of component will be with border-radius and rounded handler
disabledBooleanfalseDisable interaction with component
noanimateBooleanfalseDisable css animations (but not css transitions)
widthNumber400Width of element (ignored if autoWidth is true)
heightNumber60Height of element
positionNumber0Progress percent (to emulate sliding)
textString"slide to unlock"Text on element
successTextString"success"Text on element when slide is completed
nameString"slideunlock"Unique ID, in case of using several components on one page

Also, you can customize some styles via CSS Variables:

VariableDefaultDescription
--su-size-text24pxFont size of text on element
--su-size-padding6pxPadding on element from progressbar
--su-color-bg#ebebebBackground color of element.
--su-color-progress-normal-bg#cacacaColor of progressbar
--su-color-progress-complete-bg#42b983Color of progressbar when slide is completed
--su-color-text-normal#4F4F4FColor of text on element
--su-color-text-complete#FEFEFEColor of text on element when slide is completed
--su-color-handler-bg#FFFFFFColor of handler
--su-icon-handlerbase64Icon of handler

Events

<template>
    <slide-unlock ... @completed="alert('Unlocked!')" />
</template>

Emitted when pass verify, the handler swiped to the right side.

Reset state

If you want to reset the state of a component, you need to assign a ref to the component

<template>
    <slide-unlock ref="vueSlideUnlockRef" />
</template>

And then you need to call the "reset" method

const vueSlideUnlockRef = ref()

const resetComponent = () => {
    vueSlideUnlockRef.value.reset()
}

Completed state

If you want to get the сompleted state of a component, you need to call the "complete" method

const unlockComponent = () => {
    vueSlideUnlockRef.value.complete()
}

Licensing

MIT License

0.5.7

1 month ago

0.5.6

2 months ago

0.5.5

2 months ago

0.5.4

2 months ago

0.5.3

2 months ago

0.5.2

2 months ago

0.5.1

3 months ago

0.5.0

3 months ago