UNPKG

@progress/kendo-vue-buttons

Version:
234 lines (233 loc) 5.91 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { defineComponent as y, createVNode as o } from "vue"; import { validatePackage as $, getDefaultSlots as m, kendoThemeMaps as b, classNames as k, Icon as S } from "@progress/kendo-vue-common"; import v from "./util.mjs"; import { packageMetadata as C } from "./package-metadata.mjs"; const w = v.styles, I = /* @__PURE__ */ y({ name: "KendoButton", emits: { click: null, mousedown: null, mouseup: null, pointerdown: null, pointerup: null, focus: null, blur: null, keypress: null, keydown: null, contextmenu: null }, props: { ariaLabel: String, ariaPressed: Boolean, title: String, dir: String, selected: { type: Boolean, default: void 0 }, togglable: { type: Boolean, default: !1 }, icon: { type: String, default: function() { } }, svgIcon: Object, iconClass: { type: String, default: function() { } }, imageUrl: { type: String, default: function() { } }, imageAlt: String, disabled: { type: Boolean, default: void 0 }, size: { type: String, default: "medium" }, shape: { type: String }, rounded: { type: String, default: "medium" }, fillMode: { type: String, default: "solid" }, themeColor: { type: String, default: "base" }, tabIndex: Number, accessKey: String, id: String, type: String, role: String }, created() { $(C), this.currentActive = this.$props.togglable === !0 && this.$props.selected === !0, this._activeTemp = void 0; }, data() { return { currentActive: null }; }, computed: { computedSelected() { return this._activeTemp !== void 0 ? this._activeTemp : this.$props.selected !== void 0 ? this.$props.selected : this.currentActive; }, buttonClasses() { const { disabled: e, icon: d, iconClass: a, imageUrl: i, dir: r, svgIcon: c, size: n, shape: s, rounded: l, fillMode: t, themeColor: u } = this.$props, h = c !== void 0 || d !== void 0 || a !== void 0 || i !== void 0, f = m(this); return { [w.button]: !0, [`k-button-${b.sizeMap[n] || n}`]: n, [`k-button-${s}`]: s && s !== "rectangle", [`k-rounded-${b.roundedMap[l] || l}`]: l, "k-icon-button": !f && h, "k-disabled": e, "k-selected": this.computedSelected, "k-rtl": r === "rtl", [`k-button-${t}`]: t, [`k-button-${t}-${u}`]: t && u }; } }, updated() { this.$props.togglable && this.$props.selected !== void 0 && this.$props.selected !== this.currentActive && (this.currentActive = this.$props.selected); }, methods: { focus(e) { this.$el.focus(e); }, toggleIfApplicable() { if (!this.disabled && this.$props.togglable && this.$props.selected === void 0) { const e = !this.currentActive; this._activeTemp = e, this.currentActive = e, this._activeTemp = void 0; } }, handleClick(e) { this.toggleIfApplicable(), this.disabled || this.$emit("click", e); }, handleMouseDown(e) { this.disabled || this.$emit("mousedown", e); }, handlePointerDown(e) { this.disabled || this.$emit("pointerdown", e); }, handleMouseUp(e) { this.disabled || this.$emit("mouseup", e); }, handlePointerUp(e) { this.disabled || this.$emit("pointerup", e); }, handleFocus(e) { this.disabled || this.$emit("focus", e); }, handleBlur(e) { this.disabled || this.$emit("blur", e); }, handleKeypress(e) { this.disabled || this.$emit("keypress", e); }, handleKeydown(e) { this.disabled || this.$emit("keydown", e); }, handleContextmenu(e) { this.disabled || this.$emit("contextmenu", e); } }, render() { const { togglable: e, icon: d, svgIcon: a, iconClass: i, imageUrl: r, imageAlt: c, accessKey: n, tabIndex: s, id: l, type: t, disabled: u, role: h } = this.$props, p = m(this), f = function() { if (r) return o("img", { role: "presentation", class: "k-image", alt: c, src: r }, null); if (d || a) { const g = k("k-button-icon", i); return o(S, { name: d, icon: a, class: g }, null); } else if (i) return o("span", { role: "presentation", class: i }, null); return null; }; return o("button", { class: this.buttonClasses, onClick: this.handleClick, onMousedown: this.handleMouseDown, onMouseup: this.handleMouseUp, onPointerdown: this.handlePointerDown, onPointerup: this.handlePointerUp, onFocus: this.handleFocus, onBlur: this.handleBlur, onKeypress: this.handleKeypress, onKeydown: this.handleKeydown, onContextmenu: this.handleContextmenu, title: this.title, "aria-label": this.ariaLabel, "aria-disabled": u || void 0, "aria-pressed": e ? !!this.currentActive : void 0, accesskey: n, tabindex: s, id: l, type: t, role: h }, [f.call(this), p && o("span", { class: "k-button-text" }, [p])]); } }); export { I as Button };