Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Allow the usage of built-in input to be optional #19

Merged
merged 2 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Interactive password strength meter based on [zxcvbn](https://github.com/dropbox
| strengthMeterClass | String | Password__strength-meter | strength-meter class |
| strengthMeterFillClass | String | Password__strength-meter--fill | strength-meter class for individual data fills |
| showStrengthMeter | Boolean | true | Hide the Strength Meter if you want to implement your own |
| strengthMeterOnly | Boolean | false | Hides the built-in input if you want to implement your own |

## Events

Expand Down
36 changes: 25 additions & 11 deletions src/components/PasswordStrengthMeter.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<template>
<div class="Password">
<div class="Password__group">
<div
v-if="!strengthMeterOnly"
class="Password__group"
>
<input
:type="inputType"
:ref="referanceValue"
v-bind:value="value"
v-on:input="emitValue($event.target.value)"
:class="[defaultClass, disabled ? disabledClass : '']"
:name="name"
:id="id"
:placeholder="placeholder"
:required="required"
:disabled="disabled"
v-bind:value="value"
@input="evt => emitValue(evt.target.value)"
>
<div class="Password__icons">
<div
Expand Down Expand Up @@ -156,6 +159,16 @@
type: Boolean,
default: true
},
/**
* Prop to toggle the
* input element if
* User wants to implement
* their own input element
*/
strengthMeterOnly: {
type: Boolean,
default: false
},
/**
* CSS Class for the Input field
* @type {String}
Expand Down Expand Up @@ -221,14 +234,6 @@
},

methods: {
/**
* Emit passowrd value to parent component
* @param {String} value password typed in
*/
emitValue (value) {
this.password = value
this.$emit('input', value)
},
togglePassword () {
if (this.$data._showPassword) {
this.$emit('hide')
Expand All @@ -237,6 +242,10 @@
this.$emit('show')
this.$data._showPassword = true
}
},
emitValue (value) {
this.$emit('input', value)
this.password = value
}
},

Expand Down Expand Up @@ -289,6 +298,11 @@
},

watch: {
value (newValue) {
if (this.strengthMeterOnly) {
this.emitValue(newValue)
}
},
passwordStrength (score) {
this.$emit('score', score)
this.$emit('feedback', zxcvbn(this.password).feedback)
Expand Down