1
0
mirror of synced 2024-11-28 16:00:51 +01:00
bemaniutils/bemani/frontend/static/components/longmessage.react.js
2019-12-08 21:43:49 +00:00

44 lines
1.4 KiB
JavaScript

/** @jsx React.DOM */
var LongMessage = React.createClass({
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>;
}
},
});