homebox/frontend/components/Base/Button.vue

80 lines
1.5 KiB
Vue
Raw Normal View History

2022-09-01 22:32:03 +00:00
<template>
2022-09-06 18:32:13 +00:00
<NuxtLink
v-if="to"
:to="to"
v-bind="attributes"
class="btn"
ref="submitBtn"
:class="{
loading: loading,
'btn-sm': size === 'sm',
'btn-lg': size === 'lg',
}"
>
<label v-if="$slots.icon" class="swap swap-rotate mr-2" :class="{ 'swap-active': isHover }">
<slot name="icon" />
</label>
<slot />
</NuxtLink>
2022-09-01 22:32:03 +00:00
<button
2022-09-06 18:32:13 +00:00
v-else
v-bind="attributes"
2022-09-01 22:32:03 +00:00
class="btn"
2022-09-02 17:46:20 +00:00
ref="submitBtn"
2022-09-01 22:32:03 +00:00
:class="{
loading: loading,
2022-09-06 18:32:13 +00:00
'btn-sm': size === 'sm',
'btn-lg': size === 'lg',
2022-09-01 22:32:03 +00:00
}"
>
2022-09-02 17:46:20 +00:00
<label v-if="$slots.icon" class="swap swap-rotate mr-2" :class="{ 'swap-active': isHover }">
<slot name="icon" />
</label>
2022-09-01 22:32:03 +00:00
<slot />
</button>
</template>
<script setup lang="ts">
2022-09-06 18:32:13 +00:00
type Sizes = 'sm' | 'md' | 'lg';
const props = defineProps({
2022-09-01 22:32:03 +00:00
loading: {
type: Boolean,
default: false,
},
disabled: {
type: Boolean,
default: false,
},
2022-09-06 18:32:13 +00:00
size: {
type: String as () => Sizes,
default: 'md',
},
to: {
type: String as () => string | null,
default: null,
},
});
const attributes = computed(() => {
if (props.to) {
return {
href: props.to,
};
}
return {
disabled: props.disabled || props.loading,
};
});
const is = computed(() => {
if (props.to) {
return 'a';
}
return 'button';
2022-09-01 22:32:03 +00:00
});
2022-09-02 17:46:20 +00:00
const submitBtn = ref(null);
const isHover = useElementHover(submitBtn);
2022-09-01 22:32:03 +00:00
</script>