Chatwoot/app/javascript/dashboard/components/ui/WootButton.vue

94 lines
1.9 KiB
Vue
Raw Normal View History

2021-03-26 14:50:20 +00:00
<template>
<button
class="button"
2021-05-20 08:21:46 +00:00
:class="buttonClasses"
2021-03-26 14:50:20 +00:00
:disabled="isDisabled || isLoading"
@click="handleClick"
>
<spinner v-if="isLoading" size="small" />
<emoji-or-icon
v-else-if="icon || emoji"
class="icon"
:emoji="emoji"
:icon="icon"
/>
<span v-if="$slots.default" class="button__content"><slot></slot></span>
2021-03-26 14:50:20 +00:00
</button>
</template>
<script>
import Spinner from 'shared/components/Spinner';
import EmojiOrIcon from 'shared/components/EmojiOrIcon';
2021-03-26 14:50:20 +00:00
export default {
name: 'WootButton',
components: { EmojiOrIcon, Spinner },
2021-03-26 14:50:20 +00:00
props: {
variant: {
type: String,
default: '',
},
size: {
type: String,
default: '',
},
icon: {
type: String,
default: '',
},
emoji: {
type: String,
default: '',
},
2021-03-26 14:50:20 +00:00
colorScheme: {
type: String,
default: 'primary',
},
classNames: {
type: [String, Object],
2021-03-26 14:50:20 +00:00
default: '',
},
isDisabled: {
type: Boolean,
default: false,
},
isLoading: {
type: Boolean,
default: false,
},
2021-05-20 08:21:46 +00:00
isExpanded: {
type: Boolean,
default: false,
},
},
computed: {
variantClasses() {
if (this.variant.includes('link')) {
return `clear ${this.variant}`;
}
return this.variant;
},
hasOnlyIconClasses() {
const hasEmojiOrIcon = this.emoji || this.icon;
if (!this.$slots.default && hasEmojiOrIcon) return 'button--only-icon';
return '';
},
2021-05-20 08:21:46 +00:00
buttonClasses() {
return [
this.variantClasses,
this.hasOnlyIconClasses,
2021-05-20 08:21:46 +00:00
this.size,
this.colorScheme,
this.classNames,
this.isDisabled ? 'disabled' : '',
this.isExpanded ? 'expanded' : '',
];
},
2021-03-26 14:50:20 +00:00
},
methods: {
handleClick(evt) {
this.$emit('click', evt);
},
},
};
</script>