1
0
mirror of synced 2024-12-29 22:03:04 +01:00
bemaniutils/bemani/frontend/static/components/longmessage.react.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

/** @jsx React.DOM */
var LongMessage = createReactClass({
getInitialState: function(props) {
return {
expanded: false,
};
},
render: function() {
var length = this.props.length ? this.props.length : 50;
var text = this.props.children;
if (text.length > length) {
if (this.state.expanded) {
return (
<div className="longmessage">
<pre>{text}</pre>
<button
className="viewmore"
onClick={function(event) {
this.setState({expanded: false});
}.bind(this)}
>view less</button>
</div>
);
} else {
return (
<div className="longmessage">
<pre>{text.substring(0, length)}...</pre>
<button
className="viewmore"
onClick={function(event) {
this.setState({expanded: true});
}.bind(this)}
>view more</button>
</div>
);
}
} else {
return <div className="longmessage"><pre>{text}</pre></div>;
}
},
});