added toggle functionality for password field through icon

This commit is contained in:
Brandon Tripp 2020-11-10 15:31:18 -07:00
parent 0237ceb57e
commit 07da166cd4
4 changed files with 90 additions and 56 deletions

View File

@ -12,7 +12,7 @@
</template> </template>
<h2 class="title">{{ $t('login.login') }}</h2> <h2 class="title">{{ $t('login.login') }}</h2>
<form :disabled="pending" @submit.prevent="onSubmit"> <form :disabled="pending" @submit.prevent="onSubmit">
<ds-input <base-input
v-model="form.email" v-model="form.email"
:disabled="pending" :disabled="pending"
:placeholder="$t('login.email')" :placeholder="$t('login.email')"
@ -25,7 +25,7 @@
:disabled="pending" :disabled="pending"
:placeholder="$t('login.password')" :placeholder="$t('login.password')"
icon="lock" icon="lock"
icon-right="eye" icon-right="lock"
icon-right-secondary="eye" icon-right-secondary="eye"
name="password" name="password"
type="password" type="password"

View File

@ -39,6 +39,8 @@ export default {
display: inline-flex; display: inline-flex;
vertical-align: bottom; vertical-align: bottom;
> .svg { > .svg {
height: 1.2em; height: 1.2em;
fill: currentColor; fill: currentColor;

View File

@ -11,7 +11,8 @@
]" ]"
:id="id" :id="id"
:name="name ? name : model" :name="name ? name : model"
:type="type" :type="[showPassword ? 'text' : 'password']"
:v-model="type"
:autofocus="autofocus" :autofocus="autofocus"
:placeholder="placeholder" :placeholder="placeholder"
:tabindex="tabindex" :tabindex="tabindex"
@ -21,35 +22,52 @@
@input="handleInput" @input="handleInput"
@focus="handleFocus" @focus="handleFocus"
@blur="handleBlur" @blur="handleBlur"
:rows="type === 'textarea' ? rows : null"
v-html="type === 'textarea'"
/> />
<base-icon <base-icon
class="input-icon-right" class="input-icon-right"
v-if="iconRight" v-if="[iconRight && capsLock]"
:name="iconRight" /> :name="iconRight" />
<base-icon <a
class="input-icon-right" class="click-wrapper"
v-if="iconRightSecondary" @click="showPassword = !showPassword"
:name="iconRightSecondary" /> >
<base-icon
class="toggle-icon"
icon="[showPassword ? iconRightSecondary : eye-slash]"
v-if="iconRightSecondary"
:name="iconRightSecondary"
/>
</a>
</div> </div>
</template> </template>
<script> <script>
import BaseButton from '../BaseButton/BaseButton'
import BaseIcon from '../BaseIcon/BaseIcon' import BaseIcon from '../BaseIcon/BaseIcon'
import IconButton from '../IconButton/IconButton'
import inputMixin from '~/mixins/tempMixins-styleguide/input' import inputMixin from '~/mixins/tempMixins-styleguide/input'
export default { export default {
components: { components: {
BaseIcon, BaseIcon,
BaseButton,
IconButton
},
data: function() {
return {
showPassword: false,
capsLock: false
}
}, },
mixins: [inputMixin], mixins: [inputMixin],
props: { props: {
type: { type: {
type: String, type: String,
default: 'text', default: 'text',
// validator - check if there is existing value helper validator: value => {
return value.match(/(url|text|password|email|search|textarea)/)
}
}, },
placeholder: { placeholder: {
type: String, type: String,
@ -63,10 +81,6 @@ export default {
type: String, type: String,
default: null default: null
}, },
rows: {
type: [String, Number],
default: 1
},
iconRight: { iconRight: {
type: String, type: String,
default: null default: null
@ -76,14 +90,11 @@ export default {
default: null default: null
} }
}, },
computed: { // computed: {
tag() { // togglePassword(event) {
if (this.type === 'textarea') { // this.type = this.type === 'password' ? 'text' : 'password'
return 'textarea' // }
} // }
return 'input'
}
}
} }
</script> </script>
@ -117,7 +128,7 @@ export default {
.base-input { .base-input {
border: none; border: none;
width: 76%; width: 60%;
background-color: $background-color-disabled; background-color: $background-color-disabled;
font-size: $input-font-size-base; font-size: $input-font-size-base;
line-height: $line-height-base; line-height: $line-height-base;
@ -136,9 +147,6 @@ export default {
border: $input-border-size solid $border-color-active; border: $input-border-size solid $border-color-active;
} }
} }
/* .input-is-disabled &, */
} }
} }
@ -148,45 +156,36 @@ export default {
outline-width: 0; outline-width: 0;
} }
.input-icon, .input-icon {
.input-icon-right {
top: 0;
bottom: 0;
left: 0;
/* width: 10%; */
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: $input-height; width: $input-height;
color: $text-color-softer; color: $text-color-softer;
transition: color $duration-short $ease-out; transition: color $duration-short $ease-out;
pointer-events: none; pointer-events: none;
.input-has-focus & {
color: $text-color-base;
}
} }
/* .input-has-icon-right { .input-icon-right,
padding-right: $input-height; .icon-button {
align-items: center;
.input-size-small & { justify-content: center;
padding-right: $input-height-small; width: $input-height;
} color: $text-color-softer;
transition: color $duration-short $ease-out;
.input-size-large & { pointer-events: none;
padding-right: $input-height-large; }
} .input-icon-right-secondary {
pointer-events: all;
}
.toggle-icon {
color: $text-color-disabled;
background-color: $background-color-disabled;
width: 100%;
height: 100%;
} }
.input-has-icon-right-secondary {
padding-right: $input-height;
.input-size-small & {
padding-right: $input-height-small;
}
.input-size-large & {
padding-right: $input-height-large;
}
} */
</style> </style>

View File

@ -0,0 +1,33 @@
<template>
<button
class="icon-button"
@click.prevent="clickFunction"
>
<base-icon :name="icon" />
<slot />
</button>
</template>
<script>
import BaseIcon from '../BaseIcon/BaseIcon'
export default {
components: {
BaseIcon
},
props: {
icon: {
type: String,
},
}
}
</script>
<style>
.icon-button {
background-color: red;
}
</style>