Files
baserow/web-frontend/modules/builder/components/elements/baseComponents/ABLink.vue
56943a3601 feat: add compact menu variant to Menu element (#4059)
---------

Co-authored-by: Tsering Paljor <tsering@baserow.io>
Co-authored-by: Jeremie Pardou <571533+jrmi@users.noreply.github.com>
Co-authored-by: Jonathan Adeline <jonathan@baserow.io>
2026-06-03 17:32:23 +00:00

109 lines
2.3 KiB
Vue

<template>
<component
:is="url !== null ? 'a' : 'div'"
:class="[
{
'ab-link': variant !== 'button',
'ab-button ab-button--medium': variant === 'button',
'ab-button--full-width': variant === 'button' && fullWidth === true,
},
forceActiveClass,
]"
:target="`_${target}`"
:href="url"
:rel="isExternalLink ? 'noopener noreferrer' : null"
v-bind="$attrs"
@click="handleClick"
>
<slot></slot>
</component>
</template>
<script>
/**
* @typedef ABLink
*/
export default {
name: 'ABLink',
inject: ['mode'],
props: {
/**
* @type {string} - The variant of the link. Can be `link` (default) or `button`.
*/
variant: {
type: String,
required: false,
default: 'link',
validator(value) {
return ['link', 'button'].includes(value)
},
},
/**
* @type {Boolean} - Wheter the button should be full width.
*/
fullWidth: {
type: Boolean,
required: false,
default: false,
},
/**
* @type {string} - The target of the link. Can be `self` (default) or `blank`.
*/
target: {
type: String,
required: false,
default: 'self',
validator(value) {
return ['self', 'blank'].includes(value)
},
},
/**
* @type {string} - The URL of the link.
*/
url: {
type: String,
required: false,
default: null,
},
/**
* @type {Boolean} - Whether the active class should be applied to the link.
*/
forceActive: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
isExternalLink() {
if (this.url === null) {
return false
}
return !this.url.startsWith('/')
},
forceActiveClass() {
return this.forceActive ? `ab-${this.variant}--force-active` : ''
},
},
methods: {
handleClick(event) {
if (this.url === null) {
return
}
if (this.mode === 'editing' || !this.url) {
event.preventDefault()
return
}
if (this.target === 'self' && this.url.startsWith('/')) {
event.preventDefault()
if (this.$route.path !== this.url) {
this.$router.push(this.url)
}
}
},
},
}
</script>