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

59 lines
2.1 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-06-23 09:53:53 +00:00
<button v-ripple :class="cx('root')" type="button" :aria-label="defaultAriaLabel" :disabled="disabled" v-bind="getPTOptions('root')" 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-08-15 11:06:25 +00:00
<slot v-else name="icon" :class="[cx('icon')]">
<span v-if="icon" :class="[cx('icon'), icon, iconClass]" 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>
<Badge v-if="badge" :value="badge" :class="badgeClass" :severity="badgeSeverity" :unstyled="unstyled" v-bind="ptm('badge')"></Badge>
2023-04-27 12:18:17 +00:00
</slot>
2022-09-06 12:03:37 +00:00
</button>
</template>
<script>
2023-07-04 09:28:55 +00:00
import Badge from 'primevue/badge';
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,
2023-06-23 09:53:53 +00:00
methods: {
getPTOptions(key) {
return this.ptm(key, {
2023-07-30 18:22:49 +00:00
parent: {
props: this.$parent?.$props,
state: this.$parent?.$data
},
2023-06-23 09:53:53 +00:00
context: {
disabled: this.disabled
}
});
}
},
2022-09-06 12:03:37 +00:00
computed: {
disabled() {
2023-06-22 14:16:55 +00:00
return this.$attrs.disabled || this.$attrs.disabled === '' || this.loading;
2022-09-06 12:03:37 +00:00
},
defaultAriaLabel() {
2023-11-30 20:08:56 +00:00
return this.label ? this.label + (this.badge ? ' ' + this.badge : '') : this.$attrs.ariaLabel;
},
hasIcon() {
return this.icon || this.$slots.icon;
2022-09-06 12:03:37 +00:00
}
},
components: {
SpinnerIcon,
Badge
},
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>