uptime-kuma/src/components/HiddenInput.vue

88 lines
2.1 KiB
Vue
Raw Normal View History

2021-09-06 20:24:02 -04:00
<template>
<div class="input-group mb-3">
2021-09-07 04:46:42 -04:00
<input
ref="input"
2021-09-07 04:46:42 -04:00
v-model="model"
:type="visibility"
class="form-control"
:placeholder="placeholder"
:maxlength="maxlength"
:autocomplete="autocomplete"
:required="required"
:readonly="readonly"
2021-09-07 04:46:42 -04:00
>
2021-09-06 20:24:02 -04:00
<a v-if="visibility == 'password'" class="btn btn-outline-primary" @click="showInput()">
<font-awesome-icon icon="eye" />
</a>
<a v-if="visibility == 'text'" class="btn btn-outline-primary" @click="hideInput()">
<font-awesome-icon icon="eye-slash" />
</a>
</div>
</template>
<script>
export default {
props: {
/** The value of the input */
2021-09-06 20:24:02 -04:00
modelValue: {
type: String,
default: ""
},
/** A placeholder to use */
2021-09-06 20:24:02 -04:00
placeholder: {
type: String,
default: ""
},
/** Maximum length of the input */
2021-09-06 20:24:02 -04:00
maxlength: {
type: Number,
default: 255
},
/** Should the field auto complete */
2021-09-06 20:24:02 -04:00
autocomplete: {
type: String,
default: undefined,
2021-09-06 20:24:02 -04:00
},
/** Is the input required? */
2021-09-06 20:24:02 -04:00
required: {
type: Boolean
},
/** Should the input be read only? */
readonly: {
type: String,
default: undefined,
},
2021-09-06 20:24:02 -04:00
},
2022-04-17 03:27:35 -04:00
emits: [ "update:modelValue" ],
2021-09-06 20:24:02 -04:00
data() {
return {
visibility: "password",
2022-04-13 12:30:32 -04:00
};
2021-09-06 20:24:02 -04:00
},
computed: {
model: {
get() {
2022-04-13 12:30:32 -04:00
return this.modelValue;
2021-09-06 20:24:02 -04:00
},
set(value) {
2022-04-13 12:30:32 -04:00
this.$emit("update:modelValue", value);
2021-09-06 20:24:02 -04:00
}
}
},
created() {
2021-09-06 20:24:02 -04:00
},
methods: {
/** Show users input in plain text */
2021-09-06 20:24:02 -04:00
showInput() {
this.visibility = "text";
},
/** Censor users input */
2021-09-06 20:24:02 -04:00
hideInput() {
this.visibility = "password";
},
2021-09-06 20:24:02 -04:00
}
2022-04-13 12:30:32 -04:00
};
2021-09-06 20:24:02 -04:00
</script>