Files
axp-ui/src/components/Btn.vue
T

56 lines
1.1 KiB
Vue
Raw Normal View History

2023-09-20 14:09:22 +03:00
<script lang="ts">
2023-07-27 15:36:52 +03:00
import type { TColor } from '../colors'
import type { TUiIcon } from '../icons'
2023-09-20 14:09:22 +03:00
export type TUiBtnProps = {
2023-07-11 10:38:21 +03:00
label?: string
type?: 'button' | 'submit'
2023-07-27 15:36:52 +03:00
color?: TColor
icon?: TUiIcon
to?: string
2023-09-20 14:09:22 +03:00
}
export type TUiBtnEmits = {
(e: 'click', v: PointerEvent): void
}
</script>
<script setup lang="ts">
import UiIcon from './Icon.vue'
import { computed } from 'vue'
// Props.
const props = defineProps<TUiBtnProps>()
// Emits.
const emit = defineEmits<TUiBtnEmits>()
// Handlers.
const clickHandler = (e: PointerEvent) => emit('click', e)
// Computed.
const cssClass = computed(() => {
let obj: any = {
'ui-btn': true,
'ui-btn-icon': props.icon
}
if (props.color) obj[props.color] = true
return obj
})
2023-07-11 10:38:21 +03:00
</script>
<template>
2023-07-27 15:36:52 +03:00
<component
:is="props.to ? 'router-link' : 'button'"
:to="props.to"
:type="props.type"
2023-09-20 14:09:22 +03:00
@click="clickHandler"
:class="cssClass"
2023-07-27 15:36:52 +03:00
>
2023-07-11 10:38:21 +03:00
<ui-icon v-if="props.icon" :name="props.icon" />
<div v-if="props.label" class="label">{{ props.label }}</div>
2023-07-26 14:07:17 +03:00
<slot v-if="$slots.default" name="default" />
2023-07-27 15:36:52 +03:00
</component>
2023-07-11 10:38:21 +03:00
</template>