UNPKG

primevue

Version:

PrimeVue is a premium UI library for Vue featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock, wh

267 lines (261 loc) 9.11 kB
import Spinner from '@primeicons/vue/spinner'; import { cn } from '@primeuix/utils'; import { isEmpty } from '@primeuix/utils/object'; import Badge from 'primevue/badge'; import Ripple from 'primevue/ripple'; import { mergeProps, resolveComponent, resolveDirective, withDirectives, openBlock, createBlock, resolveDynamicComponent, withCtx, renderSlot, createElementBlock, createCommentVNode, toDisplayString, normalizeClass } from 'vue'; import BaseComponent from '@primevue/core/basecomponent'; import ButtonStyle from 'primevue/button/style'; var script$1 = { name: 'BaseButton', "extends": BaseComponent, props: { /** * @deprecated since v5.0.0. Use the default slot instead. */ label: { type: String, "default": null }, /** * @deprecated since v5.0.0. Use the default slot instead. */ icon: { type: String, "default": null }, /** * @deprecated since v5.0.0. Express icon position via slot order in the default slot. */ iconPos: { type: String, "default": 'left' }, /** * @deprecated since v5.0.0. Use the default slot instead. */ iconClass: { type: [String, Object], "default": null }, /** * @deprecated since v5.0.0. Compose a Badge inside the default slot instead. */ badge: { type: String, "default": null }, /** * @deprecated since v5.0.0. Compose a Badge inside the default slot instead. */ badgeClass: { type: [String, Object], "default": null }, /** * @deprecated since v5.0.0. Compose a Badge inside the default slot instead. */ badgeSeverity: { type: String, "default": 'secondary' }, /** * @deprecated since v5.0.0. Render your own spinner inside the default slot and toggle disabled. */ loading: { type: Boolean, "default": false }, /** * @deprecated since v5.0.0. Render your own spinner inside the default slot and toggle disabled. */ loadingIcon: { type: String, "default": undefined }, iconOnly: { type: Boolean, "default": false }, as: { type: [String, Object], "default": 'BUTTON' }, asChild: { type: Boolean, "default": false }, link: { type: Boolean, "default": false }, severity: { type: String, "default": null }, raised: { type: Boolean, "default": false }, rounded: { type: Boolean, "default": false }, text: { type: Boolean, "default": false }, outlined: { type: Boolean, "default": false }, size: { type: String, "default": null }, variant: { type: String, "default": null }, fluid: { type: Boolean, "default": null } }, style: ButtonStyle, provide: function provide() { return { $pcButton: this, $parentInstance: this }; } }; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var script = { name: 'Button', "extends": script$1, inheritAttrs: false, inject: { $pcFluid: { "default": null } }, methods: { getPTOptions: function getPTOptions(key) { var _ptm = key === 'root' ? this.ptmi : this.ptm; return _ptm(key, { context: { disabled: this.disabled } }); } }, computed: { disabled: function disabled() { return this.$attrs.disabled || this.$attrs.disabled === '' || this.loading; }, defaultAriaLabel: function defaultAriaLabel() { return this.label ? this.label + (this.badge ? ' ' + this.badge : '') : this.$attrs.ariaLabel; }, hasIcon: function hasIcon() { return this.icon || this.$slots.icon; }, attrs: function attrs() { return mergeProps(this.asAttrs, this.a11yAttrs, this.getPTOptions('root')); }, asAttrs: function asAttrs() { return this.as === 'BUTTON' ? { type: 'button', disabled: this.disabled } : undefined; }, a11yAttrs: function a11yAttrs() { return { 'aria-label': this.defaultAriaLabel, 'data-pc-name': 'button', 'data-p-disabled': this.disabled, 'data-p-severity': this.severity }; }, hasFluid: function hasFluid() { return isEmpty(this.fluid) ? !!this.$pcFluid : this.fluid; }, dataP: function dataP() { return cn(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, this.size, this.size), 'icon-only', this.iconOnly || this.hasIcon && !this.label && !this.badge), "loading", this.loading), "fluid", this.hasFluid), "rounded", this.rounded), "raised", this.raised), "outlined", this.outlined || this.variant === 'outlined'), "text", this.text || this.variant === 'text'), "link", this.link || this.variant === 'link'), "vertical", (this.iconPos === 'top' || this.iconPos === 'bottom') && this.label)); }, dataIconP: function dataIconP() { return cn(_defineProperty(_defineProperty({}, this.iconPos, this.iconPos), this.size, this.size)); }, dataLabelP: function dataLabelP() { return cn(_defineProperty(_defineProperty({}, this.size, this.size), 'icon-only', this.iconOnly || this.hasIcon && !this.label && !this.badge)); } }, components: { Spinner: Spinner, Badge: Badge }, directives: { ripple: Ripple } }; var _hoisted_1 = ["data-p"]; var _hoisted_2 = ["data-p"]; function render(_ctx, _cache, $props, $setup, $data, $options) { var _component_Spinner = resolveComponent("Spinner"); var _component_Badge = resolveComponent("Badge"); var _directive_ripple = resolveDirective("ripple"); return !_ctx.asChild ? withDirectives((openBlock(), createBlock(resolveDynamicComponent(_ctx.as), mergeProps({ key: 0, "class": _ctx.cx('root'), "data-p": $options.dataP }, $options.attrs), { "default": withCtx(function () { return [renderSlot(_ctx.$slots, "default", {}, function () { return [_ctx.loading ? renderSlot(_ctx.$slots, "loadingicon", mergeProps({ key: 0, "class": [_ctx.cx('loadingIcon'), _ctx.cx('icon')] }, _ctx.ptm('loadingIcon')), function () { return [_ctx.loadingIcon ? (openBlock(), createElementBlock("span", mergeProps({ key: 0, "class": [_ctx.cx('loadingIcon'), _ctx.cx('icon'), _ctx.loadingIcon] }, _ctx.ptm('loadingIcon')), null, 16)) : (openBlock(), createBlock(_component_Spinner, mergeProps({ key: 1, "class": [_ctx.cx('loadingIcon'), _ctx.cx('icon')], spin: "" }, _ctx.ptm('loadingIcon')), null, 16, ["class"]))]; }) : renderSlot(_ctx.$slots, "icon", mergeProps({ key: 1, "class": [_ctx.cx('icon')] }, _ctx.ptm('icon')), function () { return [_ctx.icon ? (openBlock(), createElementBlock("span", mergeProps({ key: 0, "class": [_ctx.cx('icon'), _ctx.icon, _ctx.iconClass], "data-p": $options.dataIconP }, _ctx.ptm('icon')), null, 16, _hoisted_1)) : createCommentVNode("", true)]; }), _ctx.label ? (openBlock(), createElementBlock("span", mergeProps({ key: 2, "class": _ctx.cx('label') }, _ctx.ptm('label'), { "data-p": $options.dataLabelP }), toDisplayString(_ctx.label), 17, _hoisted_2)) : createCommentVNode("", true), _ctx.badge ? (openBlock(), createBlock(_component_Badge, { key: 3, value: _ctx.badge, "class": normalizeClass(_ctx.badgeClass), severity: _ctx.badgeSeverity, unstyled: _ctx.unstyled, pt: _ctx.ptm('pcBadge') }, null, 8, ["value", "class", "severity", "unstyled", "pt"])) : createCommentVNode("", true)]; })]; }), _: 3 }, 16, ["class", "data-p"])), [[_directive_ripple]]) : renderSlot(_ctx.$slots, "default", { key: 1, "class": normalizeClass(_ctx.cx('root')), a11yAttrs: $options.a11yAttrs }); } script.render = render; export { script as default };