11import React from 'react' ;
2+ import ContentEditable from 'tonic-ui/lib/react/widget/ContentEditable' ;
23
34require ( './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 } ) }
0 commit comments