Open
Description
Description
As a developer using Storyblok SDK I want a link component that easily handles all potential scenarios for the Storyblok link field so I don't re-write the same logic and have a faster experience developing with Storyblok and converting my components to work properly :)
Suggested solution or improvement
I'd like to add a built-in Storyblok component called StoryblokLink
that handles all of the different situations from the Storyblok link field.
Something like:
<!-- components/StoryblokLink.vue -->
<template>
<NuxtLink :to="linkMap[linkField.linktype]" :target="linkField.target" :download="linkField.linktype === 'asset' ? '' : null">
<slot />
</NuxtLink>
</template>
<script setup>
const { linkField } = defineProps({ linkField: Object })
const linkMap = {
url: linkField.url,
asset: linkField.url,
email: `mailto:${linkField.email}`,
story: linkField.story?.url,
}
</script>
Usage:
<template>
<div>
<StoryblokLink link-field="blok.my_link" class="btn">Click me!</StoryblokLink>
</div>
</template>
<script setup>
defineProps({ blok: Object })
</script>
<style>
.btn {
@apply whitespace-nowrap inline-flex justify-center items-center px-5 py-2 rounded bg-cyan-500 hover:bg-cyan-400 transition-colors;
}
</style>
Additional context
No response
Validations
- Follow our Code of Conduct