1
1
import React from 'react' ;
2
2
import fetch from 'isomorphic-unfetch' ;
3
+ import styled from 'react-emotion' ;
3
4
import { space } from 'styled-system' ;
4
5
import { Flex , Box } from 'grid-emotion' ;
5
- import styled from 'react-emotion' ;
6
+ import ExpandTOC from 'react-icons/lib/fa/angle-double-right' ;
7
+ import CollapseTOC from 'react-icons/lib/fa/angle-double-left' ;
6
8
7
9
import { baseContainer , Title , breakpoints } from '../../utils/base.styles' ;
8
10
import Layout from '../../components/common/layout' ;
9
11
import BannerSection from '../../components/learn/subject-banner' ;
10
12
import SyllabusTree from '../../components/learn/syllabus-tree/syllabus-tree-container' ;
11
13
import SubjectMarkdown from '../../components/learn/subject-marked' ;
12
- import FloatingSyllabus from '../../components/learn/floating-syllabus' ;
13
14
14
15
import { laravelSyllabus } from '../../utils/mock-data' ;
15
16
@@ -21,9 +22,7 @@ const CurriculumSection = styled.section`
21
22
background-color: #fff;
22
23
& .box_toc {
23
24
border-right: 1px solid #f5f5f5;
24
- ${ breakpoints . xs } {
25
- display: none;
26
- }
25
+ min-width: 250px;
27
26
}
28
27
& .toc_title {
29
28
background-color: #374355;
@@ -36,6 +35,28 @@ const CurriculumSection = styled.section`
36
35
}
37
36
` ;
38
37
38
+ const Fab = styled . div `
39
+ position: sticky;
40
+ top: 0.5rem;
41
+ z-index: 3;
42
+ left: 0;
43
+ margin-top: 0.5rem;
44
+ top: 3rem;
45
+ display: none;
46
+ & .fab_symbol {
47
+ opacity: 0.5;
48
+ padding: 0.05rem;
49
+ border-radius: 0 5px 5px 0;
50
+ background: #fff;
51
+ border: 0.5px solid #555;
52
+ width: 1.2rem;
53
+ height: 2rem;
54
+ }
55
+ ${ breakpoints . xs } {
56
+ display: inherit;
57
+ }
58
+ ` ;
59
+
39
60
const defaultChapter = laravelSyllabus [ 0 ] . chapters [ 0 ] ;
40
61
41
62
export default class Subject extends React . Component {
@@ -45,6 +66,7 @@ export default class Subject extends React.Component {
45
66
activeChapterContent : '' ,
46
67
activeChapterName : defaultChapter . name ,
47
68
loading : true ,
69
+ isSidebarOpen : true ,
48
70
} ;
49
71
}
50
72
@@ -78,14 +100,22 @@ export default class Subject extends React.Component {
78
100
subTitle = "Web Development"
79
101
icon = "devicon-laravel-plain colored"
80
102
/>
81
- < FloatingSyllabus />
82
103
< CurriculumSection my = { [ 0 , 4 ] } >
83
104
< Flex column = { false } >
84
- < Box width = { [ 0 , 0.2 ] } className = "box_toc" >
85
- < div className = "toc_title" > Table of content</ div >
86
- < SyllabusTree data = { laravelSyllabus } changeChapter = { this . changeChapter } />
87
- </ Box >
88
- < Box width = { [ 1 , 0.8 ] } px = { [ 1 , 2 ] } >
105
+ { this . state . isSidebarOpen ? (
106
+ < Box width = { [ 0 , 0.2 ] } flex = { '1 1 auto' } className = "box_toc" >
107
+ < div className = "toc_title" > Table of content</ div >
108
+ < SyllabusTree data = { laravelSyllabus } changeChapter = { this . changeChapter } />
109
+ </ Box >
110
+ ) : null }
111
+ < Box width = { [ 1 , 0.8 ] } flex = { '1 1 auto' } px = { [ 1 , 2 ] } className = "box_content" >
112
+ < Fab onClick = { ( ) => this . setState ( { isSidebarOpen : ! this . state . isSidebarOpen } ) } >
113
+ { this . state . isSidebarOpen ? (
114
+ < CollapseTOC className = "fab_symbol" />
115
+ ) : (
116
+ < ExpandTOC className = "fab_symbol" />
117
+ ) }
118
+ </ Fab >
89
119
< h2 className = "chapter_name" > { this . state . activeChapterName } </ h2 >
90
120
< SubjectMarkdown loading = { this . state . loading } markdown = { this . state . activeChapterContent } />
91
121
</ Box >
0 commit comments