This repository was archived by the owner on Sep 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +117
-30
lines changed Expand file tree Collapse file tree 5 files changed +117
-30
lines changed Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change 103
103
<script >
104
104
import { boxProps , CBox , CHeading , CPseudoBox } from ' @chakra-ui/vue'
105
105
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'
129
107
130
108
export default {
131
109
name: ' SideNavContent' ,
Original file line number Diff line number Diff line change 28
28
</keep-alive >
29
29
<Footer v-if =" $route.path === '/'" />
30
30
<FileContributors />
31
+ <BottomLink v-if =" $route.path !== '/'" />
31
32
</CBox >
32
33
</CFlex >
33
34
</CBox >
@@ -53,6 +54,7 @@ import Navbar from '../components/Navbar'
53
54
import Sidebar from ' ../components/Sidebar'
54
55
import Footer from ' ../components/Footer'
55
56
import FileContributors from ' ../components/FileContributors'
57
+ import BottomLink from ' ../components/BottomLink'
56
58
57
59
// import { stringToUrl } from '../utils'
58
60
@@ -68,7 +70,8 @@ export default {
68
70
Sidebar,
69
71
Footer,
70
72
CReset,
71
- CFlex
73
+ CFlex,
74
+ BottomLink
72
75
},
73
76
data () {
74
77
return {
Original file line number Diff line number Diff line change 6
6
*/
7
7
8
8
export const components = [
9
- 'Index' ,
10
9
'Accordion' ,
11
10
'Alert' ,
12
11
'AlertDialog' ,
@@ -60,23 +59,23 @@ export const components = [
60
59
export const topNavLinks = [
61
60
'Getting Started' ,
62
61
'With Nuxt' ,
62
+ 'Plugin Options' ,
63
63
'Principles' ,
64
64
'Style Props' ,
65
- 'Plugin Options' ,
66
65
'Theme' ,
67
66
'Extending Theme' ,
68
67
'Color Mode' ,
69
68
'Responsive Styles' ,
70
- 'Starters' ,
71
- 'Recipes' ,
72
- 'Storybook'
69
+ 'Starters'
73
70
]
74
71
75
72
export const aboutNavLinks = [
76
73
'Why Chakra UI' ,
77
74
'Accessibility' ,
78
75
'Constraint Based Design' ,
79
- 'Contributing'
76
+ 'Contributing' ,
77
+ 'Recipes' ,
78
+ 'Storybook'
80
79
]
81
80
82
81
export const footerLinks = [
Original file line number Diff line number Diff line change
1
+ import { topNavLinks , components , aboutNavLinks } from './all-routes'
2
+
1
3
export const stringToUrl = ( str , path = '/' ) => {
2
4
return `${ path } ${ str
3
5
. toLowerCase ( )
@@ -17,3 +19,30 @@ export const removeHyphenFromString = (hyphenatedString) => {
17
19
const str = hyphenatedString . split ( '-' )
18
20
return str . join ( ' ' )
19
21
}
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
+ }
You can’t perform that action at this time.
0 commit comments