Skip to content

Commit 1382435

Browse files
authored
Merge pull request infinitered#605 from alin23/toggle-sidebar
Add Sidebar toggle icon and shortcut
2 parents c261c8a + 437a681 commit 1382435

File tree

9 files changed

+108
-14
lines changed

9 files changed

+108
-14
lines changed

packages/reactotron-app/App/Foundation/BackupsHeader.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Colors from '../Theme/Colors'
33
import AppStyles from '../Theme/AppStyles'
44
import { inject, observer } from 'mobx-react'
55
import IconAdd from 'react-icons/lib/md/file-download'
6+
import SidebarToggleButton from './SidebarToggleButton'
67

78
const TITLE = 'State Snapshots'
89

@@ -27,7 +28,8 @@ const Styles = {
2728
},
2829
left: {
2930
...AppStyles.Layout.hbox,
30-
width: 100
31+
width: 100,
32+
alignItems: 'center'
3133
},
3234
right: {
3335
width: 100,
@@ -60,7 +62,9 @@ class BackupsHeader extends Component {
6062
return (
6163
<div style={Styles.container}>
6264
<div style={Styles.content}>
63-
<div style={Styles.left} />
65+
<div style={Styles.left}>
66+
<SidebarToggleButton onClick={ui.toggleSidebar} isSidebarVisible={ui.isSidebarVisible} />
67+
</div>
6468
<div style={Styles.center}>
6569
<div style={Styles.title}>{TITLE}</div>
6670
</div>

packages/reactotron-app/App/Foundation/HelpHeader.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component } from 'react'
22
import Colors from '../Theme/Colors'
33
import AppStyles from '../Theme/AppStyles'
44
import { inject, observer } from 'mobx-react'
5+
import SidebarToggleButton from './SidebarToggleButton'
56

67
const TITLE = 'Using Reactotron'
78

@@ -15,9 +16,22 @@ const Styles = {
1516
},
1617
content: {
1718
height: 60,
19+
paddingLeft: 10,
20+
paddingRight: 10,
1821
...AppStyles.Layout.hbox,
1922
alignItems: 'center',
20-
justifyContent: 'center'
23+
justifyContent: 'space-between'
24+
},
25+
left: {
26+
...AppStyles.Layout.hbox,
27+
width: 100,
28+
alignItems: 'center'
29+
},
30+
right: {
31+
width: 100,
32+
...AppStyles.Layout.hbox,
33+
justifyContent: 'flex-end',
34+
alignItems: 'center'
2135
},
2236
title: {
2337
color: Colors.foregroundLight,
@@ -27,16 +41,24 @@ const Styles = {
2741

2842
@inject('session')
2943
@observer
30-
class TimelineHeader extends Component {
44+
class HelpHeader extends Component {
3145
render () {
46+
const { ui } = this.props.session
47+
3248
return (
3349
<div style={Styles.container}>
3450
<div style={Styles.content}>
35-
<div style={Styles.title}>{TITLE}</div>
51+
<div style={Styles.left}>
52+
<SidebarToggleButton onClick={ui.toggleSidebar} isSidebarVisible={ui.isSidebarVisible} />
53+
</div>
54+
<div style={Styles.center}>
55+
<div style={Styles.title}>{TITLE}</div>
56+
</div>
57+
<div style={Styles.right} />
3658
</div>
3759
</div>
3860
)
3961
}
4062
}
4163

42-
export default TimelineHeader
64+
export default HelpHeader

packages/reactotron-app/App/Foundation/HelpKeystrokes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ const HelpKeystrokes = () => (
130130
</div>
131131
<div style={Styles.helpDetail}>clear the timeline</div>
132132
</div>
133+
<div style={Styles.helpShortcut}>
134+
<div style={Styles.helpLabel}>
135+
<Key text={Keystroke.modifierName} />+<Key text='⬆' />+<Key text='S' />
136+
</div>
137+
<div style={Styles.helpDetail}>toggle sidebar</div>
138+
</div>
133139
</div>
134140
</div>
135141
</div>

packages/reactotron-app/App/Foundation/NativeHeader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component } from 'react'
22
import Colors from '../Theme/Colors'
33
import AppStyles from '../Theme/AppStyles'
44
import { inject, observer } from 'mobx-react'
5+
import SidebarToggleButton from './SidebarToggleButton'
56

67
const TITLE = 'React Native'
78

@@ -26,7 +27,8 @@ const Styles = {
2627
},
2728
left: {
2829
...AppStyles.Layout.hbox,
29-
width: 100
30+
width: 100,
31+
alignItems: 'center'
3032
},
3133
right: {
3234
width: 100,
@@ -54,10 +56,14 @@ const Styles = {
5456
@observer
5557
class NativeHeader extends Component {
5658
render () {
59+
const { ui } = this.props.session
60+
5761
return (
5862
<div style={Styles.container}>
5963
<div style={Styles.content}>
60-
<div style={Styles.left} />
64+
<div style={Styles.left}>
65+
<SidebarToggleButton onClick={ui.toggleSidebar} isSidebarVisible={ui.isSidebarVisible} />
66+
</div>
6167
<div style={Styles.center}>
6268
<div style={Styles.title}>{TITLE}</div>
6369
</div>

packages/reactotron-app/App/Foundation/Sidebar.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const Styles = {
1111
backgroundColor: Colors.backgroundSubtleDark,
1212
boxShadow: `0px 0px 30px ${Colors.glow}`,
1313
borderRight: `1px solid ${Colors.chromeLine}`,
14-
WebkitAppRegion: 'drag'
14+
WebkitAppRegion: 'drag',
15+
transition: 'margin 0.2s ease-out'
1516
},
1617
content: {
1718
...AppStyles.Layout.vbox,
@@ -56,7 +57,7 @@ class Sidebar extends Component {
5657
const { ui } = session
5758

5859
return (
59-
<div style={Styles.container}>
60+
<div style={{...Styles.container, ...(!ui.isSidebarVisible ? { marginLeft: -Styles.container.maxWidth } : {})}}>
6061
<div style={Styles.content}>
6162
<div style={Styles.tabs}>
6263
<SidebarButton
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react'
2+
import IconArrowBack from 'react-icons/lib/md/arrow-back'
3+
4+
const Styles = {
5+
iconSize: 32,
6+
sidebarIcon: { paddingRight: 7, cursor: 'pointer', transition: 'transform 0.2s ease-in 0.2s, margin 0.2s' },
7+
sidebarHiddenIcon: { transform: 'rotate(0.5turn)', marginTop: 20 }
8+
}
9+
10+
const SidebarToggleButton = props => {
11+
const sidebarIconStyle = {
12+
...Styles.sidebarIcon,
13+
...(props.isSidebarVisible ? {} : Styles.sidebarHiddenIcon)
14+
}
15+
16+
return (
17+
<IconArrowBack
18+
size={Styles.iconSize}
19+
style={sidebarIconStyle}
20+
onClick={props.onClick}
21+
/>
22+
)
23+
}
24+
25+
export default SidebarToggleButton

packages/reactotron-app/App/Foundation/SubscriptionsHeader.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import AppStyles from '../Theme/AppStyles'
44
import { inject, observer } from 'mobx-react'
55
import IconAdd from 'react-icons/lib/md/add'
66
import IconClear from 'react-icons/lib/md/delete-forever'
7+
import SidebarToggleButton from './SidebarToggleButton'
78

89
const TITLE = 'State Subscriptions'
910

@@ -28,7 +29,8 @@ const Styles = {
2829
},
2930
left: {
3031
...AppStyles.Layout.hbox,
31-
width: 100
32+
width: 100,
33+
alignItems: 'center'
3234
},
3335
right: {
3436
width: 100,
@@ -64,7 +66,9 @@ class SubscriptionsHeader extends Component {
6466
return (
6567
<div style={Styles.container}>
6668
<div style={Styles.content}>
67-
<div style={Styles.left} />
69+
<div style={Styles.left}>
70+
<SidebarToggleButton onClick={ui.toggleSidebar} isSidebarVisible={ui.isSidebarVisible} />
71+
</div>
6872
<div style={Styles.center}>
6973
<div style={Styles.title}>{TITLE}</div>
7074
</div>

packages/reactotron-app/App/Foundation/TimelineHeader.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { inject, observer } from 'mobx-react'
66
import IconFilter from 'react-icons/lib/md/filter-list'
77
import IconClear from 'react-icons/lib/md/delete-sweep'
88
import IconSearch from 'react-icons/lib/md/search'
9+
import SidebarToggleButton from './SidebarToggleButton'
910

1011
const TITLE = 'Timeline'
1112

@@ -28,7 +29,7 @@ const Styles = {
2829
...AppStyles.Layout.hbox,
2930
justifyContent: 'space-between'
3031
},
31-
left: { ...AppStyles.Layout.hbox, width: 100 },
32+
left: { ...AppStyles.Layout.hbox, width: 100, alignItems: 'center' },
3233
right: { ...AppStyles.Layout.hbox, justifyContent: 'flex-end', alignItems: 'center', width: 100 },
3334
center: { ...AppStyles.Layout.vbox, flex: 1, alignItems: 'center', justifyContent: 'center' },
3435
title: { color: Colors.foregroundLight, textAlign: 'center' },
@@ -115,7 +116,9 @@ class TimelineHeader extends Component {
115116
return (
116117
<div style={Styles.container}>
117118
<div style={Styles.content}>
118-
<div style={Styles.left} />
119+
<div style={Styles.left}>
120+
<SidebarToggleButton onClick={ui.toggleSidebar} isSidebarVisible={ui.isSidebarVisible} />
121+
</div>
119122
<div style={Styles.center}>
120123
<div style={Styles.title}>{TITLE}</div>
121124
</div>

packages/reactotron-app/App/Stores/UiStore.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class UI {
5757
// show the timeline search
5858
@observable isTimelineSearchVisible = false
5959

60+
// hide the sidebar
61+
@observable isSidebarVisible = true
62+
6063
/**
6164
* The current search phrase used to narrow down visible commands.
6265
*/
@@ -89,6 +92,7 @@ class UI {
8992
Mousetrap.bind(`${Keystroke.mousetrap}+?`, this.switchTab.bind(this, 'help'))
9093
Mousetrap.bind(`${Keystroke.mousetrap}+f`, this.showTimelineSearch)
9194
Mousetrap.bind(`${Keystroke.mousetrap}+.`, this.openSendCustomDialog)
95+
Mousetrap.bind(`${Keystroke.mousetrap}+shift+s`, this.toggleSidebar)
9296
}
9397

9498
@action
@@ -145,6 +149,25 @@ class UI {
145149
}
146150
}
147151

152+
@action
153+
hideSidebar = () => {
154+
this.isSidebarVisible = false
155+
}
156+
157+
@action
158+
showSidebar = () => {
159+
this.isSidebarVisible = true
160+
}
161+
162+
@action
163+
toggleSidebar = () => {
164+
if (this.isSidebarVisible) {
165+
this.hideSidebar()
166+
} else {
167+
this.showSidebar()
168+
}
169+
}
170+
148171
@action
149172
switchTab = newTab => {
150173
this.tab = newTab

0 commit comments

Comments
 (0)