2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-02-11 23:48:21 +00:00
|
|
|
<div :class="cx('root')" :style="sx('root')" v-bind="ptmi('root')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<PInputText
|
|
|
|
ref="input"
|
|
|
|
:id="inputId"
|
|
|
|
:type="inputType"
|
2023-05-25 08:53:29 +00:00
|
|
|
:class="[cx('input'), inputClass]"
|
2022-09-14 11:26:01 +00:00
|
|
|
:style="inputStyle"
|
|
|
|
:value="modelValue"
|
|
|
|
:aria-labelledby="ariaLabelledby"
|
|
|
|
:aria-label="ariaLabel"
|
|
|
|
:aria-controls="(panelProps && panelProps.id) || panelId || panelUniqueId"
|
|
|
|
:aria-expanded="overlayVisible"
|
|
|
|
:aria-haspopup="true"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
:required="required"
|
2023-08-12 21:43:27 +00:00
|
|
|
:disabled="disabled"
|
2024-02-02 11:46:26 +00:00
|
|
|
:variant="variant"
|
|
|
|
:invalid="invalid"
|
2022-09-14 11:26:01 +00:00
|
|
|
@input="onInput"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
@keyup="onKeyUp"
|
|
|
|
@invalid="onInvalid"
|
2023-12-04 08:42:33 +00:00
|
|
|
v-bind="inputProps"
|
|
|
|
:pt="ptm('input')"
|
2023-06-12 07:11:42 +00:00
|
|
|
:unstyled="unstyled"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
2023-10-31 17:21:47 +00:00
|
|
|
<slot v-if="toggleMask && unmasked" name="hideicon" :onClick="onMaskToggle" :toggleCallback="onMaskToggle">
|
2024-02-14 07:34:27 +00:00
|
|
|
<component :is="hideIcon ? 'i' : 'EyeSlashIcon'" :class="[cx('hideIcon'), hideIcon]" @click="onMaskToggle" v-bind="ptm('hideIcon')" />
|
2023-04-04 12:41:34 +00:00
|
|
|
</slot>
|
2023-10-31 17:21:47 +00:00
|
|
|
<slot v-if="toggleMask && !unmasked" name="showicon" :onClick="onMaskToggle" :toggleCallback="onMaskToggle">
|
2024-02-14 07:34:27 +00:00
|
|
|
<component :is="showIcon ? 'i' : 'EyeIcon'" :class="[cx('showIcon'), showIcon]" @click="onMaskToggle" v-bind="ptm('showIcon')" />
|
2023-04-04 12:41:34 +00:00
|
|
|
</slot>
|
2023-07-03 22:20:35 +00:00
|
|
|
<span class="p-hidden-accessible" aria-live="polite" v-bind="ptm('hiddenAccesible')" :data-p-hidden-accessible="true">
|
2022-09-14 11:26:01 +00:00
|
|
|
{{ infoText }}
|
2022-09-06 12:03:37 +00:00
|
|
|
</span>
|
|
|
|
<Portal :appendTo="appendTo">
|
2023-08-02 12:02:16 +00:00
|
|
|
<transition name="p-connected-overlay" @enter="onOverlayEnter" @leave="onOverlayLeave" @after-leave="onOverlayAfterLeave" v-bind="ptm('transition')">
|
2023-05-25 08:53:29 +00:00
|
|
|
<div v-if="overlayVisible" :ref="overlayRef" :id="panelId || panelUniqueId" :class="[cx('panel'), panelClass]" :style="panelStyle" @click="onOverlayClick" v-bind="{ ...panelProps, ...ptm('panel') }">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="header"></slot>
|
|
|
|
<slot name="content">
|
2023-05-25 08:53:29 +00:00
|
|
|
<div :class="cx('meter')" v-bind="ptm('meter')">
|
|
|
|
<div :class="cx('meterLabel')" :style="{ width: meter ? meter.width : '' }" v-bind="ptm('meterLabel')"></div>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-05-25 08:53:29 +00:00
|
|
|
<div :class="cx('info')" v-bind="ptm('info')">{{ infoText }}</div>
|
2022-09-06 12:03:37 +00:00
|
|
|
</slot>
|
|
|
|
<slot name="footer"></slot>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</Portal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-18 12:53:43 +00:00
|
|
|
import EyeIcon from 'primevue/icons/eye';
|
|
|
|
import EyeSlashIcon from 'primevue/icons/eyeslash';
|
2022-09-06 12:03:37 +00:00
|
|
|
import InputText from 'primevue/inputtext';
|
2022-09-14 11:26:01 +00:00
|
|
|
import OverlayEventBus from 'primevue/overlayeventbus';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Portal from 'primevue/portal';
|
2022-09-14 11:26:01 +00:00
|
|
|
import { ConnectedOverlayScrollHandler, DomHandler, UniqueComponentId, ZIndexUtils } from 'primevue/utils';
|
2023-05-25 08:53:29 +00:00
|
|
|
import BasePassword from './BasePassword.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Password',
|
2023-05-25 08:53:29 +00:00
|
|
|
extends: BasePassword,
|
2024-02-11 23:48:21 +00:00
|
|
|
inheritAttrs: false,
|
2022-09-14 11:26:01 +00:00
|
|
|
emits: ['update:modelValue', 'change', 'focus', 'blur', 'invalid'],
|
2022-09-06 12:03:37 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2024-02-02 15:47:44 +00:00
|
|
|
id: this.$attrs.id,
|
2022-09-06 12:03:37 +00:00
|
|
|
overlayVisible: false,
|
|
|
|
meter: null,
|
|
|
|
infoText: null,
|
|
|
|
focused: false,
|
|
|
|
unmasked: false
|
|
|
|
};
|
|
|
|
},
|
2024-02-02 15:47:44 +00:00
|
|
|
watch: {
|
|
|
|
'$attrs.id': function (newValue) {
|
|
|
|
this.id = newValue || UniqueComponentId();
|
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
mediumCheckRegExp: null,
|
|
|
|
strongCheckRegExp: null,
|
|
|
|
resizeListener: null,
|
|
|
|
scrollHandler: null,
|
|
|
|
overlay: null,
|
|
|
|
mounted() {
|
2024-02-02 15:47:44 +00:00
|
|
|
this.id = this.id || UniqueComponentId();
|
2022-09-06 12:03:37 +00:00
|
|
|
this.infoText = this.promptText;
|
|
|
|
this.mediumCheckRegExp = new RegExp(this.mediumRegex);
|
|
|
|
this.strongCheckRegExp = new RegExp(this.strongRegex);
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
this.unbindResizeListener();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.scrollHandler) {
|
|
|
|
this.scrollHandler.destroy();
|
|
|
|
this.scrollHandler = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.overlay) {
|
|
|
|
ZIndexUtils.clear(this.overlay);
|
|
|
|
this.overlay = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onOverlayEnter(el) {
|
|
|
|
ZIndexUtils.set('overlay', el, this.$primevue.config.zIndex.overlay);
|
2023-05-25 08:53:29 +00:00
|
|
|
|
|
|
|
DomHandler.addStyles(el, { position: 'absolute', top: '0', left: '0' });
|
2022-09-06 12:03:37 +00:00
|
|
|
this.alignOverlay();
|
|
|
|
this.bindScrollListener();
|
|
|
|
this.bindResizeListener();
|
|
|
|
},
|
|
|
|
onOverlayLeave() {
|
|
|
|
this.unbindScrollListener();
|
|
|
|
this.unbindResizeListener();
|
|
|
|
this.overlay = null;
|
|
|
|
},
|
|
|
|
onOverlayAfterLeave(el) {
|
|
|
|
ZIndexUtils.clear(el);
|
|
|
|
},
|
|
|
|
alignOverlay() {
|
|
|
|
if (this.appendTo === 'self') {
|
|
|
|
DomHandler.relativePosition(this.overlay, this.$refs.input.$el);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.overlay.style.minWidth = DomHandler.getOuterWidth(this.$refs.input.$el) + 'px';
|
|
|
|
DomHandler.absolutePosition(this.overlay, this.$refs.input.$el);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
testStrength(str) {
|
|
|
|
let level = 0;
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.strongCheckRegExp.test(str)) level = 3;
|
|
|
|
else if (this.mediumCheckRegExp.test(str)) level = 2;
|
|
|
|
else if (str.length) level = 1;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
return level;
|
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
onInput(event) {
|
|
|
|
this.$emit('update:modelValue', event.target.value);
|
2023-08-02 09:27:43 +00:00
|
|
|
this.$emit('change', event);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onFocus(event) {
|
|
|
|
this.focused = true;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.feedback) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.setPasswordMeter(this.modelValue);
|
2022-09-06 12:03:37 +00:00
|
|
|
this.overlayVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('focus', event);
|
|
|
|
},
|
|
|
|
onBlur(event) {
|
|
|
|
this.focused = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.feedback) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('blur', event);
|
|
|
|
},
|
|
|
|
onKeyUp(event) {
|
|
|
|
if (this.feedback) {
|
|
|
|
const value = event.target.value;
|
2022-09-14 11:26:01 +00:00
|
|
|
const { meter, label } = this.checkPasswordStrength(value);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.meter = meter;
|
|
|
|
this.infoText = label;
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (event.code === 'Escape') {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.overlayVisible && (this.overlayVisible = false);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.overlayVisible) {
|
|
|
|
this.overlayVisible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
setPasswordMeter() {
|
|
|
|
if (!this.modelValue) return;
|
|
|
|
|
|
|
|
const { meter, label } = this.checkPasswordStrength(this.modelValue);
|
|
|
|
|
|
|
|
this.meter = meter;
|
|
|
|
this.infoText = label;
|
|
|
|
|
|
|
|
if (!this.overlayVisible) {
|
|
|
|
this.overlayVisible = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
checkPasswordStrength(value) {
|
|
|
|
let label = null;
|
|
|
|
let meter = null;
|
|
|
|
|
|
|
|
switch (this.testStrength(value)) {
|
|
|
|
case 1:
|
|
|
|
label = this.weakText;
|
|
|
|
meter = {
|
|
|
|
strength: 'weak',
|
|
|
|
width: '33.33%'
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
label = this.mediumText;
|
|
|
|
meter = {
|
|
|
|
strength: 'medium',
|
|
|
|
width: '66.66%'
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
label = this.strongText;
|
|
|
|
meter = {
|
|
|
|
strength: 'strong',
|
|
|
|
width: '100%'
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
label = this.promptText;
|
|
|
|
meter = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { label, meter };
|
|
|
|
},
|
|
|
|
onInvalid(event) {
|
|
|
|
this.$emit('invalid', event);
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
bindScrollListener() {
|
|
|
|
if (!this.scrollHandler) {
|
|
|
|
this.scrollHandler = new ConnectedOverlayScrollHandler(this.$refs.input.$el, () => {
|
|
|
|
if (this.overlayVisible) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.scrollHandler.bindScrollListener();
|
|
|
|
},
|
|
|
|
unbindScrollListener() {
|
|
|
|
if (this.scrollHandler) {
|
|
|
|
this.scrollHandler.unbindScrollListener();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
bindResizeListener() {
|
|
|
|
if (!this.resizeListener) {
|
|
|
|
this.resizeListener = () => {
|
|
|
|
if (this.overlayVisible && !DomHandler.isTouchDevice()) {
|
|
|
|
this.overlayVisible = false;
|
|
|
|
}
|
|
|
|
};
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
window.addEventListener('resize', this.resizeListener);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unbindResizeListener() {
|
|
|
|
if (this.resizeListener) {
|
|
|
|
window.removeEventListener('resize', this.resizeListener);
|
|
|
|
this.resizeListener = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
overlayRef(el) {
|
|
|
|
this.overlay = el;
|
|
|
|
},
|
|
|
|
onMaskToggle() {
|
|
|
|
this.unmasked = !this.unmasked;
|
|
|
|
},
|
|
|
|
onOverlayClick(event) {
|
|
|
|
OverlayEventBus.emit('overlay-click', {
|
|
|
|
originalEvent: event,
|
|
|
|
target: this.$el
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
inputType() {
|
|
|
|
return this.unmasked ? 'text' : 'password';
|
|
|
|
},
|
|
|
|
filled() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.modelValue != null && this.modelValue.toString().length > 0;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
weakText() {
|
|
|
|
return this.weakLabel || this.$primevue.config.locale.weak;
|
|
|
|
},
|
|
|
|
mediumText() {
|
|
|
|
return this.mediumLabel || this.$primevue.config.locale.medium;
|
|
|
|
},
|
|
|
|
strongText() {
|
|
|
|
return this.strongLabel || this.$primevue.config.locale.strong;
|
|
|
|
},
|
|
|
|
promptText() {
|
|
|
|
return this.promptLabel || this.$primevue.config.locale.passwordPrompt;
|
|
|
|
},
|
|
|
|
panelUniqueId() {
|
2024-02-02 15:47:44 +00:00
|
|
|
return this.id + '_panel';
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2022-09-14 11:26:01 +00:00
|
|
|
PInputText: InputText,
|
2023-04-04 12:41:34 +00:00
|
|
|
Portal: Portal,
|
|
|
|
EyeSlashIcon: EyeSlashIcon,
|
|
|
|
EyeIcon: EyeIcon
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|