1
- import React , { FC } from 'react'
2
- import { CNav } from '@coreui/react/src/index'
1
+ import React , { FC , useState } from 'react'
2
+ import { CCollapse , CNav } from '@coreui/react/src/index'
3
3
4
4
type TocItem = {
5
5
url : string
@@ -11,34 +11,58 @@ interface TocProps {
11
11
items : TocItem [ ]
12
12
}
13
13
14
- const Toc : FC < TocProps > = ( { items } ) => {
15
- const toc = ( items : TocItem [ ] ) => {
16
- return (
17
- items &&
18
- items . map ( ( item , index ) => {
19
- if ( Array . isArray ( item . items ) ) {
20
- return (
21
- < li key = { index } >
22
- < a href = { item . url } > { item . title } </ a >
23
- < ul > { toc ( item . items ) } </ ul >
24
- </ li >
25
- )
26
- }
14
+ const toc = ( items : TocItem [ ] ) => {
15
+ return (
16
+ items &&
17
+ items . map ( ( item , index ) => {
18
+ if ( Array . isArray ( item . items ) ) {
27
19
return (
28
20
< li key = { index } >
29
21
< a href = { item . url } > { item . title } </ a >
22
+ < ul > { toc ( item . items ) } </ ul >
30
23
</ li >
31
24
)
32
- } )
33
- )
34
- }
25
+ }
26
+ return (
27
+ < li key = { index } >
28
+ < a href = { item . url } > { item . title } </ a >
29
+ </ li >
30
+ )
31
+ } )
32
+ )
33
+ }
35
34
35
+ const Toc : FC < TocProps > = ( { items } ) => {
36
+ const [ visible , setVisible ] = useState ( false )
36
37
return (
37
38
< div className = "docs-toc mt-4 mb-5 my-md-0 ps-xl-5 mb-lg-5 text-body-secondary" >
38
- < strong className = "d-block h6 mb-2 pb-2 border-bottom" > On this page</ strong >
39
- < CNav as = "nav" className = "flex-column" >
40
- < ul > { toc ( items ) } </ ul >
41
- </ CNav >
39
+ < button
40
+ className = "btn btn-link p-md-0 mb-2 mb-md-0 text-decoration-none docs-toc-toggle d-md-none"
41
+ type = "button"
42
+ aria-expanded = { visible ? true : false }
43
+ aria-controls = "tocContents"
44
+ onClick = { ( ) => setVisible ( ! visible ) }
45
+ >
46
+ On this page
47
+ < svg
48
+ xmlns = "http://www.w3.org/2000/svg"
49
+ className = "icon d-md-none ms-2"
50
+ aria-hidden = "true"
51
+ viewBox = "0 0 512 512"
52
+ >
53
+ < polygon
54
+ fill = "var(--ci-primary-color, currentColor)"
55
+ points = "256 382.627 60.687 187.313 83.313 164.687 256 337.372 428.687 164.687 451.313 187.313 256 382.627"
56
+ className = "ci-primary"
57
+ />
58
+ </ svg >
59
+ </ button >
60
+ < strong className = "d-none d-md-block h6 mb-2 pb-2 border-bottom" > On this page</ strong >
61
+ < CCollapse className = "docs-toc-collapse" id = "tocContents" visible = { visible } >
62
+ < CNav as = "nav" >
63
+ < ul > { toc ( items ) } </ ul >
64
+ </ CNav >
65
+ </ CCollapse >
42
66
</ div >
43
67
)
44
68
}
0 commit comments