Skip to content

Commit 84ed901

Browse files
committed
fix(ui): fix #5: Rename subviews on sidebar
1 parent da7d869 commit 84ed901

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

dist/Simput.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ViewMenu/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import ContentEditable from 'tonic-ui/lib/react/widget/ContentEditable';
23

34
require('./style.css');
45

@@ -24,9 +25,16 @@ export default React.createClass({
2425
return {
2526
viewId: null,
2627
index: 0,
28+
editingIndex: -1,
2729
};
2830
},
2931

32+
componentDidUpdate() {
33+
if (this.state.editingIndex !== -1) {
34+
this.refs.editable.setFocus();
35+
}
36+
},
37+
3038
addView(viewId) {
3139
const viewList = this.props.data.data[viewId] || [],
3240
index = viewList.length,
@@ -44,6 +52,14 @@ export default React.createClass({
4452
this.activateSection(viewId, index > 0 ? index - 1 : 0);
4553
},
4654

55+
editView(viewId, index) {
56+
this.setState({editingIndex: viewId + '-' + index});
57+
},
58+
59+
stopEditingView() {
60+
this.setState({editingIndex: -1});
61+
},
62+
4763
activateSection(viewId, index) {
4864
const viewList = this.props.data.data[viewId] || [];
4965
if(viewList.length <= index) {
@@ -77,8 +93,16 @@ export default React.createClass({
7793
</i>
7894
<ul style={{ display: (hasSubList && viewSize !== undefined) ? 'block' : 'none' }}>
7995
{ viewList.map( (viewData, viewIdx) => {
96+
if (this.state.editingIndex === viewId + '-' + viewIdx) {
97+
return <li key={ 'view-' + viewId + '-' + viewIdx } style={{ fontWeight: fontWeight(viewId, viewIdx) }}>
98+
<ContentEditable ref="editable" html={viewData.name} blurOnEnter
99+
onChange={ (e) => {viewData.name = e.target.value;} }/>
100+
<i className='fa fa-fw fa-check' onClick={ this.stopEditingView }></i>
101+
</li>;
102+
}
80103
return <li key={ 'view-' + viewId + '-' + viewIdx } style={{ fontWeight: fontWeight(viewId, viewIdx) }}>
81104
<span onClick={ this.activateSection.bind(this, viewId, viewIdx) }>{ viewData.name }</span>
105+
<i className='fa fa-fw fa-pencil' onClick={ this.editView.bind(this, viewId, viewIdx) }></i>
82106
<i className='fa fa-fw fa-trash' onClick={ this.removeView.bind(this, viewId, viewIdx) }></i>
83107
</li>;
84108
})}

lib/ViewMenu/style.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@
1515
.Outline li {
1616
cursor: pointer;
1717
max-width: 30vw;
18-
}
18+
}
19+
20+
.ContentEditable {
21+
display: inline-block;
22+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"react-dom": "0.14.6",
5757

5858
"tonic-io": "1.2.2",
59-
"tonic-ui": "1.3.1",
59+
"tonic-ui": "1.3.7",
6060

6161
"font-awesome": "4.5.0",
6262
"mout": "0.11.1",

0 commit comments

Comments
 (0)