Skip to content

Commit ca2de6a

Browse files
committed
Add new prop containerClassName
1 parent fad79a4 commit ca2de6a

File tree

8 files changed

+30
-14
lines changed

8 files changed

+30
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var TextTruncate = require('react-text-truncate'); // CommonJS or UMD
3939

4040

4141
## Changelog
42+
* 0.7.1 Add new prop `containerClassName`
4243
* 0.7.0 Fix infinite update bug, drop raf
4344
* 0.6.2 Fix infinite loop bug
4445
* 0.6.1 Fix lib issue for browser

build/bundle.js

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

build/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ <h3>Property</h3>
5050
<td>node</td>
5151
<td>undefined</td>
5252
</tr>
53+
<tr>
54+
<td>containerClassName</td>
55+
<td>string</td>
56+
<td>undefined</td>
57+
</tr>
5358
</tbody>
5459
</table>
5560
<div class="page-header">

lib/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@
198198
var line = _props.line;
199199
var showTitle = _props.showTitle;
200200
var textTruncateChild = _props.textTruncateChild;
201+
var containerClassName = _props.containerClassName;
201202

202-
var props = _objectWithoutProperties(_props, ['text', 'truncateText', 'line', 'showTitle', 'textTruncateChild']);
203+
var props = _objectWithoutProperties(_props, ['text', 'truncateText', 'line', 'showTitle', 'textTruncateChild', 'containerClassName']);
203204

204205
var renderText = '';
205206
if (this.refs.scope) {
@@ -212,7 +213,7 @@
212213

213214
return _react2.default.createElement(
214215
'div',
215-
{ ref: 'scope', style: { overflow: 'hidden' } },
216+
{ ref: 'scope', className: containerClassName, style: { overflow: 'hidden' } },
216217
_react2.default.createElement(
217218
'div',
218219
props,
@@ -231,7 +232,8 @@
231232
truncateText: _react2.default.PropTypes.string,
232233
line: _react2.default.PropTypes.number,
233234
showTitle: _react2.default.PropTypes.bool,
234-
textTruncateChild: _react2.default.PropTypes.node
235+
textTruncateChild: _react2.default.PropTypes.node,
236+
containerClassName: _react2.default.PropTypes.string
235237
};
236238
TextTruncate.defaultProps = {
237239
text: '',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-text-truncate",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "Truncate text for React.js",
55
"main": "lib/index.js",
66
"scripts": {

src/App.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export class App extends Component {
99
line: 2,
1010
truncateText: '…',
1111
showTitle: true,
12-
appendTextTruncateChild: true,
13-
raf: true
12+
appendTextTruncateChild: true
1413
};
1514
}
1615

@@ -69,11 +68,13 @@ export class App extends Component {
6968
</div>
7069
</div>
7170
<div className='col-md-6 col-xs-12'>
72-
<label>Result</label>
71+
<h4>Result</h4>
7372
<div id='sample-1'>
73+
<h5>1. Default</h5>
7474
<TextTruncate {...props}/>
7575
</div>
7676
<div id='sample-2'>
77+
<h5>2. With floating image</h5>
7778
<div className='media'>
7879
<div className='media-left'>
7980
<img className='media-object' src='http://fakeimg.pl/64' width='64' height='64'/>
@@ -84,11 +85,16 @@ export class App extends Component {
8485
</div>
8586
</div>
8687
<div id='sample-3'>
88+
<h5>3. Default hidden</h5>
8789
<div ref='invisibleBlock' style={{display: 'none'}}>
8890
<TextTruncate ref='invisibleTextTruncate' {...props}/>
8991
</div>
9092
<button type='button' className='btn btn-default' onClick={this.onToggle}>Toggle show/hide</button>
9193
</div>
94+
<div id='sample-4'>
95+
<h5>4. Customize class</h5>
96+
<TextTruncate {...props} containerClassName='text-danger'/>
97+
</div>
9298
</div>
9399
</div>
94100
)

src/TextTruncate.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export default class TextTruncate extends Component {
66
truncateText: React.PropTypes.string,
77
line: React.PropTypes.number,
88
showTitle: React.PropTypes.bool,
9-
textTruncateChild: React.PropTypes.node
9+
textTruncateChild: React.PropTypes.node,
10+
containerClassName: React.PropTypes.string
1011
};
1112

1213
static defaultProps = {
@@ -117,6 +118,7 @@ export default class TextTruncate extends Component {
117118
line,
118119
showTitle,
119120
textTruncateChild,
121+
containerClassName,
120122
...props
121123
} = this.props;
122124

@@ -130,7 +132,7 @@ export default class TextTruncate extends Component {
130132
}
131133

132134
return (
133-
<div ref='scope' style={{overflow: 'hidden'}}>
135+
<div ref='scope' className={containerClassName} style={{overflow: 'hidden'}}>
134136
<div {...props}>{renderText}</div>
135137
{text === renderText ? null : textTruncateChild}
136138
</div>

0 commit comments

Comments
 (0)