Skip to content

Commit

Permalink
Merge pull request #97 from Realityloop/feature/4-navigation_card
Browse files Browse the repository at this point in the history
feat(#4): add external link icon
  • Loading branch information
Decipher authored Aug 7, 2023
2 parents fba3b0d + eeabf9e commit c53ddd0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
76 changes: 37 additions & 39 deletions src/components/Link.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<template>
<!-- External link -->
<a
v-if="isExternal"
<component
:is="component"
:class="classes"
:disabled="disabled"
:href="link"
:title="title"
v-bind="props"
>
<CTIcon
v-if="icon && iconPosition === 'before'"
class="ct-button__icon"
class="ct-link__icon"
:size="iconSize"
:symbol="icon"
/>
Expand All @@ -21,40 +18,16 @@

<CTIcon
v-if="icon && iconPosition === 'after'"
class="ct-button__icon"
class="ct-link__icon"
:size="iconSize"
:symbol="icon"
/>
</a>

<!-- Internal link -->
<NuxtLink
v-else
:class="classes"
:disabled="disabled"
tag="a"
:title="title"
:to="link"
>
<CTIcon
v-if="icon && iconPosition === 'before'"
class="ct-button__icon"
:size="iconSize"
:symbol="icon"
/>

<slot v-if="!text || $slots.default" />
<template v-else>
{{ text }}
</template>

<CTIcon
v-if="icon && iconPosition === 'after'"
class="ct-button__icon"
:size="iconSize"
:symbol="icon"
/>
</NuxtLink>
<span
v-if="props.target === '_blank'"
class="ct-visually-hidden"
>(Opens in a new tab/window)</span>
</component>
</template>

<script>
Expand All @@ -68,6 +41,10 @@ export default {
type: Boolean,
default: undefined
},
external: {
type: Boolean,
default: undefined
},
icon: {
type: String,
default: undefined
Expand All @@ -84,6 +61,10 @@ export default {
type: String,
default: '#'
},
target: {
type: String,
default: undefined
},
text: {
type: String,
default: 'link'
Expand All @@ -95,12 +76,29 @@ export default {
},
computed: {
classes: ({ disabled, themeClass }) => ({
classes: ({ disabled, isExternal, themeClass }) => ({
'ct-link': true,
'ct-link--disabled': disabled,
'ct-link--external': isExternal,
[themeClass]: true
}),
isExternal: ({ link }) => !(link || '').startsWith('/')
component: ({ isExternal }) => isExternal ? 'a': 'NuxtLink',
isExternal: ({ external, link }) => external || !['/', '#'].includes(link[0]),
props: ({ component, disabled, link, target, title }) => ({
disabled,
title,
...{
a: {
href: link,
target: target || '_blank'
},
NuxtLink: {
tag: 'a',
target,
to: link
}
}[component]
})
}
}
</script>
10 changes: 8 additions & 2 deletions src/components/NavigationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
>
<CTLink
class="ct-navigation-card__title__link"
:external="linkExternal"
:link="link"
:text="title"
:theme="theme"
icon="right-arrow-2"
:icon="linkIcon"
/>
</CTHeading>

Expand Down Expand Up @@ -90,6 +91,10 @@ export default {
type: String,
default: '#'
},
linkExternal: {
type: Boolean,
default: undefined,
},
summary: {
type: String,
default: undefined,
Expand All @@ -101,7 +106,8 @@ export default {
},
computed: {
hasImage: ({ $scopedSlots, imageSrc }) => imageSrc || $scopedSlots.image
hasImage: ({ $scopedSlots, imageSrc }) => imageSrc || $scopedSlots.image,
linkIcon: ({ linkExternal }) => linkExternal ? 'upper-right-arrow' : 'right-arrow-2',
}
}
</script>

0 comments on commit c53ddd0

Please sign in to comment.