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

93 lines (83 loc) 2.82 kB
'use strict'; var Ripple = require('primevue/ripple'); var vue = require('vue'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var Ripple__default = /*#__PURE__*/_interopDefaultLegacy(Ripple); var script = { name: 'ToggleButton', emits: ['update:modelValue', 'change'], props: { modelValue: Boolean, onIcon: String, offIcon: String, onLabel: String, offLabel: String, iconPos: { type: String, default: 'left' } }, methods: { onClick(event) { if (!this.$attrs.disabled) { this.$emit('update:modelValue', !this.modelValue); this.$emit('change', event); } } }, computed: { buttonClass() { return { 'p-button p-togglebutton p-component': true, 'p-button-icon-only': this.hasIcon && !this.hasLabel, 'p-disabled': this.$attrs.disabled, 'p-highlight': this.modelValue === true } }, iconClass() { return [ this.modelValue ? this.onIcon: this.offIcon, 'p-button-icon', { 'p-button-icon-left': this.iconPos === 'left' && this.label, 'p-button-icon-right': this.iconPos === 'right' && 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': Ripple__default['default'] } }; const _hoisted_1 = { class: "p-button-label" }; function render(_ctx, _cache, $props, $setup, $data, $options) { const _directive_ripple = vue.resolveDirective("ripple"); return vue.withDirectives((vue.openBlock(), vue.createBlock("div", { class: $options.buttonClass, onClick: _cache[1] || (_cache[1] = $event => ($options.onClick($event))), role: "checkbox", "aria-checked": $props.modelValue, tabindex: _ctx.$attrs.disabled ? null : '0' }, [ ($options.hasIcon) ? (vue.openBlock(), vue.createBlock("span", { key: 0, class: $options.iconClass }, null, 2)) : vue.createCommentVNode("", true), vue.createVNode("span", _hoisted_1, vue.toDisplayString($options.label), 1) ], 10, ["aria-checked", "tabindex"])), [ [_directive_ripple] ]) } script.render = render; module.exports = script;