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

Commit 62e8a1c

Browse files
Merge pull request #225 from Easybuoy/feature/bottom-navigation-links
Bottom navigation links
2 parents f0eed01 + 60b441f commit 62e8a1c

File tree

5 files changed

+117
-30
lines changed

5 files changed

+117
-30
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<template>
2+
<div v-show="visible === true">
3+
<CFlex justify="space-between">
4+
<div>
5+
<CLink v-if="prevName" as="router-link" class="link" :to="prevPath">
6+
<c-button left-icon="chevron-left" border-color="green.500" variant-color="green" variant="outline">
7+
{{ prevName }}
8+
</c-button>
9+
</CLink>
10+
<div v-else />
11+
</div>
12+
13+
<div>
14+
<CLink v-if="nextName" as="router-link" class="link" :to="nextPath">
15+
<c-button right-icon="chevron-right" border-color="green.500" variant-color="green" variant="outline">
16+
{{ nextName }}
17+
</c-button>
18+
</CLink>
19+
20+
<div v-else />
21+
</div>
22+
</CFlex>
23+
</div>
24+
</template>
25+
26+
<script>
27+
import { CLink, CFlex, CButton } from '@chakra-ui/vue'
28+
import { findNextAndPrevRoute } from '../utils'
29+
30+
export default {
31+
components: {
32+
CLink,
33+
CFlex,
34+
CButton
35+
},
36+
data: () => ({
37+
prevPath: '',
38+
prevName: '',
39+
nextPath: '',
40+
nextName: '',
41+
visible: true
42+
}),
43+
watch: {
44+
'$route.path' (nextPath) {
45+
const { prev, next } = findNextAndPrevRoute(nextPath)
46+
47+
this.prevPath = prev.path
48+
this.prevName = prev.name
49+
this.nextPath = next.path
50+
this.nextName = next.name
51+
}
52+
},
53+
created () {
54+
const { prev, next } = findNextAndPrevRoute(this.$route.path)
55+
56+
if (!prev.path && !next.path) {
57+
this.visible = false
58+
}
59+
this.prevPath = prev.path
60+
this.prevName = prev.name
61+
this.nextPath = next.path
62+
this.nextName = next.name
63+
console.log(this.prevName, this.nextName)
64+
}
65+
}
66+
</script>
67+
68+
<style lang="scss">
69+
.link {
70+
&:focus {
71+
box-shadow: none;
72+
}
73+
74+
&:hover {
75+
text-decoration: none;
76+
}
77+
}
78+
</style>

packages/chakra-ui-docs/components/SideNavContent.vue

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,7 @@
103103
<script>
104104
import { boxProps, CBox, CHeading, CPseudoBox } from '@chakra-ui/vue'
105105
import { stringToUrl } from '../utils'
106-
import { components as componentLinks } from '../utils/all-routes'
107-
108-
const topNavLinks = [
109-
'Getting Started',
110-
'With Nuxt',
111-
'Plugin Options',
112-
'Principles',
113-
'Style Props',
114-
'Theme',
115-
'Extending Theme',
116-
'Color Mode',
117-
'Responsive Styles',
118-
'Starters'
119-
]
120-
121-
const aboutNavLinks = [
122-
'Why Chakra UI',
123-
'Accessibility',
124-
'Constraint Based Design',
125-
'Contributing',
126-
'Recipes',
127-
'Storybook'
128-
]
106+
import { components as componentLinks, topNavLinks, aboutNavLinks } from '../utils/all-routes'
129107
130108
export default {
131109
name: 'SideNavContent',

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+
<BottomLink 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 BottomLink from '../components/BottomLink'
5658
5759
// import { stringToUrl } from '../utils'
5860
@@ -68,7 +70,8 @@ export default {
6870
Sidebar,
6971
Footer,
7072
CReset,
71-
CFlex
73+
CFlex,
74+
BottomLink
7275
},
7376
data () {
7477
return {

packages/chakra-ui-docs/utils/all-routes.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
export const components = [
9-
'Index',
109
'Accordion',
1110
'Alert',
1211
'AlertDialog',
@@ -60,23 +59,23 @@ export const components = [
6059
export const topNavLinks = [
6160
'Getting Started',
6261
'With Nuxt',
62+
'Plugin Options',
6363
'Principles',
6464
'Style Props',
65-
'Plugin Options',
6665
'Theme',
6766
'Extending Theme',
6867
'Color Mode',
6968
'Responsive Styles',
70-
'Starters',
71-
'Recipes',
72-
'Storybook'
69+
'Starters'
7370
]
7471

7572
export const aboutNavLinks = [
7673
'Why Chakra UI',
7774
'Accessibility',
7875
'Constraint Based Design',
79-
'Contributing'
76+
'Contributing',
77+
'Recipes',
78+
'Storybook'
8079
]
8180

8281
export const footerLinks = [

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { topNavLinks, components, aboutNavLinks } from './all-routes'
2+
13
export const stringToUrl = (str, path = '/') => {
24
return `${path}${str
35
.toLowerCase()
@@ -17,3 +19,30 @@ export const removeHyphenFromString = (hyphenatedString) => {
1719
const str = hyphenatedString.split('-')
1820
return str.join(' ')
1921
}
22+
23+
export const findNextAndPrevRoute = (path) => {
24+
console.log(path)
25+
const orderedRoutes = [...topNavLinks, ...aboutNavLinks, ...components]
26+
27+
let isValidRoutePath = false
28+
const extractedRoutes = []
29+
orderedRoutes.forEach((singleRoute) => {
30+
const urlString = stringToUrl(singleRoute)
31+
if (urlString === path) {
32+
isValidRoutePath = true
33+
}
34+
extractedRoutes.push({ name: singleRoute, path: urlString })
35+
})
36+
37+
console.log(isValidRoutePath)
38+
if (isValidRoutePath === false) {
39+
return { prev: '', next: '' }
40+
}
41+
42+
const currentRouteIndex = extractedRoutes.map(route => route.path).indexOf(path)
43+
44+
const nextPage = extractedRoutes[currentRouteIndex + 1]
45+
const prevPage = extractedRoutes[currentRouteIndex - 1]
46+
47+
return { prev: prevPage || '', next: nextPage || '' }
48+
}

0 commit comments

Comments
 (0)