@@ -9,8 +9,7 @@ export class App extends Component {
99 line : 2 ,
1010 truncateText : '…' ,
1111 showTitle : true ,
12- textTruncateChild : < a className = 'pull-right' onClick = { this . showAll } > show more</ a > ,
13- showAll : false ,
12+ appendTextTruncateChild : true ,
1413 raf : true
1514 } ;
1615 }
@@ -20,57 +19,75 @@ export class App extends Component {
2019 line : this . refs . line . value << 0 ,
2120 text : this . refs . text . value ,
2221 truncateText : this . refs . truncateText . value ,
23- showTitle : this . refs . showTitle . checked
22+ showTitle : this . refs . showTitle . checked ,
23+ appendTextTruncateChild : this . refs . appendTextTruncateChild . checked
2424 } ) ;
2525 } ;
2626
27- showAll = ( ) => {
28- this . setState ( {
29- showAll : true
30- } ) ;
27+ onToggle = ( e ) => {
28+ var display = this . refs . invisibleBlock . style . display ;
29+ this . refs . invisibleBlock . style . display = display === 'none' ? 'block' : 'none' ;
3130 } ;
3231
33- noShowAll = ( ) => {
34- this . setState ( {
35- showAll : false
36- } ) ;
37- }
38-
3932 render ( ) {
40- const { showAll , ... props } = this . state ;
41- let text ;
42- if ( showAll ) {
43- text = (
44- < div >
45- { props . text }
46- < a className = 'pull-right' onClick = { this . noShowAll } > Hide </ a >
47- </ div >
33+ const {
34+ appendTextTruncateChild ,
35+ ... props
36+ } = this . state ;
37+
38+ if ( appendTextTruncateChild ) {
39+ props . textTruncateChild = (
40+ < a href = '#' > Read On </ a >
4841 ) ;
49- } else {
50- text = < TextTruncate { ...props } />
5142 }
43+
5244 return (
53- < div >
54- < div className = 'form-group' >
55- < label htmlFor = 'line' > Line</ label >
56- < input className = 'form-control' id = 'line' ref = 'line' onChange = { this . handleChange } type = 'number' value = { this . state . line } min = { 1 } required />
57- </ div >
58- < div className = 'form-group' >
59- < label htmlFor = 'text' > Text</ label >
60- < textarea className = 'form-control' id = 'text' ref = 'text' onChange = { this . handleChange } rows = { 10 } value = { this . state . text } > </ textarea >
61- </ div >
62- < div className = 'form-group' >
63- < label htmlFor = 'truncateText' > TruncateText</ label >
64- < input className = 'form-control' id = 'truncateText' ref = 'truncateText' onChange = { this . handleChange } type = 'text' value = { this . state . truncateText } />
65- </ div >
66- < div className = 'checkbox' >
67- < label htmlFor = 'showTitle' >
68- < input id = 'showTitle' ref = 'showTitle' onChange = { this . handleChange } type = 'checkbox' checked = { this . state . showTitle } /> Show Title
69- </ label >
45+ < div className = 'row' >
46+ < div className = 'col-md-6 col-xs-12' >
47+ < div className = 'form-group' >
48+ < label htmlFor = 'line' > Line</ label >
49+ < input className = 'form-control' id = 'line' ref = 'line' onChange = { this . handleChange } type = 'number' value = { this . state . line } min = { 1 } required />
50+ </ div >
51+ < div className = 'form-group' >
52+ < label htmlFor = 'text' > Text</ label >
53+ < textarea className = 'form-control' id = 'text' ref = 'text' onChange = { this . handleChange } rows = { 5 } value = { this . state . text } > </ textarea >
54+ </ div >
55+ < div className = 'form-group' >
56+ < label htmlFor = 'truncateText' > TruncateText</ label >
57+ < input className = 'form-control' id = 'truncateText' ref = 'truncateText' onChange = { this . handleChange } type = 'text' value = { this . state . truncateText } />
58+ </ div >
59+ < div className = 'checkbox' >
60+ < label htmlFor = 'showTitle' >
61+ < input id = 'showTitle' ref = 'showTitle' onChange = { this . handleChange } type = 'checkbox' checked = { this . state . showTitle } /> Show title
62+ </ label >
63+ </ div >
64+ < div className = 'checkbox' >
65+ < label htmlFor = 'appendTextTruncateChild' >
66+ < input id = 'appendTextTruncateChild' ref = 'appendTextTruncateChild' onChange = { this . handleChange } type = 'checkbox' checked = { this . state . appendTextTruncateChild } /> Append TextTruncate child
67+ </ label >
68+ </ div >
7069 </ div >
71- < div className = 'form-group sample ' >
70+ < div className = 'col-md-6 col-xs-12 ' >
7271 < label > Result</ label >
73- { text }
72+ < div id = 'sample-1' >
73+ < TextTruncate { ...props } />
74+ </ div >
75+ < div id = 'sample-2' >
76+ < div className = 'media' >
77+ < div className = 'media-left' >
78+ < img className = 'media-object' src = 'http://fakeimg.pl/64' width = '64' height = '64' />
79+ </ div >
80+ < div className = 'media-body' >
81+ < TextTruncate { ...props } />
82+ </ div >
83+ </ div >
84+ </ div >
85+ < div id = 'sample-3' >
86+ < div ref = 'invisibleBlock' style = { { display : 'none' } } >
87+ < TextTruncate { ...props } />
88+ </ div >
89+ < button type = 'button' className = 'btn btn-default' onClick = { this . onToggle } > Toggle show/hide</ button >
90+ </ div >
7491 </ div >
7592 </ div >
7693 )
0 commit comments