feat: allow external links in sidebar (#205) (#686)

close #205

Co-authored-by: Kia Ishii <kia.king.08@gmail.com>
pull/731/head
Divyansh Singh 2 years ago committed by GitHub
parent 86690fa1ac
commit ce17f5035c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,7 @@ import VPIconMinusSquare from './icons/VPIconMinusSquare.vue'
import VPSidebarLink from './VPSidebarLink.vue' import VPSidebarLink from './VPSidebarLink.vue'
const props = defineProps<{ const props = defineProps<{
text: string text?: string
items: DefaultTheme.SidebarItem[] items: DefaultTheme.SidebarItem[]
collapsible?: boolean collapsible?: boolean
collapsed?: boolean collapsed?: boolean
@ -23,7 +23,12 @@ function toggle() {
<template> <template>
<section class="VPSidebarGroup" :class="{ collapsible, collapsed }"> <section class="VPSidebarGroup" :class="{ collapsible, collapsed }">
<div class="title" :role="collapsible ? 'button' : undefined" @click="toggle"> <div
v-if="text"
class="title"
:role="collapsible ? 'button' : undefined"
@click="toggle"
>
<h2 class="title-text">{{ text }}</h2> <h2 class="title-text">{{ text }}</h2>
<div class="action"> <div class="action">
<VPIconMinusSquare class="icon minus" /> <VPIconMinusSquare class="icon minus" />

@ -3,6 +3,7 @@ import { inject } from 'vue'
import { useData } from 'vitepress' import { useData } from 'vitepress'
import { DefaultTheme } from '../config' import { DefaultTheme } from '../config'
import { isActive, normalizeLink } from '../support/utils' import { isActive, normalizeLink } from '../support/utils'
import VPLink from './VPLink.vue'
defineProps<{ defineProps<{
item: DefaultTheme.SidebarItem item: DefaultTheme.SidebarItem
@ -14,37 +15,40 @@ const closeSideBar = inject('close-sidebar') as () => void
</script> </script>
<template> <template>
<a <VPLink
class="link"
:class="{ active: isActive(page.relativePath, item.link) }" :class="{ active: isActive(page.relativePath, item.link) }"
:href="normalizeLink(item.link)" :href="normalizeLink(item.link)"
@click="closeSideBar" @click="closeSideBar"
> >
<p class="link-text">{{ item.text }}</p> <span class="link-text">{{ item.text }}</span>
</a> </VPLink>
</template> </template>
<style scoped> <style scoped>
.link { .link {
display: block; display: block;
padding: 6px 0; padding: 6px 0;
color: var(--vp-c-text-2);
transition: color 0.5s;
} }
.link:hover .link-text { .link:hover {
color: var(--vp-c-text-1); color: var(--vp-c-text-1);
transition: color 0.25s;
} }
.link.active .link-text { .link.active {
color: var(--vp-c-brand); color: var(--vp-c-brand);
transition: color 0.25s; }
.link :deep(.icon) {
width: 12px;
height: 12px;
fill: currentColor;
} }
.link-text { .link-text {
line-height: 20px; line-height: 20px;
font-size: 14px; font-size: 14px;
font-weight: 500; font-weight: 500;
color: var(--vp-c-text-2);
transition: color 0.5s;
} }
</style> </style>

@ -93,7 +93,7 @@ export namespace DefaultTheme {
} }
export interface SidebarGroup { export interface SidebarGroup {
text: string text?: string
items: SidebarItem[] items: SidebarItem[]
/** /**

Loading…
Cancel
Save