2021-03-26 14:50:20 +00:00
|
|
|
<template>
|
|
|
|
<button
|
|
|
|
class="button"
|
2022-07-12 08:03:16 +00:00
|
|
|
:type="type"
|
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" />
|
2021-06-09 08:31:43 +00:00
|
|
|
<emoji-or-icon
|
|
|
|
v-else-if="icon || emoji"
|
|
|
|
class="icon"
|
|
|
|
:emoji="emoji"
|
|
|
|
:icon="icon"
|
2021-12-01 05:03:18 +00:00
|
|
|
:icon-size="iconSize"
|
2021-06-09 08:31:43 +00:00
|
|
|
/>
|
2022-06-10 13:59:52 +00:00
|
|
|
<span v-if="$slots.default" class="button__content"><slot /></span>
|
2021-03-26 14:50:20 +00:00
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
<script>
|
2021-06-09 08:31:43 +00:00
|
|
|
import Spinner from 'shared/components/Spinner';
|
|
|
|
import EmojiOrIcon from 'shared/components/EmojiOrIcon';
|
2021-03-26 14:50:20 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'WootButton',
|
2021-06-09 08:31:43 +00:00
|
|
|
components: { EmojiOrIcon, Spinner },
|
2021-03-26 14:50:20 +00:00
|
|
|
props: {
|
2022-07-12 08:03:16 +00:00
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
default: 'submit',
|
|
|
|
},
|
2021-03-26 14:50:20 +00:00
|
|
|
variant: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
2021-06-09 08:31:43 +00:00
|
|
|
emoji: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
2021-03-26 14:50:20 +00:00
|
|
|
colorScheme: {
|
|
|
|
type: String,
|
|
|
|
default: 'primary',
|
|
|
|
},
|
|
|
|
classNames: {
|
2021-06-09 08:31:43 +00:00
|
|
|
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;
|
|
|
|
},
|
2021-12-14 12:07:25 +00:00
|
|
|
hasOnlyIcon() {
|
2021-06-09 08:31:43 +00:00
|
|
|
const hasEmojiOrIcon = this.emoji || this.icon;
|
2021-12-14 12:07:25 +00:00
|
|
|
return !this.$slots.default && hasEmojiOrIcon;
|
|
|
|
},
|
|
|
|
hasOnlyIconClasses() {
|
|
|
|
return this.hasOnlyIcon ? 'button--only-icon' : '';
|
2021-06-09 08:31:43 +00:00
|
|
|
},
|
2021-05-20 08:21:46 +00:00
|
|
|
buttonClasses() {
|
|
|
|
return [
|
|
|
|
this.variantClasses,
|
2021-06-09 08:31:43 +00:00
|
|
|
this.hasOnlyIconClasses,
|
2021-05-20 08:21:46 +00:00
|
|
|
this.size,
|
|
|
|
this.colorScheme,
|
|
|
|
this.classNames,
|
|
|
|
this.isDisabled ? 'disabled' : '',
|
|
|
|
this.isExpanded ? 'expanded' : '',
|
|
|
|
];
|
|
|
|
},
|
2021-12-20 18:37:33 +00:00
|
|
|
iconSize() {
|
2021-12-14 12:07:25 +00:00
|
|
|
switch (this.size) {
|
|
|
|
case 'tiny':
|
|
|
|
return 12;
|
|
|
|
case 'small':
|
|
|
|
return 14;
|
|
|
|
case 'medium':
|
|
|
|
return 16;
|
|
|
|
case 'large':
|
|
|
|
return 18;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
},
|
2021-03-26 14:50:20 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleClick(evt) {
|
|
|
|
this.$emit('click', evt);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|