yunohost-portal/components/YButton.vue

56 lines
1.1 KiB
Vue
Raw Normal View History

2023-07-25 19:19:27 +02:00
<script setup lang="ts">
import { NuxtLink } from '#components'
2023-07-25 19:19:27 +02:00
const props = withDefaults(
defineProps<{
2023-08-01 16:30:36 +02:00
type?: 'button' | 'submit' | 'reset'
2023-07-25 22:46:38 +02:00
text?: string
variant?: string
icon?: string
2023-07-26 04:09:10 +02:00
iconSize?: string
iconOnly?: boolean
2023-08-28 15:08:33 +02:00
iconClass?: string
2023-07-25 19:19:27 +02:00
block?: boolean
}>(),
{
type: 'button',
2023-07-25 22:46:38 +02:00
text: undefined,
variant: 'primary',
icon: undefined,
2023-07-26 04:08:17 +02:00
iconSize: '1.5em',
2023-08-28 14:42:54 +02:00
iconClass: '',
2023-07-26 04:08:17 +02:00
iconOnly: false,
2023-07-25 19:19:27 +02:00
block: false,
},
)
const variantClass = computed(() => {
return {
primary: 'btn-primary',
success: 'btn-success',
info: 'btn-info',
2023-07-26 04:08:17 +02:00
error: 'btn-error',
2023-07-25 19:19:27 +02:00
}[props.variant]
})
</script>
<template>
<component
:is="$attrs.to ? NuxtLink : 'button'"
2023-08-01 16:30:36 +02:00
class="btn"
:class="[variantClass, { 'btn-block': block }]"
:type="$attrs.to ? null : type"
2023-08-01 16:30:36 +02:00
>
2023-07-25 22:46:38 +02:00
<slot name="default">
2023-08-28 14:42:54 +02:00
<Icon
v-if="icon"
:name="icon"
:size="iconSize"
:class="iconClass"
aria-hidden="true"
/>
2023-07-26 04:08:17 +02:00
<span :class="{ 'sr-only': iconOnly }">{{ text }}</span>
2023-07-25 22:46:38 +02:00
</slot>
</component>
2023-07-25 19:19:27 +02:00
</template>