UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue)

2 lines (1 loc) 6.4 kB
"use strict";var e=require("primevue/utils"),t=require("primevue/overlayeventbus"),n=require("primevue/inputtext"),s=require("vue");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=i(t),r={emits:["update:modelValue"],inheritAttrs:!1,props:{modelValue:String,promptLabel:{type:String,default:null},mediumRegex:{type:String,default:"^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"},strongRegex:{type:String,default:"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})"},weakLabel:{type:String,default:null},mediumLabel:{type:String,default:null},strongLabel:{type:String,default:null},feedback:{type:Boolean,default:!0},appendTo:{type:String,default:"body"},toggleMask:{type:Boolean,default:!1},inputClass:null,inputStyle:null,style:null,class:null},data:()=>({overlayVisible:!1,meter:null,infoText:null,focused:!1,unmasked:!1}),mediumCheckRegExp:null,strongCheckRegExp:null,resizeListener:null,scrollHandler:null,overlay:null,mounted(){this.infoText=this.promptText,this.mediumCheckRegExp=new RegExp(this.mediumRegex),this.strongCheckRegExp=new RegExp(this.strongRegex)},beforeUnmount(){this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null)},methods:{onOverlayEnter(){this.overlay.style.zIndex=String(e.DomHandler.generateZIndex()),this.alignOverlay(),this.bindScrollListener(),this.bindResizeListener()},onOverlayLeave(){this.unbindScrollListener(),this.unbindResizeListener(),this.overlay=null},alignOverlay(){this.overlay.style.minWidth=e.DomHandler.getOuterWidth(this.$refs.input.$el)+"px",e.DomHandler.absolutePosition(this.overlay,this.$refs.input.$el)},testStrength(e){let t=0;return this.strongCheckRegExp.test(e)?t=3:this.mediumCheckRegExp.test(e)?t=2:e.length&&(t=1),t},onInput(e){this.$emit("update:modelValue",e.target.value)},onFocus(){this.focused=!0,this.feedback&&(this.overlayVisible=!0)},onBlur(){this.focused=!1,this.feedback&&(this.overlayVisible=!1)},onKeyUp(e){if(this.feedback){let t=e.target.value,n=null,s=null;switch(this.testStrength(t)){case 1:n=this.weakText,s={strength:"weak",width:"33.33%"};break;case 2:n=this.mediumText,s={strength:"medium",width:"66.66%"};break;case 3:n=this.strongText,s={strength:"strong",width:"100%"};break;default:n=this.promptText,s=null}this.meter=s,this.infoText=n,this.overlayVisible||(this.overlayVisible=!0)}},bindScrollListener(){this.scrollHandler||(this.scrollHandler=new e.ConnectedOverlayScrollHandler(this.$refs.input.$el,(()=>{this.overlayVisible&&(this.overlayVisible=!1)}))),this.scrollHandler.bindScrollListener()},unbindScrollListener(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()},bindResizeListener(){this.resizeListener||(this.resizeListener=()=>{this.overlayVisible&&(this.overlayVisible=!1)},window.addEventListener("resize",this.resizeListener))},unbindResizeListener(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},overlayRef(e){this.overlay=e},onMaskToggle(){this.unmasked=!this.unmasked},onOverlayClick(e){l.default.emit("overlay-click",{originalEvent:e,target:this.$el})}},computed:{containerClass(){return["p-password p-component p-inputwrapper",this.class,{"p-inputwrapper-filled":this.filled,"p-inputwrapper-focus":this.focused,"p-input-icon-right":this.toggleMask}]},inputFieldClass(){return["p-password-input",this.inputClass,{"p-disabled":this.$attrs.disabled}]},toggleIconClass(){return this.unmasked?"pi pi-eye-slash":"pi pi-eye"},strengthClass(){return`p-password-strength ${this.meter?this.meter.strength:""}`},inputType(){return this.unmasked?"text":"password"},filled(){return null!=this.modelValue&&this.modelValue.toString().length>0},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}},components:{PInputText:i(n).default}};const o={class:"p-password-meter"},a={className:"p-password-info"};!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&s.firstChild?s.insertBefore(i,s.firstChild):s.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}("\n.p-password {\n position: relative;\n display: -webkit-inline-box;\n display: -ms-inline-flexbox;\n display: inline-flex;\n}\n.p-password-panel {\n position: absolute;\n}\n.p-password .p-password-panel {\n min-width: 100%;\n}\n.p-password-meter {\n height: 10px;\n}\n.p-password-strength {\n height: 100%;\n width: 0%;\n -webkit-transition: width 1s ease-in-out;\n transition: width 1s ease-in-out;\n}\n.p-fluid .p-password {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n}\n"),r.render=function(e,t,n,i,l,r){const d=s.resolveComponent("PInputText");return s.openBlock(),s.createBlock("div",{class:r.containerClass,style:n.style},[s.createVNode(d,s.mergeProps({ref:"input",class:r.inputFieldClass,style:n.inputStyle,type:r.inputType,value:n.modelValue,onInput:r.onInput,onFocus:r.onFocus,onBlur:r.onBlur,onKeyup:r.onKeyUp},e.$attrs),null,16,["class","style","type","value","onInput","onFocus","onBlur","onKeyup"]),n.toggleMask?(s.openBlock(),s.createBlock("i",{key:0,class:r.toggleIconClass,onClick:t[1]||(t[1]=(...e)=>r.onMaskToggle&&r.onMaskToggle(...e))},null,2)):s.createCommentVNode("",!0),(s.openBlock(),s.createBlock(s.Teleport,{to:n.appendTo},[s.createVNode(s.Transition,{name:"p-connected-overlay",onEnter:r.onOverlayEnter,onLeave:r.onOverlayLeave},{default:s.withCtx((()=>[l.overlayVisible?(s.openBlock(),s.createBlock("div",{key:0,ref:r.overlayRef,class:"p-password-panel p-component",onClick:t[2]||(t[2]=(...e)=>r.onOverlayClick&&r.onOverlayClick(...e))},[s.renderSlot(e.$slots,"header"),s.renderSlot(e.$slots,"content",{},(()=>[s.createVNode("div",o,[s.createVNode("div",{class:r.strengthClass,style:{width:l.meter?l.meter.width:""}},null,6)]),s.createVNode("div",a,s.toDisplayString(l.infoText),1)])),s.renderSlot(e.$slots,"footer")],512)):s.createCommentVNode("",!0)])),_:1},8,["onEnter","onLeave"])],8,["to"]))],6)},module.exports=r;