14ee8d290SYoshie Muranaka<template> 24ee8d290SYoshie Muranaka <div class="input-password-toggle-container"> 34ee8d290SYoshie Muranaka <slot></slot> 44ee8d290SYoshie Muranaka <b-button 530f11f81SDixsie Wolmers :title="togglePasswordLabel" 64ee8d290SYoshie Muranaka variant="link" 730f11f81SDixsie Wolmers class="input-action-btn btn-icon-only" 84ee8d290SYoshie Muranaka :class="{ isVisible: isVisible }" 94ee8d290SYoshie Muranaka @click="toggleVisibility" 104ee8d290SYoshie Muranaka > 1130f11f81SDixsie Wolmers <icon-view-off v-if="isVisible" /> 1230f11f81SDixsie Wolmers <icon-view v-else /> 136e2cb978SSurenNeware <span class="sr-only">{{ togglePasswordLabel }}</span> 144ee8d290SYoshie Muranaka </b-button> 154ee8d290SYoshie Muranaka </div> 164ee8d290SYoshie Muranaka</template> 174ee8d290SYoshie Muranaka 184ee8d290SYoshie Muranaka<script> 194ee8d290SYoshie Muranakaimport IconView from '@carbon/icons-vue/es/view/20'; 204ee8d290SYoshie Muranakaimport IconViewOff from '@carbon/icons-vue/es/view--off/20'; 21*883a0d59SEd Tanousimport i18n from '@/i18n'; 224ee8d290SYoshie Muranaka 234ee8d290SYoshie Muranakaexport default { 244ee8d290SYoshie Muranaka name: 'InputPasswordToggle', 254ee8d290SYoshie Muranaka components: { IconView, IconViewOff }, 264ee8d290SYoshie Muranaka data() { 274ee8d290SYoshie Muranaka return { 28602e98aaSDerick Montague isVisible: false, 29*883a0d59SEd Tanous togglePasswordLabel: i18n.global.t('global.ariaLabel.showPassword'), 304ee8d290SYoshie Muranaka }; 314ee8d290SYoshie Muranaka }, 324ee8d290SYoshie Muranaka methods: { 334ee8d290SYoshie Muranaka toggleVisibility() { 344ee8d290SYoshie Muranaka const firstChild = this.$children[0]; 354ee8d290SYoshie Muranaka const inputEl = firstChild ? firstChild.$el : null; 364ee8d290SYoshie Muranaka 374ee8d290SYoshie Muranaka this.isVisible = !this.isVisible; 384ee8d290SYoshie Muranaka 39e881499eSSukanya Pandey if (inputEl && inputEl.nodeName === 'INPUT') { 404ee8d290SYoshie Muranaka inputEl.type = this.isVisible ? 'text' : 'password'; 414ee8d290SYoshie Muranaka } 4230f11f81SDixsie Wolmers 4330f11f81SDixsie Wolmers this.isVisible 44*883a0d59SEd Tanous ? (this.togglePasswordLabel = i18n.global.t( 45*883a0d59SEd Tanous 'global.ariaLabel.hidePassword', 46*883a0d59SEd Tanous )) 47*883a0d59SEd Tanous : (this.togglePasswordLabel = i18n.global.t( 48*883a0d59SEd Tanous 'global.ariaLabel.showPassword', 49*883a0d59SEd Tanous )); 50602e98aaSDerick Montague }, 51602e98aaSDerick Montague }, 524ee8d290SYoshie Muranaka}; 534ee8d290SYoshie Muranaka</script> 544ee8d290SYoshie Muranaka 554ee8d290SYoshie Muranaka<style lang="scss" scoped> 564ee8d290SYoshie Muranaka.input-password-toggle-container { 574ee8d290SYoshie Muranaka position: relative; 584ee8d290SYoshie Muranaka} 594ee8d290SYoshie Muranaka</style> 60