show password icon in custom input

This commit is contained in:
Alexandro Uc Santos
2025-05-06 20:03:08 -06:00
parent 4c8b0470d2
commit 4eac691907
2 changed files with 61 additions and 16 deletions

View File

@@ -180,6 +180,7 @@ td {
border: none; border: none;
padding: 10px 12px; padding: 10px 12px;
font-size: 1rem; font-size: 1rem;
width: 100%;
} }
.custom-input-light { .custom-input-light {

View File

@@ -1,4 +1,7 @@
<script setup> <script setup>
import { computed, ref } from 'vue'
const props = defineProps({ const props = defineProps({
field: { field: {
type: [String, Number, Date] type: [String, Number, Date]
@@ -47,6 +50,17 @@
defineEmits(['update:field']) defineEmits(['update:field'])
const showPassword = ref(false)
const computedType = computed(() => {
return props.type === 'password' && showPassword.value ? 'text' : props.type
})
const toggleVisibility = () => {
showPassword.value = !showPassword.value
}
</script> </script>
<template> <template>
@@ -69,28 +83,48 @@
</div> </div>
</div> </div>
</div> </div>
<input <div class="input-container">
class="custom-input" <input
:class="[ class="custom-input"
!filled ? 'custom-input-light' : '', :class="[
// label.includes('*') ? 'border-required' : '' !filled ? 'custom-input-light' : '',
]" // label.includes('*') ? 'border-required' : ''
:type="type" ]"
:id="name" :type="computedType"
:name="name" :id="name"
:min="0" :name="name"
:step="step" :min="0"
:value="field" :step="step"
:disabled="readonly" :value="field"
:readonly="readonly" :disabled="readonly"
:required="required" :readonly="readonly"
@input="$event => $emit('update:field', $event.target.value)"> :required="required"
:autocomplete="type === 'password' ? 'off' : 'on'"
@input="$event => $emit('update:field', $event.target.value)"/>
<span
v-if="props.type === 'password'"
class="toggle-icon"
@click="toggleVisibility">
<i
class="fa-solid fa-eye"
v-if="!showPassword"
></i>
<i
class="fa-solid fa-eye-slash"
v-else
></i>
</span>
</div>
<span class="help" v-if="helpText.length > 0">{{ helpText }}</span> <span class="help" v-if="helpText.length > 0">{{ helpText }}</span>
<span class="error-msg" v-if="error">{{ error }}</span> <span class="error-msg" v-if="error">{{ error }}</span>
</div> </div>
</template> </template>
<style scoped> <style scoped>
.input-container {
position: relative;
width: 100%;
}
.help { .help {
font-size: 12px; font-size: 12px;
font-weight: 300; font-weight: 300;
@@ -110,6 +144,16 @@
align-items: center; align-items: center;
} }
.toggle-icon {
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
user-select: none;
font-size: 18px;
}
.label-text { .label-text {
flex: 1; flex: 1;
} }