2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-04-24 12:00:20 +00:00
|
|
|
<button v-ripple :class="buttonClass" type="button" :aria-label="defaultAriaLabel" :disabled="disabled" v-bind="ptm('root')">
|
2023-04-27 12:18:17 +00:00
|
|
|
<slot>
|
2023-04-18 07:35:20 +00:00
|
|
|
<slot v-if="loading" name="loadingicon" :class="loadingIconStyleClass">
|
2023-04-24 12:00:20 +00:00
|
|
|
<span v-if="loadingIcon" :class="[loadingIconStyleClass, loadingIcon]" v-bind="ptm('loadingIcon')" />
|
|
|
|
<SpinnerIcon v-else :class="loadingIconStyleClass" spin v-bind="ptm('loadingIcon')" />
|
2023-04-13 09:19:28 +00:00
|
|
|
</slot>
|
|
|
|
<slot v-else name="icon" :class="iconStyleClass">
|
2023-04-24 12:00:20 +00:00
|
|
|
<span v-if="icon" :class="[iconStyleClass, icon]" v-bind="ptm('icon')"></span>
|
2023-04-13 09:19:28 +00:00
|
|
|
</slot>
|
2023-04-24 12:00:20 +00:00
|
|
|
<span class="p-button-label" v-bind="ptm('label')">{{ label || ' ' }}</span>
|
|
|
|
<span v-if="badge" :class="badgeStyleClass" v-bind="ptm('badge')">{{ badge }}</span>
|
2023-04-27 12:18:17 +00:00
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-24 12:00:20 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2023-04-18 12:53:43 +00:00
|
|
|
import SpinnerIcon from 'primevue/icons/spinner';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Button',
|
2023-04-24 12:00:20 +00:00
|
|
|
extends: BaseComponent,
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
|
|
|
label: {
|
2022-12-08 11:04:25 +00:00
|
|
|
type: String,
|
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
icon: {
|
2022-12-08 11:04:25 +00:00
|
|
|
type: String,
|
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
iconPos: {
|
|
|
|
type: String,
|
|
|
|
default: 'left'
|
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
iconClass: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
badge: {
|
2022-12-08 11:04:25 +00:00
|
|
|
type: String,
|
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
badgeClass: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
loadingIcon: {
|
|
|
|
type: String,
|
2023-04-13 09:19:28 +00:00
|
|
|
default: undefined
|
2023-03-03 07:03:54 +00:00
|
|
|
},
|
|
|
|
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
|
2023-03-06 08:14:59 +00:00
|
|
|
},
|
|
|
|
plain: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
buttonClass() {
|
2023-03-03 07:03:54 +00:00
|
|
|
return [
|
|
|
|
'p-button p-component',
|
|
|
|
{
|
2023-04-13 09:19:28 +00:00
|
|
|
'p-button-icon-only': this.hasIcon && !this.label,
|
2023-03-03 07:03:54 +00:00
|
|
|
'p-button-vertical': (this.iconPos === 'top' || this.iconPos === 'bottom') && this.label,
|
|
|
|
'p-disabled': this.$attrs.disabled || this.loading,
|
|
|
|
'p-button-loading': this.loading,
|
2023-04-13 09:19:28 +00:00
|
|
|
'p-button-loading-label-only': this.loading && !this.hasIcon && this.label,
|
2023-03-03 07:03:54 +00:00
|
|
|
'p-button-link': this.link,
|
|
|
|
[`p-button-${this.severity}`]: this.severity,
|
|
|
|
'p-button-raised': this.raised,
|
|
|
|
'p-button-rounded': this.rounded,
|
|
|
|
'p-button-text': this.text,
|
|
|
|
'p-button-outlined': this.outlined,
|
|
|
|
'p-button-sm': this.size === 'small',
|
2023-03-06 08:14:59 +00:00
|
|
|
'p-button-lg': this.size === 'large',
|
|
|
|
'p-button-plain': this.plain
|
2023-03-03 07:03:54 +00:00
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
iconStyleClass() {
|
2022-09-06 12:03:37 +00:00
|
|
|
return [
|
|
|
|
'p-button-icon',
|
2022-09-14 11:26:01 +00:00
|
|
|
this.iconClass,
|
2022-09-06 12:03:37 +00:00
|
|
|
{
|
|
|
|
'p-button-icon-left': this.iconPos === 'left' && this.label,
|
|
|
|
'p-button-icon-right': this.iconPos === 'right' && this.label,
|
|
|
|
'p-button-icon-top': this.iconPos === 'top' && this.label,
|
|
|
|
'p-button-icon-bottom': this.iconPos === 'bottom' && this.label
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-04-18 07:35:20 +00:00
|
|
|
loadingIconStyleClass() {
|
|
|
|
return ['p-button-loading-icon pi-spin', this.iconStyleClass];
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
badgeStyleClass() {
|
|
|
|
return [
|
2022-09-14 11:26:01 +00:00
|
|
|
'p-badge p-component',
|
|
|
|
this.badgeClass,
|
|
|
|
{
|
|
|
|
'p-badge-no-gutter': this.badge && String(this.badge).length === 1
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
disabled() {
|
|
|
|
return this.$attrs.disabled || this.loading;
|
|
|
|
},
|
|
|
|
defaultAriaLabel() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.label ? this.label + (this.badge ? ' ' + this.badge : '') : this.$attrs['aria-label'];
|
2023-04-13 09:19:28 +00:00
|
|
|
},
|
|
|
|
hasIcon() {
|
|
|
|
return this.icon || this.$slots.icon;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2023-04-13 09:19:28 +00:00
|
|
|
components: {
|
|
|
|
SpinnerIcon
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
directives: {
|
2022-09-14 11:26:01 +00:00
|
|
|
ripple: Ripple
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|