@progress/kendo-vue-buttons
Version:
244 lines (243 loc) • 6.12 kB
JavaScript
/**
* @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 $, createVNode as d } from "vue";
import { getDefaultSlots as m, kendoThemeMaps as b, validatePackage as v, classNames as k, Icon as S } from "@progress/kendo-vue-common";
import C from "./util.mjs";
import { packageMetadata as w } from "./package-metadata.mjs";
const A = C.styles, K = /* @__PURE__ */ $({
name: "KendoButton",
emits: {
click: (e) => !0,
mousedown: (e) => !0,
mouseup: (e) => !0,
pointerdown: (e) => !0,
pointerup: (e) => !0,
focus: (e) => !0,
blur: (e) => !0,
keypress: (e) => !0,
keydown: (e) => !0,
contextmenu: (e) => !0
},
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,
iconSize: {
type: String,
default: "medium"
},
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() {
v(w), 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: l,
iconClass: r,
imageUrl: i,
dir: a,
svgIcon: h,
size: n,
shape: s,
rounded: o,
fillMode: t,
themeColor: u
} = this.$props, p = h !== void 0 || l !== void 0 || r !== void 0 || i !== void 0, c = m(this);
return {
[A.button]: !0,
[`k-button-${b.sizeMap[n] || n}`]: n,
[`k-button-${s}`]: s && s !== "rectangle",
[`k-rounded-${b.roundedMap[o] || o}`]: o,
"k-icon-button": !c && p,
"k-disabled": e,
"k-selected": this.computedSelected,
"k-rtl": a === "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", {
event: e
});
},
handleBlur(e) {
this.disabled || this.$emit("blur", {
event: 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: l,
svgIcon: r,
iconClass: i,
imageUrl: a,
imageAlt: h,
accessKey: n,
tabIndex: s,
id: o,
type: t,
disabled: u,
role: p,
iconSize: f
} = this.$props, c = m(this), g = function() {
if (a)
return d("img", {
role: "presentation",
class: "k-image",
alt: h,
src: a
}, null);
if (l || r) {
const y = k("k-button-icon", i);
return d(S, {
name: l,
icon: r,
class: y,
size: f
}, null);
} else if (i)
return d("span", {
role: "presentation",
class: i
}, null);
return null;
};
return d("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: o,
type: t,
role: p
}, [g.call(this), c && d("span", {
class: "k-button-text"
}, [c])]);
}
});
export {
K as Button
};