Show sticker description as a tooltip, on hover.

pull/21833/head
Richard Lewis 2018-02-27 23:07:59 +00:00
parent 57c98d96a5
commit 0fdbddf8fd
1 changed files with 29 additions and 2 deletions

View File

@ -17,22 +17,49 @@ limitations under the License.
'use strict';
import MImageBody from "./MImageBody";
import sdk from '../../../index';
export default class MStickerBody extends MImageBody {
displayName: 'MStickerBody'
constructor(props) {
super(props);
this._onMouseEnter = this._onMouseEnter.bind(this);
this._onMouseLeave = this._onMouseLeave.bind(this);
}
_onMouseEnter() {
this.setState({showTooltip: true});
}
_onMouseLeave() {
this.setState({showTooltip: false});
}
_messageContent(contentUrl, thumbUrl, content) {
let tooltip;
const tooltipBody = (
this.props.mxEvent &&
this.props.mxEvent.getContent() &&
this.props.mxEvent.getContent().body) ?
this.props.mxEvent.getContent().body : null;
if (this.state.showTooltip && tooltipBody) {
const RoomTooltip = sdk.getComponent("rooms.RoomTooltip");
tooltip = <RoomTooltip
className="mx_RoleButton_tooltip"
label={ tooltipBody } />;
}
return (
<span className="mx_MImageBody" ref="body">
<img className="mx_MImageBody_thumbnail" src={thumbUrl} ref="image"
alt={content.body}
onLoad={this.props.onWidgetLoad}
onMouseEnter={this.onImageEnter}
onMouseLeave={this.onImageLeave} />
onMouseEnter={this._onMouseEnter}
onMouseLeave={this._onMouseLeave}
/>
{ tooltip }
</span>
);
}