2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-27 10:51:33 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-14 14:57:21 +00:00
|
|
|
<template>
|
|
|
|
<div class="input-wrap">
|
2019-01-02 13:20:51 +00:00
|
|
|
<div class="label-container">
|
2019-10-23 13:26:39 +01:00
|
|
|
<ErrorIcon v-if="error"/>
|
2020-05-29 16:36:59 +01:00
|
|
|
<p class="label-container__label" v-if="isLabelShown" :style="style.labelStyle">{{label}}</p>
|
|
|
|
<p class="label-container__error" v-if="error" :style="style.errorStyle">{{error}}</p>
|
2019-07-09 16:04:51 +01:00
|
|
|
</div>
|
2018-12-18 14:43:23 +00:00
|
|
|
<input
|
2019-09-26 14:36:12 +01:00
|
|
|
class="headerless-input"
|
2019-09-20 11:13:22 +01:00
|
|
|
:class="{'inputError' : error, 'password': isPassword}"
|
2018-12-18 14:43:23 +00:00
|
|
|
@input="onInput"
|
2019-07-19 14:32:01 +01:00
|
|
|
@change="onInput"
|
2018-12-18 14:43:23 +00:00
|
|
|
v-model="value"
|
2019-07-19 14:32:01 +01:00
|
|
|
:placeholder="placeholder"
|
|
|
|
:type="type"
|
2019-10-02 10:42:12 +01:00
|
|
|
:style="style.inputStyle"
|
2019-11-29 12:52:21 +00:00
|
|
|
@focus="showPasswordStrength"
|
|
|
|
@blur="hidePasswordStrength"
|
2021-02-08 14:38:01 +00:00
|
|
|
@click="showOptions"
|
|
|
|
:optionsShown="optionsShown"
|
|
|
|
@optionsList="optionsList"
|
2019-10-02 10:42:12 +01:00
|
|
|
/>
|
2021-02-08 14:38:01 +00:00
|
|
|
|
|
|
|
<!-- Shown if there are input choice options -->
|
|
|
|
<InputCaret v-if="optionsList.length > 0" class="headerless-input__caret" />
|
|
|
|
<ul v-click-outside="hideOptions" class="headerless-input__options-wrapper" v-if="optionsShown">
|
|
|
|
<li
|
|
|
|
class="headerless-input__option"
|
|
|
|
@click="chooseOption(option)"
|
|
|
|
v-for="(option, index) in optionsList"
|
|
|
|
:key="index"
|
|
|
|
>
|
|
|
|
{{option}}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<!-- end of option render logic-->
|
|
|
|
|
2018-11-14 14:57:21 +00:00
|
|
|
<!--2 conditions of eye image (crossed or not) -->
|
2019-10-23 13:26:39 +01:00
|
|
|
<PasswordHiddenIcon
|
|
|
|
class="input-wrap__image"
|
|
|
|
v-if="isPasswordHiddenState"
|
|
|
|
@click="changeVision"
|
|
|
|
/>
|
|
|
|
<PasswordShownIcon
|
|
|
|
class="input-wrap__image"
|
|
|
|
v-if="isPasswordShownState"
|
|
|
|
@click="changeVision"
|
|
|
|
/>
|
2018-11-14 14:57:21 +00:00
|
|
|
<!-- end of image-->
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-09-13 15:58:18 +01:00
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
2018-11-14 14:57:21 +00:00
|
|
|
|
2021-02-08 14:38:01 +00:00
|
|
|
import InputCaret from '@/../static/images/common/caret.svg';
|
2019-10-23 13:26:39 +01:00
|
|
|
import PasswordHiddenIcon from '@/../static/images/common/passwordHidden.svg';
|
|
|
|
import PasswordShownIcon from '@/../static/images/common/passwordShown.svg';
|
|
|
|
import ErrorIcon from '@/../static/images/register/ErrorInfo.svg';
|
|
|
|
|
2019-09-13 15:58:18 +01:00
|
|
|
// Custom input component for login page
|
2019-10-23 13:26:39 +01:00
|
|
|
@Component({
|
|
|
|
components: {
|
2021-02-08 14:38:01 +00:00
|
|
|
InputCaret,
|
2019-10-23 13:26:39 +01:00
|
|
|
ErrorIcon,
|
|
|
|
PasswordHiddenIcon,
|
|
|
|
PasswordShownIcon,
|
|
|
|
},
|
|
|
|
})
|
2019-09-13 15:58:18 +01:00
|
|
|
export default class HeaderlessInput extends Vue {
|
|
|
|
private readonly textType: string = 'text';
|
|
|
|
private readonly passwordType: string = 'password';
|
2019-07-19 14:32:01 +01:00
|
|
|
|
2019-09-13 15:58:18 +01:00
|
|
|
private type: string = this.textType;
|
2021-08-02 19:17:49 +01:00
|
|
|
private isPasswordShown = false;
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2021-08-02 19:17:49 +01:00
|
|
|
protected value = '';
|
2019-07-19 14:32:01 +01:00
|
|
|
|
2019-09-13 15:58:18 +01:00
|
|
|
@Prop({default: ''})
|
|
|
|
protected readonly label: string;
|
|
|
|
@Prop({default: 'default'})
|
|
|
|
protected readonly placeholder: string;
|
|
|
|
@Prop({default: false})
|
|
|
|
protected readonly isPassword: boolean;
|
|
|
|
@Prop({default: '48px'})
|
|
|
|
protected readonly height: string;
|
|
|
|
@Prop({default: '100%'})
|
|
|
|
protected readonly width: string;
|
|
|
|
@Prop({default: ''})
|
|
|
|
protected readonly error: string;
|
|
|
|
@Prop({default: Number.MAX_SAFE_INTEGER})
|
|
|
|
protected readonly maxSymbols: number;
|
2021-03-23 20:23:27 +00:00
|
|
|
@Prop({default: () => []})
|
|
|
|
protected readonly optionsList: string[];
|
2021-02-08 14:38:01 +00:00
|
|
|
@Prop({default: false})
|
|
|
|
protected optionsShown: boolean;
|
|
|
|
@Prop({default: false})
|
|
|
|
protected inputClicked: boolean;
|
2019-07-19 14:32:01 +01:00
|
|
|
|
2019-09-13 15:58:18 +01:00
|
|
|
@Prop({default: false})
|
|
|
|
private readonly isWhite: boolean;
|
2021-02-24 22:35:24 +00:00
|
|
|
@Prop({default: false})
|
|
|
|
private readonly withIcon: boolean;
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2019-09-13 15:58:18 +01:00
|
|
|
public constructor() {
|
|
|
|
super();
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2019-09-13 15:58:18 +01:00
|
|
|
this.type = this.isPassword ? this.passwordType : this.textType;
|
|
|
|
}
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* Used to set default value from parent component.
|
|
|
|
* @param value
|
|
|
|
*/
|
2019-09-13 15:58:18 +01:00
|
|
|
public setValue(value: string): void {
|
|
|
|
this.value = value;
|
|
|
|
}
|
2019-07-19 14:32:01 +01:00
|
|
|
|
2019-11-29 12:52:21 +00:00
|
|
|
public showPasswordStrength(): void {
|
|
|
|
this.$emit('showPasswordStrength');
|
|
|
|
}
|
|
|
|
|
|
|
|
public hidePasswordStrength(): void {
|
|
|
|
this.$emit('hidePasswordStrength');
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* triggers on input.
|
|
|
|
*/
|
2019-09-13 15:58:18 +01:00
|
|
|
public onInput({ target }): void {
|
|
|
|
if (target.value.length > this.maxSymbols) {
|
|
|
|
this.value = target.value.slice(0, this.maxSymbols);
|
|
|
|
} else {
|
|
|
|
this.value = target.value;
|
2019-07-19 14:32:01 +01:00
|
|
|
}
|
|
|
|
|
2019-09-13 15:58:18 +01:00
|
|
|
this.$emit('setData', this.value);
|
|
|
|
}
|
2019-07-19 14:32:01 +01:00
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* Triggers input type between text and password to show/hide symbols.
|
|
|
|
*/
|
2019-09-20 11:13:22 +01:00
|
|
|
public changeVision(): void {
|
2019-09-13 15:58:18 +01:00
|
|
|
this.isPasswordShown = !this.isPasswordShown;
|
2020-02-14 15:35:10 +00:00
|
|
|
this.type = this.isPasswordShown ? this.textType : this.passwordType;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-09-13 15:58:18 +01:00
|
|
|
|
2021-02-08 14:38:01 +00:00
|
|
|
/**
|
|
|
|
* Chose a dropdown option as the input value.
|
|
|
|
*/
|
|
|
|
public chooseOption(option: string): void {
|
|
|
|
this.value = option;
|
|
|
|
this.$emit('setData', this.value);
|
|
|
|
this.optionsShown = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show dropdown options when the input is clicked, if they exist.
|
|
|
|
*/
|
|
|
|
public showOptions(): void {
|
|
|
|
if (this.optionsList.length > 0) {
|
|
|
|
this.optionsShown = true;
|
|
|
|
this.inputClicked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the dropdown options from view when there is a click outside of the dropdown.
|
|
|
|
*/
|
|
|
|
public hideOptions(): void {
|
|
|
|
if (this.optionsList.length > 0 && !this.inputClicked && this.optionsShown) {
|
|
|
|
this.optionsShown = false;
|
|
|
|
this.inputClicked = false;
|
|
|
|
}
|
|
|
|
this.inputClicked = false;
|
|
|
|
}
|
|
|
|
|
2019-10-02 10:42:12 +01:00
|
|
|
public get isLabelShown(): boolean {
|
|
|
|
return !!(!this.error && this.label);
|
|
|
|
}
|
|
|
|
|
|
|
|
public get isPasswordHiddenState(): boolean {
|
|
|
|
return this.isPassword && !this.isPasswordShown;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get isPasswordShownState(): boolean {
|
|
|
|
return this.isPassword && this.isPasswordShown;
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* Returns style objects depends on props.
|
|
|
|
*/
|
2021-08-02 19:17:49 +01:00
|
|
|
protected get style(): Record<string, unknown> {
|
2019-09-13 15:58:18 +01:00
|
|
|
return {
|
|
|
|
inputStyle: {
|
|
|
|
width: this.width,
|
|
|
|
height: this.height,
|
2021-04-14 21:28:48 +01:00
|
|
|
padding: this.withIcon ? '0 30px 0 50px' : '',
|
2019-09-13 15:58:18 +01:00
|
|
|
},
|
|
|
|
labelStyle: {
|
|
|
|
color: this.isWhite ? 'white' : '#354049',
|
|
|
|
},
|
|
|
|
errorStyle: {
|
|
|
|
color: this.isWhite ? 'white' : '#FF5560',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2018-11-14 14:57:21 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2019-09-26 14:36:12 +01:00
|
|
|
.input-wrap {
|
|
|
|
position: relative;
|
|
|
|
width: 100%;
|
2019-10-28 15:59:19 +00:00
|
|
|
font-family: 'font_regular', sans-serif;
|
2019-10-02 10:42:12 +01:00
|
|
|
|
2019-09-26 14:36:12 +01:00
|
|
|
&__image {
|
|
|
|
position: absolute;
|
|
|
|
right: 25px;
|
|
|
|
bottom: 5px;
|
|
|
|
transform: translateY(-50%);
|
|
|
|
z-index: 20;
|
|
|
|
cursor: pointer;
|
2019-10-02 10:42:12 +01:00
|
|
|
|
2019-09-26 14:36:12 +01:00
|
|
|
&:hover .input-wrap__image__path {
|
2019-10-28 15:59:19 +00:00
|
|
|
fill: #2683ff !important;
|
2019-09-26 14:36:12 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-08 14:38:01 +00:00
|
|
|
|
|
|
|
.headerless-input {
|
|
|
|
font-size: 16px;
|
|
|
|
line-height: 21px;
|
|
|
|
resize: none;
|
|
|
|
height: 46px;
|
|
|
|
padding: 0 30px 0 0;
|
|
|
|
text-indent: 20px;
|
|
|
|
border: 1px solid rgba(56, 75, 101, 0.4);
|
|
|
|
border-radius: 6px;
|
2021-02-24 22:35:24 +00:00
|
|
|
-webkit-box-sizing: border-box;
|
|
|
|
-moz-box-sizing: border-box;
|
|
|
|
box-sizing: border-box;
|
2021-02-08 14:38:01 +00:00
|
|
|
|
|
|
|
&__caret {
|
|
|
|
position: absolute;
|
|
|
|
right: 28px;
|
|
|
|
bottom: 18px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&__options-wrapper {
|
|
|
|
border: 1px solid rgba(56, 75, 101, 0.4);
|
|
|
|
position: absolute;
|
2021-04-27 19:40:03 +01:00
|
|
|
width: calc(100% - 5px);
|
|
|
|
top: 70px;
|
2021-02-08 14:38:01 +00:00
|
|
|
padding: 0;
|
|
|
|
background: #fff;
|
|
|
|
z-index: 21;
|
2021-06-22 11:16:06 +01:00
|
|
|
border-radius: 0 0 6px 6px;
|
2021-02-08 14:38:01 +00:00
|
|
|
list-style: none;
|
|
|
|
border-top: none;
|
|
|
|
height: 176px;
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
&__option {
|
|
|
|
cursor: pointer;
|
|
|
|
padding: 20px 22px;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: #2582ff;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.headerless-input::placeholder {
|
|
|
|
color: #384b65;
|
|
|
|
opacity: 0.4;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:focus-within {
|
|
|
|
|
|
|
|
.headerless-input {
|
|
|
|
position: relative;
|
|
|
|
z-index: 22;
|
|
|
|
|
|
|
|
&__options-wrapper {
|
|
|
|
border-top: 3px solid #145ecc;
|
|
|
|
}
|
|
|
|
|
|
|
|
&__caret {
|
|
|
|
z-index: 23;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-02 13:20:51 +00:00
|
|
|
}
|
2019-09-26 14:36:12 +01:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
.label-container {
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: flex-end;
|
|
|
|
padding-bottom: 8px;
|
|
|
|
flex-direction: row;
|
2019-09-26 14:36:12 +01:00
|
|
|
|
|
|
|
&__label {
|
|
|
|
font-size: 16px;
|
|
|
|
line-height: 21px;
|
|
|
|
color: #354049;
|
2019-07-10 10:55:40 +01:00
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
2019-09-26 14:36:12 +01:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__add-label {
|
|
|
|
margin-left: 5px;
|
|
|
|
font-size: 16px;
|
|
|
|
line-height: 21px;
|
|
|
|
color: rgba(56, 75, 101, 0.4);
|
|
|
|
}
|
2019-09-26 14:36:12 +01:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__error {
|
2019-09-26 14:36:12 +01:00
|
|
|
font-size: 16px;
|
|
|
|
margin: 18px 0 0 10px;
|
2019-07-10 10:55:40 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-26 14:36:12 +01:00
|
|
|
|
|
|
|
.inputError::placeholder {
|
2019-10-28 15:59:19 +00:00
|
|
|
color: #eb5757;
|
2019-09-26 14:36:12 +01:00
|
|
|
opacity: 0.4;
|
|
|
|
}
|
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
.error {
|
2019-10-28 15:59:19 +00:00
|
|
|
color: #ff5560;
|
2019-01-02 13:20:51 +00:00
|
|
|
margin-left: 10px;
|
|
|
|
}
|
2019-09-20 11:13:22 +01:00
|
|
|
|
|
|
|
.password {
|
|
|
|
padding-right: 75px;
|
|
|
|
}
|
2018-11-14 14:57:21 +00:00
|
|
|
</style>
|