feat(theme): add custom label for social links (#2466)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/2486/head
Agustin Banchio 2 years ago committed by GitHub
parent 7a2bde357d
commit c995b9f61d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -214,7 +214,9 @@ export default {
icon: { icon: {
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Dribbble</title><path d="M12...6.38z"/></svg>' svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Dribbble</title><path d="M12...6.38z"/></svg>'
}, },
link: '...' link: '...',
// You can include a custom label for accessibility too (optional but recommended):
ariaLabel: 'cool link'
} }
] ]
} }
@ -225,6 +227,7 @@ export default {
interface SocialLink { interface SocialLink {
icon: SocialLinkIcon icon: SocialLinkIcon
link: string link: string
ariaLabel?: string
} }
type SocialLinkIcon = type SocialLinkIcon =

@ -6,6 +6,7 @@ import { icons } from '../support/socialIcons'
const props = defineProps<{ const props = defineProps<{
icon: DefaultTheme.SocialLinkIcon icon: DefaultTheme.SocialLinkIcon
link: string link: string
ariaLabel?: string
}>() }>()
const svg = computed(() => { const svg = computed(() => {
@ -18,7 +19,7 @@ const svg = computed(() => {
<a <a
class="VPSocialLink" class="VPSocialLink"
:href="link" :href="link"
:aria-label="typeof icon === 'string' ? icon : ''" :aria-label="ariaLabel ?? (typeof icon === 'string' ? icon : '')"
target="_blank" target="_blank"
rel="noopener" rel="noopener"
v-html="svg" v-html="svg"

@ -10,10 +10,11 @@ defineProps<{
<template> <template>
<div class="VPSocialLinks"> <div class="VPSocialLinks">
<VPSocialLink <VPSocialLink
v-for="{ link, icon } in links" v-for="{ link, icon, ariaLabel } in links"
:key="link" :key="link"
:icon="icon" :icon="icon"
:link="link" :link="link"
:ariaLabel="ariaLabel"
/> />
</div> </div>
</template> </template>

@ -251,6 +251,7 @@ export namespace DefaultTheme {
export interface SocialLink { export interface SocialLink {
icon: SocialLinkIcon icon: SocialLinkIcon
link: string link: string
ariaLabel?: string
} }
export type SocialLinkIcon = export type SocialLinkIcon =

Loading…
Cancel
Save