Truncate consecutive member events
This is needed for the IRC bridge to be able to do full membership list syncing without cluttering the message panel.
This commit is contained in:
parent
5a61a1e6e1
commit
cd241a4a17
2 changed files with 73 additions and 4 deletions
|
@ -28,10 +28,16 @@ module.exports = React.createClass({
|
|||
createOverflowElement: React.PropTypes.func
|
||||
},
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
enabled: true,
|
||||
};
|
||||
},
|
||||
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
truncateAt: 2,
|
||||
createOverflowElement: function(overflowCount, totalCount) {
|
||||
createOverflowElement: function(overflowCount, totalCount, toggleTruncate, isExpanded) {
|
||||
return (
|
||||
<div>And {overflowCount} more...</div>
|
||||
);
|
||||
|
@ -39,6 +45,12 @@ module.exports = React.createClass({
|
|||
};
|
||||
},
|
||||
|
||||
toggleTruncate: function() {
|
||||
this.setState({
|
||||
enabled: !this.state.enabled
|
||||
});
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var childsJsx = this.props.children;
|
||||
var overflowJsx;
|
||||
|
@ -48,20 +60,26 @@ module.exports = React.createClass({
|
|||
|
||||
var childCount = childArray.length;
|
||||
|
||||
if (this.props.truncateAt >= 0) {
|
||||
if (this.state.enabled && this.props.truncateAt >= 0) {
|
||||
var overflowCount = childCount - this.props.truncateAt;
|
||||
|
||||
if (overflowCount > 1) {
|
||||
overflowJsx = this.props.createOverflowElement(
|
||||
overflowCount, childCount
|
||||
overflowCount, childCount, this.toggleTruncate
|
||||
);
|
||||
|
||||
|
||||
// cut out the overflow elements
|
||||
childArray.splice(childCount - overflowCount, overflowCount);
|
||||
childsJsx = childArray; // use what is left
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.state.enabled) {
|
||||
overflowJsx = this.props.createOverflowElement(
|
||||
0, childCount, this.toggleTruncate, true
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={this.props.className}>
|
||||
{childsJsx}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue