Skip to content

Commit 27e0252

Browse files
committed
resizable SideNav
1 parent 0a707b3 commit 27e0252

6 files changed

Lines changed: 65 additions & 11 deletions

File tree

browser/main/Main.js

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ class Main extends React.Component {
2020
let { config } = props
2121

2222
this.state = {
23-
isSliderFocused: false,
24-
listWidth: config.listWidth
23+
isRightSliderFocused: false,
24+
listWidth: config.listWidth,
25+
navWidth: config.listWidth,
26+
isLeftSliderFocused: false
2527
}
2628
}
2729

@@ -49,17 +51,24 @@ class Main extends React.Component {
4951
})
5052
}
5153

52-
handleSlideMouseDown (e) {
54+
handleLeftSlideMouseDown (e) {
5355
e.preventDefault()
5456
this.setState({
55-
isSliderFocused: true
57+
isLeftSliderFocused: true
58+
})
59+
}
60+
61+
handleRightSlideMouseDown (e) {
62+
e.preventDefault()
63+
this.setState({
64+
isRightSliderFocused: true
5665
})
5766
}
5867

5968
handleMouseUp (e) {
60-
if (this.state.isSliderFocused) {
69+
if (this.state.isRightSliderFocused) {
6170
this.setState({
62-
isSliderFocused: false
71+
isRightSliderFocused: false
6372
}, () => {
6473
let { dispatch } = this.props
6574
let newListWidth = this.state.listWidth
@@ -71,10 +80,24 @@ class Main extends React.Component {
7180
})
7281
})
7382
}
83+
if (this.state.isLeftSliderFocused) {
84+
this.setState({
85+
isLeftSliderFocused: false
86+
}, () => {
87+
let { dispatch } = this.props
88+
let navWidth = this.state.navWidth
89+
// TODO: ConfigManager should dispatch itself.
90+
ConfigManager.set({listWidth: navWidth})
91+
dispatch({
92+
type: 'SET_NAV_WIDTH',
93+
listWidth: navWidth
94+
})
95+
})
96+
}
7497
}
7598

7699
handleMouseMove (e) {
77-
if (this.state.isSliderFocused) {
100+
if (this.state.isRightSliderFocused) {
78101
let offset = this.refs.body.getBoundingClientRect().left
79102
let newListWidth = e.pageX - offset
80103
if (newListWidth < 10) {
@@ -86,6 +109,17 @@ class Main extends React.Component {
86109
listWidth: newListWidth
87110
})
88111
}
112+
if (this.state.isLeftSliderFocused) {
113+
let navWidth = e.pageX
114+
if (navWidth < 80) {
115+
navWidth = 80
116+
} else if (navWidth > 600) {
117+
navWidth = 600
118+
}
119+
this.setState({
120+
navWidth: navWidth
121+
})
122+
}
89123
}
90124

91125
render () {
@@ -105,9 +139,20 @@ class Main extends React.Component {
105139
'config',
106140
'location'
107141
])}
142+
width={this.state.navWidth}
108143
/>
144+
{!config.isSideNavFolded &&
145+
<div styleName={this.state.isLeftSliderFocused ? 'slider--active' : 'slider'}
146+
style={{left: this.state.navWidth - 1}}
147+
onMouseDown={(e) => this.handleLeftSlideMouseDown(e)}
148+
draggable='false'
149+
>
150+
<div styleName='slider-hitbox'/>
151+
</div>
152+
}
109153
<div styleName={config.isSideNavFolded ? 'body--expanded' : 'body'}
110154
ref='body'
155+
style={{left: config.isSideNavFolded ? 44 : this.state.navWidth}}
111156
>
112157
<TopBar style={{width: this.state.listWidth}}
113158
{..._.pick(this.props, [
@@ -127,9 +172,9 @@ class Main extends React.Component {
127172
'location'
128173
])}
129174
/>
130-
<div styleName={this.state.isSliderFocused ? 'slider--active' : 'slider'}
175+
<div styleName={this.state.isRightSliderFocused ? 'slider--active' : 'slider'}
131176
style={{left: this.state.listWidth}}
132-
onMouseDown={(e) => this.handleSlideMouseDown(e)}
177+
onMouseDown={(e) => this.handleRightSlideMouseDown(e)}
133178
draggable='false'
134179
>
135180
<div styleName='slider-hitbox'/>
@@ -143,7 +188,7 @@ class Main extends React.Component {
143188
'params',
144189
'location'
145190
])}
146-
ignorePreviewPointerEvents={this.state.isSliderFocused}
191+
ignorePreviewPointerEvents={this.state.isRightSliderFocused}
147192
/>
148193
</div>
149194
<StatusBar

browser/main/SideNav/SideNav.styl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
.top-menu-label
2424
margin-left 5px
25+
overflow ellipsis
2526

2627
.menu
2728
margin-top 15px
@@ -33,6 +34,7 @@
3334
font-size 14px
3435
width 100%
3536
text-align left
37+
overflow ellipsis
3638

3739
.menu-button--active
3840
@extend .menu-button

browser/main/SideNav/StorageItem.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
margin 2px 0
6666
text-align left
6767
border none
68+
overflow ellipsis
6869
font-size 14px
6970
&:first-child
7071
margin-top 0

browser/main/SideNav/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ class SideNav extends React.Component {
5050
isFolded={isFolded}
5151
/>
5252
})
53-
53+
let style = {}
54+
if (!isFolded) style.width = this.props.width
5455
return (
5556
<div className='SideNav'
5657
styleName={isFolded ? 'root--folded' : 'root'}
5758
tabIndex='1'
59+
style={style}
5860
>
5961
<div styleName='top'>
6062
<button styleName='top-menu'

browser/main/lib/ConfigManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const defaultConfig = {
88
zoom: 1,
99
isSideNavFolded: false,
1010
listWidth: 250,
11+
navWidth: 200,
1112
hotkey: {
1213
toggleFinder: OSX ? 'Cmd + Alt + S' : 'Super + Alt + S',
1314
toggleMain: OSX ? 'Cmd + Alt + L' : 'Super + Alt + E'

browser/main/store.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ function config (state = defaultConfig, action) {
461461
case 'SET_LIST_WIDTH':
462462
state.listWidth = action.listWidth
463463
return Object.assign({}, state)
464+
case 'SET_NAV_WIDTH':
465+
state.navWidth = action.navWidth
466+
return Object.assign({}, state)
464467
case 'SET_CONFIG':
465468
return Object.assign({}, state, action.config)
466469
case 'SET_UI':

0 commit comments

Comments
 (0)