From cec2af240cdc911edc1a2adbdaff9b79a2a6960c Mon Sep 17 00:00:00 2001 From: saltysugar <49533754+saltysugar@users.noreply.github.com> Date: Wed, 31 Jul 2019 20:23:34 +0800 Subject: [PATCH] feat: update sidebar ui (#257) * update sidebar ui * fix dark theme * Update docs * Update style * Refactor * Remove unused style * Update style --- src/components/PageToc.vue | 59 ++++++++ src/components/Sidebar.vue | 24 +++- src/components/SidebarItem.vue | 183 ++++++++++++++----------- src/css/main.css | 2 + src/utils/cssVariables.js | 6 +- src/utils/markedRenderer.js | 2 +- website/docs/guide/customization.md | 8 +- website/docs/options.md | 23 +++- website/docs/zh/guide/customization.md | 11 +- website/docs/zh/options.md | 24 +++- website/index.js | 22 +-- 11 files changed, 236 insertions(+), 128 deletions(-) create mode 100644 src/components/PageToc.vue diff --git a/src/components/PageToc.vue b/src/components/PageToc.vue new file mode 100644 index 00000000..b57229ac --- /dev/null +++ b/src/components/PageToc.vue @@ -0,0 +1,59 @@ + + + + + diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 4affe906..3c620067 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -14,8 +14,8 @@ v-for="(item, index) in $store.getters.sidebar" :key="index" :item="item" - :open="currentOpenIndex === index" - @toggle="openSidebar(index)" + :open="openItems.indexOf(index) !== -1" + @toggle="toggleItem(index)" /> @@ -35,23 +35,33 @@ export default { }, data() { return { - currentOpenIndex: 0 + openItems: [] } }, watch: { '$route.path': { handler() { - this.currentOpenIndex = this.getCurrentIndex( + const index = this.getCurrentIndex( this.$route.path, this.$store.getters.sidebar ) + this.openItem(index) }, immediate: true } }, methods: { - openSidebar(index) { - this.currentOpenIndex = this.currentOpenIndex === index ? -1 : index + openItem(index) { + if (this.openItems.indexOf(index) === -1) { + this.openItems.push(index) + } + }, + toggleItem(index) { + if (this.openItems.indexOf(index) === -1) { + this.openItems.push(index) + } else { + this.openItems = this.openItems.filter(v => v !== index) + } }, getCurrentIndex(currentPath, sidebarItems) { for (let idx = 0; idx < sidebarItems.length; idx++) { @@ -63,7 +73,7 @@ export default { return idx } } - return -1 + return 0 }, getChildren(item) { return item.children || item.links || [] diff --git a/src/components/SidebarItem.vue b/src/components/SidebarItem.vue index df7a3aec..8a2f4055 100644 --- a/src/components/SidebarItem.vue +++ b/src/components/SidebarItem.vue @@ -2,60 +2,66 @@
- {{ item.title }} - + + + + + + {{ item.title }} +
+ {{ item.title }} +
+
- + +
+