Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow external links in sidebar #686

Merged
merged 2 commits into from Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/client/theme-default/components/VPSidebarGroup.vue
Expand Up @@ -6,7 +6,7 @@ import VPIconMinusSquare from './icons/VPIconMinusSquare.vue'
import VPSidebarLink from './VPSidebarLink.vue'

const props = defineProps<{
text: string
text?: string
items: DefaultTheme.SidebarItem[]
collapsible?: boolean
collapsed?: boolean
Expand All @@ -23,7 +23,12 @@ function toggle() {

<template>
<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>
<div class="action">
<VPIconMinusSquare class="icon minus" />
Expand Down
24 changes: 14 additions & 10 deletions src/client/theme-default/components/VPSidebarLink.vue
Expand Up @@ -3,6 +3,7 @@ import { inject } from 'vue'
import { useData } from 'vitepress'
import { DefaultTheme } from '../config'
import { isActive, normalizeLink } from '../support/utils'
import VPLink from './VPLink.vue'

defineProps<{
item: DefaultTheme.SidebarItem
Expand All @@ -14,37 +15,40 @@ const closeSideBar = inject('close-sidebar') as () => void
</script>

<template>
<a
class="link"
<VPLink
:class="{ active: isActive(page.relativePath, item.link) }"
:href="normalizeLink(item.link)"
@click="closeSideBar"
>
<p class="link-text">{{ item.text }}</p>
</a>
<span class="link-text">{{ item.text }}</span>
</VPLink>
</template>

<style scoped>
.link {
display: block;
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);
transition: color 0.25s;
}

.link.active .link-text {
.link.active {
color: var(--vp-c-brand);
transition: color 0.25s;
}

.link :deep(.icon) {
width: 12px;
height: 12px;
fill: currentColor;
}

.link-text {
line-height: 20px;
font-size: 14px;
font-weight: 500;
color: var(--vp-c-text-2);
transition: color 0.5s;
}
</style>
2 changes: 1 addition & 1 deletion types/default-theme.d.ts
Expand Up @@ -86,7 +86,7 @@ export namespace DefaultTheme {
}

export interface SidebarGroup {
text: string
text?: string
items: SidebarItem[]

/**
Expand Down