File tree Expand file tree Collapse file tree 3 files changed +31
-5
lines changed
Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ var TextTruncate = require('react-text-truncate'); // CommonJS or UMD
2727
2828
2929## Changelog
30+ * 0.4.0 New property ` textTruncateChild ` for show more or others.
3031* 0.3.7 Support CommonJS and UMD module loader
3132* 0.3.5 Fix window resize issue
3233* 0.3.4 supports Babel6
Original file line number Diff line number Diff line change 11{
22 "name" : " react-text-truncate" ,
3- "version" : " 0.3.7 " ,
3+ "version" : " 0.4.0 " ,
44 "description" : " Truncate text for React.js" ,
55 "main" : " lib/index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -9,20 +9,45 @@ export class App extends Component {
99 line : 2 ,
1010 truncateText : '…' ,
1111 showTitle : true ,
12- textTruncateChild : < a className = 'pull-right' > show more</ a >
12+ textTruncateChild : < a className = 'pull-right' onClick = { this . showAll } > show more</ a > ,
13+ showAll : false
1314 } ;
1415 }
16+
1517 handleChange = ( e ) => {
1618 this . setState ( {
1719 line : this . refs . line . value << 0 ,
1820 text : this . refs . text . value ,
1921 truncateText : this . refs . truncateText . value ,
20- showTitle : this . refs . showTitle . checked ,
22+ showTitle : this . refs . showTitle . checked
23+ } ) ;
24+ } ;
2125
26+ showAll = ( ) => {
27+ this . setState ( {
28+ showAll : true
2229 } ) ;
2330 } ;
31+
32+ noShowAll = ( ) => {
33+ this . setState ( {
34+ showAll : false
35+ } ) ;
36+ }
37+
2438 render ( ) {
25- let props = this . state ;
39+ const { showAll, ...props } = this . state ;
40+ let text ;
41+ if ( showAll ) {
42+ text = (
43+ < div >
44+ { props . text }
45+ < a className = 'pull-right' onClick = { this . noShowAll } > Hide</ a >
46+ </ div >
47+ ) ;
48+ } else {
49+ text = < TextTruncate { ...props } />
50+ }
2651 return (
2752 < div >
2853 < div className = 'form-group' >
@@ -44,7 +69,7 @@ export class App extends Component {
4469 </ div >
4570 < div className = 'form-group sample' >
4671 < label > Result</ label >
47- < TextTruncate { ... props } />
72+ { text }
4873 </ div >
4974 </ div >
5075 )
You can’t perform that action at this time.
0 commit comments