Skip to content

Commit

Permalink
feat: collapsible docs (#438)
Browse files Browse the repository at this point in the history
* ✨ (nav) add releases to resources

* ✨ (releases) hide releases page from nav

* ✨ (resources) update code sandbox icon

* 🐛 (aside) make aside sticky again

* 📝 (collapse) collapse docs to avoid scrolling on nav when landing

* docs: collapse get started

* fix: rename to `collapse`

Co-authored-by: Farnabaz <farnabaz@gmail.com>
  • Loading branch information
Tahul and farnabaz authored Jun 16, 2021
1 parent b9243a1 commit 371b5f3
Show file tree
Hide file tree
Showing 32 changed files with 78 additions and 30 deletions.
19 changes: 19 additions & 0 deletions docs/components/AsideBottom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
<h5 class="py-2 text-base font-semibold text-gray-900 cursor-pointer dark:text-gray-100">Resources</h5>
<ul>
<li v-for="resource of resources" :key="resource.title">
<!-- Href links via `url` -->
<a
v-if="!resource.to"
:href="resource.url"
:to="resource.to"
target="_blank"
rel="noopener nofollow"
class="flex items-center py-1.5 group dark:hover:text-gray-100 hover:text-gray-900"
Expand All @@ -13,6 +16,17 @@
<span>{{ resource.title }}</span>
<IconExternalLink class="w-4 h-4 ml-2 text-gray-400 opacity-0 group-hover:opacity-100" />
</a>

<!-- Local links via `to` -->
<NuxtLink
v-else
:to="resource.to"
class="flex items-center py-1.5 group dark:hover:text-gray-100 hover:text-gray-900"
>
<Component :is="resource.icon" v-if="resource.icon" class="w-5 h-5 mr-2" :class="resource.iconClass" />
<span>{{ resource.title }}</span>
<IconExternalLink class="w-4 h-4 ml-2 text-gray-400 opacity-0 group-hover:opacity-100" />
</NuxtLink>
</li>
</ul>
</div>
Expand All @@ -25,6 +39,11 @@ export default defineComponent({
setup() {
return {
resources: [
{
title: 'Releases',
to: '/releases',
icon: 'IconGit'
},
{
title: 'NuxtJS',
url: 'https://nuxtjs.org',
Expand Down
7 changes: 7 additions & 0 deletions docs/components/icons/IconGit.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<svg fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24px" height="24px">
<path
d="M 6 2 C 4.346 2 3 3.346 3 5 C 3 6.3016094 3.8387486 7.4021391 5 7.8164062 L 5 15 C 5 17.749516 7.2504839 20 10 20 L 11 20 L 11 21.025391 C 11 21.512391 11.588594 21.757109 11.933594 21.412109 L 13.755859 19.591797 C 14.082859 19.264797 14.082859 18.735203 13.755859 18.408203 L 11.933594 16.587891 C 11.588594 16.243891 11 16.487609 11 16.974609 L 11 18 L 10 18 C 8.3315161 18 7 16.668484 7 15 L 7 7.8164062 C 8.1612514 7.4021391 9 6.3016094 9 5 C 9 3.346 7.654 2 6 2 z M 12.357422 2.4335938 C 12.253687 2.4514844 12.152656 2.5018906 12.066406 2.5878906 L 10.244141 4.4082031 C 9.9171406 4.7352031 9.9171406 5.2647969 10.244141 5.5917969 L 12.066406 7.4121094 C 12.411406 7.7571094 13 7.5123906 13 7.0253906 L 13 6 L 14 6 C 15.668484 6 17 7.3315161 17 9 L 17 16.183594 C 15.838749 16.597861 15 17.698391 15 19 C 15 20.654 16.346 22 18 22 C 19.654 22 21 20.654 21 19 C 21 17.698391 20.161251 16.597861 19 16.183594 L 19 9 C 19 6.2504839 16.749516 4 14 4 L 13 4 L 13 2.9746094 C 13 2.6093594 12.668625 2.3799219 12.357422 2.4335938 z"
/>
</svg>
</template>
4 changes: 4 additions & 0 deletions docs/content/1.get-started/0.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
navigation:
collapse: true
---
4 changes: 4 additions & 0 deletions docs/content/2.writing/0.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
navigation:
collapse: true
---
4 changes: 4 additions & 0 deletions docs/content/3.features/0.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
navigation:
collapse: true
---
4 changes: 4 additions & 0 deletions docs/content/4.theme/0.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
navigation:
collapse: true
---
5 changes: 5 additions & 0 deletions docs/content/5.templates/0.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
navigation:
collapse: true
redirect: /writing/my-first-page
---
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions docs/content/releases.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
navigation: false
template: releases
---

Expand Down
2 changes: 1 addition & 1 deletion nuxtjs.org/content/0.docs/1.get-started/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: false
collapse: false
redirect: /docs/get-started/installation
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/0.docs/2.concepts/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /docs/concepts/views
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/0.docs/3.features/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /docs/features/rendering-modes
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/0.docs/4.directory-structure/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /docs/directory-structure/nuxt
---
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /docs/configuration-glossary/configuration-alias
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/0.docs/6.internals-glossary/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /docs/internals-glossary/context
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/0.docs/7.components-glossary/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /docs/components-glossary/fetch
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/0.docs/8.deployment/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /docs/deployment/21yunbox
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/1.routing/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: false
collapse: false
redirect: /examples/routing/hello-world
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/10.modules/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /examples/modules/local
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/2.data-fetching/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /examples/data-fetching/async-data
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/3.assets-management/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /examples/assets-management/pre-processors
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/4.transitions/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /examples/transitions/transitions
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/5.seo/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /examples/seo/html-head
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/6.loading/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /examples/loading/customize-nuxt-loading
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/7.miscellaneous/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /examples/miscellaneous/layouts
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/8.middlewares/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /examples/middlewares/router
---
2 changes: 1 addition & 1 deletion nuxtjs.org/content/1.examples/9.plugins/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
navigation:
collapsed: true
collapse: true
redirect: /examples/plugins/vue
---
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<svg preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 296">
<path
d="M115.498 261.088v-106.61L23.814 101.73v60.773l41.996 24.347v45.7l49.688 28.54zm23.814.627l50.605-29.151V185.78l42.269-24.495v-60.011l-92.874 53.621v106.82zm80.66-180.887l-48.817-28.289l-42.863 24.872l-43.188-24.897l-49.252 28.667l91.914 52.882l92.206-53.235zM0 222.212V74.495L127.987 0L256 74.182v147.797l-128.016 73.744L0 222.212z"
fill="#000"
fill="currentColor"
/>
</svg>
</template>
4 changes: 2 additions & 2 deletions src/defaultTheme/components/molecules/AsideNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
overflow-auto
pointer-events-auto
min-h-fill-available
lg:sticky lg:top-header lg:w-60 lg:max-h-[400vh]
lg:h-screen lg:sticky lg:top-header lg:w-60
"
>
<div class="w-auto h-full overflow-auto bg-white dark:bg-gray-900 dark:lg:bg-transparent lg:bg-transparent">
Expand Down Expand Up @@ -64,7 +64,7 @@
:key="link.navigation.title"
:title="link.navigation.title"
:docs="link.children"
:collapsed="link.navigation.collapsed"
:collapse="link.navigation.collapse"
/>
<AsideNavigationItem v-else :key="link.navigation.title" :docs="[link]" />
</template>
Expand Down
16 changes: 8 additions & 8 deletions src/defaultTheme/components/molecules/AsideNavigationItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
v-if="title"
class="py-2 text-base font-semibold text-gray-900 cursor-pointer dark:text-gray-100"
:class="[isActive ? '' : 'hover:text-gray-600 dark:hover:text-gray-400']"
@click="collapse"
@click="toggle"
>
{{ title }}
</h5>
<ul v-if="!isCollapse || isActive" class="mb-2 ml-2">
<ul v-if="!isCollapsed || isActive" class="mb-2 ml-2">
<li v-for="doc of docs" :key="doc.to">
<NuxtLink
:to="$contentLocalePath(doc.navigation.redirect || doc.to)"
Expand Down Expand Up @@ -62,24 +62,24 @@ export default defineComponent({
type: Array,
required: true
},
collapsed: {
collapse: {
type: Boolean,
default: false
}
},
setup(props) {
const { $docus } = useContext()
const isCollapse = ref(props.collapsed)
const isCollapsed = ref(props.collapse)
const isActive = computed(() => props.docs.some(document => $docus.isLinkActive(document.to)))
const collapse = () => {
const toggle = () => {
if (isActive.value) {
return
}
isCollapse.value = !isCollapse.value
isCollapsed.value = !isCollapsed.value
}
const isDocumentNew = document => {
Expand All @@ -95,9 +95,9 @@ export default defineComponent({
}
return {
collapse,
toggle,
isActive,
isCollapse,
isCollapsed,
isDocumentNew
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface NavItemNavigationConfig {
nested: boolean
slot: string
exclusive: boolean
// Collapsed aside navigation by default
// Collapse aside navigation by default
collapse: boolean
// Useful for directories `index.md` which are empty pages, to get redirect to another page
redirect: string
Expand Down

0 comments on commit 371b5f3

Please sign in to comment.