UNPKG

primevue

Version:

PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc

2 lines (1 loc) 4.64 kB
import e from"primevue/ripple";import t from"primevue/basecomponent";import n from"primevue/togglebutton/style";import{resolveDirective as i,withDirectives as o,openBlock as l,createElementBlock as r,mergeProps as u,createElementVNode as s,renderSlot as c,normalizeClass as a,createCommentVNode as d,toDisplayString as f}from"vue";var p={name:"ToggleButton",extends:{name:"BaseToggleButton",extends:t,props:{modelValue:Boolean,onIcon:String,offIcon:String,onLabel:{type:String,default:"Yes"},offLabel:{type:String,default:"No"},iconPos:{type:String,default:"left"},disabled:{type:Boolean,default:!1},tabindex:{type:Number,default:null},inputId:{type:String,default:null},inputClass:{type:[String,Object],default:null},inputStyle:{type:Object,default:null},inputProps:{type:null,default:null},ariaLabelledby:{type:String,default:null},ariaLabel:{type:String,default:null}},style:n,provide:function(){return{$parentInstance:this}}},emits:["update:modelValue","change","click","focus","blur"],outsideClickListener:null,data:function(){return{focused:!1}},mounted:function(){this.bindOutsideClickListener()},beforeUnmount:function(){this.unbindOutsideClickListener()},methods:{onClick:function(e){this.disabled||(this.$emit("update:modelValue",!this.modelValue),this.$emit("change",e),this.$emit("click",e),this.focused=!0)},onFocus:function(e){this.focused=!0,this.$emit("focus",e)},onBlur:function(e){this.focused=!1,this.$emit("blur",e)},bindOutsideClickListener:function(){var e=this;this.outsideClickListener||(this.outsideClickListener=function(t){e.focused&&!e.$refs.container.contains(t.target)&&(e.focused=!1)},document.addEventListener("click",this.outsideClickListener))},unbindOutsideClickListener:function(){this.outsideClickListener&&(document.removeEventListener("click",this.outsideClickListener),this.outsideClickListener=null)}},computed:{hasLabel:function(){return this.onLabel&&this.onLabel.length>0&&this.offLabel&&this.offLabel.length>0},hasIcon:function(){return this.$slots.icon||this.onIcon&&this.offIcon},label:function(){return this.hasLabel?this.modelValue?this.onLabel:this.offLabel:"&nbsp;"},getPTOptions:function(){return{context:{focused:this.focused,disabled:this.disabled,highlighted:!0===this.modelValue}}}},directives:{ripple:e}};function b(e){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},b(e)}function m(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function h(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?m(Object(n),!0).forEach((function(t){y(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function y(e,t,n){var i;return(t="symbol"==b(i=g(t,"string"))?i:String(i))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function g(e,t){if("object"!=b(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=b(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var v=["data-p-active"],O=["id","checked","value","aria-labelledby","aria-label"];p.render=function(e,t,n,p,b,m){var y=i("ripple");return o((l(),r("div",u({ref:"container",class:e.cx("root"),onClick:t[2]||(t[2]=function(e){return m.onClick(e)})},e.ptm("root",m.getPTOptions),{"data-p-active":!0===e.modelValue,"data-pc-name":"togglebutton"}),[s("span",u({class:"p-hidden-accessible"},e.ptm("hiddenInputWrapper"),{"data-p-hidden-accessible":!0}),[s("input",u({id:e.inputId,type:"checkbox",role:"switch",class:e.inputClass,style:e.inputStyle,checked:e.modelValue,value:e.modelValue,"aria-labelledby":e.ariaLabelledby,"aria-label":e.ariaLabel,onFocus:t[0]||(t[0]=function(e){return m.onFocus(e)}),onBlur:t[1]||(t[1]=function(e){return m.onBlur(e)})},h(h({},e.inputProps),e.ptm("hiddenInput"))),null,16,O)],16),c(e.$slots,"icon",{value:e.modelValue,class:a(e.cx("icon"))},(function(){return[e.onIcon||e.offIcon?(l(),r("span",u({key:0,class:[e.cx("icon"),e.modelValue?e.onIcon:e.offIcon]},e.ptm("icon",m.getPTOptions)),null,16)):d("",!0)]})),s("span",u({class:e.cx("label")},e.ptm("label",m.getPTOptions)),f(m.label),17)],16,v)),[[y]])};export{p as default};