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) 3.04 kB
import e from"primevue/ripple";import{ObjectUtils as t}from"primevue/utils";import n from"primevue/basecomponent";import l from"primevue/togglebutton/style";import{resolveDirective as i,openBlock as a,createElementBlock as o,mergeProps as u,createElementVNode as s,withDirectives as r,renderSlot as d,normalizeClass as p,createCommentVNode as c,toDisplayString as b}from"vue";var f={name:"ToggleButton",extends:{name:"BaseToggleButton",extends:n,props:{modelValue:Boolean,onIcon:String,offIcon:String,onLabel:{type:String,default:"Yes"},offLabel:{type:String,default:"No"},iconPos:{type:String,default:"left"},invalid:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},readonly:{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},ariaLabelledby:{type:String,default:null},ariaLabel:{type:String,default:null}},style:l,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,emits:["update:modelValue","change","focus","blur"],methods:{getPTOptions:function(e){return("root"===e?this.ptmi:this.ptm)(e,{context:{active:this.active,disabled:this.disabled}})},onChange:function(e){this.disabled||this.readonly||(this.$emit("update:modelValue",!this.modelValue),this.$emit("change",e))},onFocus:function(e){this.$emit("focus",e)},onBlur:function(e){this.$emit("blur",e)}},computed:{active:function(){return!0===this.modelValue},hasLabel:function(){return t.isNotEmpty(this.onLabel)&&t.isNotEmpty(this.offLabel)},hasIcon:function(){return this.$slots.icon||this.onIcon&&this.offIcon},label:function(){return this.hasLabel?this.modelValue?this.onLabel:this.offLabel:" "}},directives:{ripple:e}},h=["data-p-highlight","data-p-disabled"],m=["id","value","checked","tabindex","disabled","readonly","aria-labelledby","aria-label","aria-invalid"];f.render=function(e,t,n,l,f,y){var g=i("ripple");return a(),o("div",u({class:e.cx("root")},y.getPTOptions("root"),{"data-p-highlight":y.active,"data-p-disabled":e.disabled}),[s("input",u({id:e.inputId,type:"checkbox",role:"switch",class:[e.cx("input"),e.inputClass],style:e.inputStyle,value:e.modelValue,checked:y.active,tabindex:e.tabindex,disabled:e.disabled,readonly:e.readonly,"aria-labelledby":e.ariaLabelledby,"aria-label":e.ariaLabel,"aria-invalid":e.invalid||void 0,onFocus:t[0]||(t[0]=function(){return y.onFocus&&y.onFocus.apply(y,arguments)}),onBlur:t[1]||(t[1]=function(){return y.onBlur&&y.onBlur.apply(y,arguments)}),onChange:t[2]||(t[2]=function(){return y.onChange&&y.onChange.apply(y,arguments)})},y.getPTOptions("input")),null,16,m),r((a(),o("div",u({class:e.cx("box")},y.getPTOptions("box")),[d(e.$slots,"icon",{value:e.modelValue,class:p(e.cx("icon"))},(function(){return[e.onIcon||e.offIcon?(a(),o("span",u({key:0,class:[e.cx("icon"),e.modelValue?e.onIcon:e.offIcon]},y.getPTOptions("icon")),null,16)):c("",!0)]})),s("span",u({class:e.cx("label")},y.getPTOptions("label")),b(y.label),17)],16)),[[g]])],16,h)};export{f as default};