primevue-mirror/components/lib/button/Button.vue

44 lines
1.6 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-06-22 12:24:07 +00:00
<button v-ripple :class="cx('root')" type="button" :aria-label="defaultAriaLabel" :disabled="disabled" v-bind="ptm('root', { disabled })" data-pc-name="button" :data-pc-severity="severity">
2023-04-27 12:18:17 +00:00
<slot>
2023-05-30 14:05:57 +00:00
<slot v-if="loading" name="loadingicon" :class="[cx('loadingIcon'), cx('icon')]">
<span v-if="loadingIcon" :class="[cx('loadingIcon'), cx('icon'), loadingIcon]" v-bind="ptm('loadingIcon')" />
<SpinnerIcon v-else :class="[cx('loadingIcon'), cx('icon')]" spin v-bind="ptm('loadingIcon')" />
</slot>
2023-05-30 14:05:57 +00:00
<slot v-else name="icon" :class="cx('icon')">
<span v-if="icon" :class="[cx('icon'), icon]" v-bind="ptm('icon')"></span>
</slot>
2023-05-30 14:05:57 +00:00
<span :class="cx('label')" v-bind="ptm('label')">{{ label || '&nbsp;' }}</span>
<span v-if="badge" :class="[cx('badge'), badgeClass]" 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>
import SpinnerIcon from 'primevue/icons/spinner';
2022-09-06 12:03:37 +00:00
import Ripple from 'primevue/ripple';
2023-05-30 14:05:57 +00:00
import BaseButton from './BaseButton.vue';
2022-09-06 12:03:37 +00:00
export default {
name: 'Button',
2023-05-30 14:05:57 +00:00
extends: BaseButton,
2022-09-06 12:03:37 +00:00
computed: {
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'];
},
hasIcon() {
return this.icon || this.$slots.icon;
2022-09-06 12:03:37 +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>