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) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 1.65 kB
"use strict";var e=require("primevue/ripple"),t=require("vue");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n={name:"ToggleButton",emits:["update:modelValue","change"],props:{modelValue:Boolean,onIcon:String,offIcon:String,onLabel:String,offLabel:String,iconPos:{type:String,default:"left"}},methods:{onClick(e){this.$attrs.disabled||(this.$emit("update:modelValue",!this.modelValue),this.$emit("change",e))}},computed:{buttonClass(){return{"p-button p-togglebutton p-component":!0,"p-button-icon-only":this.hasIcon&&!this.hasLabel,"p-disabled":this.$attrs.disabled,"p-highlight":!0===this.modelValue}},iconClass(){return[this.modelValue?this.onIcon:this.offIcon,"p-button-icon",{"p-button-icon-left":"left"===this.iconPos&&this.label,"p-button-icon-right":"right"===this.iconPos&&this.label}]},hasLabel(){return this.onLabel&&this.onLabel.length>0&&this.offLabel&&this.offLabel.length>0},hasIcon(){return this.onIcon&&this.onIcon.length>0&&this.offIcon&&this.offIcon.length>0},label(){return this.hasLabel?this.modelValue?this.onLabel:this.offLabel:" "}},directives:{ripple:o(e).default}};const l={class:"p-button-label"};n.render=function(e,o,n,i,s,a){const c=t.resolveDirective("ripple");return t.withDirectives((t.openBlock(),t.createBlock("div",{class:a.buttonClass,onClick:o[1]||(o[1]=e=>a.onClick(e)),role:"checkbox","aria-checked":n.modelValue,tabindex:e.$attrs.disabled?null:"0"},[a.hasIcon?(t.openBlock(),t.createBlock("span",{key:0,class:a.iconClass},null,2)):t.createCommentVNode("",!0),t.createVNode("span",l,t.toDisplayString(a.label),1)],10,["aria-checked","tabindex"])),[[c]])},module.exports=n;