Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 74f4934

Browse files
committed
feat: add navigationLink functionality
1 parent 7f7d536 commit 74f4934

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed
Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
11
<template>
2-
<div />
2+
<div>
3+
<CFlex justify="space-between">
4+
<CLink as="router-link" :v-show="prev !== ''" :to="prev">
5+
Prev
6+
</CLink>
7+
8+
<CLink as="router-link" :v-show="next !== ''" :to="next">
9+
Next
10+
</CLink>
11+
</CFlex>
12+
</div>
313
</template>
414

515
<script>
6-
export default {}
16+
import { CLink, CFlex } from '@chakra-ui/vue'
17+
import { findNextAndPrevRoute } from '../utils'
18+
19+
export default {
20+
components: {
21+
CLink,
22+
CFlex
23+
},
24+
data: () => ({
25+
prev: '',
26+
next: ''
27+
}),
28+
watch: {
29+
$route (to, from) {
30+
const { prev, next } = findNextAndPrevRoute(to.path, this.$router.options.routes)
31+
32+
this.prev = prev
33+
this.next = next
34+
}
35+
},
36+
created () {
37+
const { prev, next } = findNextAndPrevRoute(this.$route.path, this.$router.options.routes)
38+
39+
this.prev = prev
40+
this.next = next
41+
}
42+
}
743
</script>
844

9-
<style>
10-
</style>
45+
<style></style>

packages/chakra-ui-docs/layouts/default.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
</keep-alive>
2929
<Footer v-if="$route.path === '/'" />
3030
<FileContributors />
31+
<BottomNavigationLink v-if="$route.path !== '/'" />
3132
</CBox>
3233
</CFlex>
3334
</CBox>
@@ -53,6 +54,7 @@ import Navbar from '../components/Navbar'
5354
import Sidebar from '../components/Sidebar'
5455
import Footer from '../components/Footer'
5556
import FileContributors from '../components/FileContributors'
57+
import BottomNavigationLink from '../components/BottomNavigationLink'
5658
5759
// import { stringToUrl } from '../utils'
5860
@@ -68,7 +70,8 @@ export default {
6870
Sidebar,
6971
Footer,
7072
CReset,
71-
CFlex
73+
CFlex,
74+
BottomNavigationLink
7275
},
7376
data () {
7477
return {

packages/chakra-ui-docs/utils/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ export const removeHyphenFromString = (hyphenatedString) => {
1717
const str = hyphenatedString.split('-')
1818
return str.join(' ')
1919
}
20+
21+
export const findNextAndPrevRoute = (path, routes) => {
22+
const currentRouteIndex = routes.map(route => route.path).indexOf(path)
23+
24+
const nextPageLink = routes[currentRouteIndex + 1]
25+
const prevPageLink = routes[currentRouteIndex - 1]
26+
27+
return { prev: prevPageLink.path, next: nextPageLink.path }
28+
}

0 commit comments

Comments
 (0)